0

I would like to change the label format of the legend in a highcharter map. I have values ranging from 0 to 200 billion. The first steps, i.e. thousand (k) and million (M), are fine, but I need to change the abbreviation for billion "G".

I am not really good in javascript, hence I dont know how to write the format-command in the hc_legend() function to change the "G" to a "B", while leaving "k" for thousand and "M" for million.

Here is a small example where one can see that highcharter uses "G" for billions.

library(highcharter)

df = data.frame(
  Country = c("AT","BE","CH","DE","FR","IT"),
  variable = rnorm(n = 6, mean = 120000000000, sd = 20000000000)
)


hcmap(map = "custom/europe",
      data = df, joinBy = c("hc-a2", "Country"), value = "variable", name = "variable",
      dataLabels = list(enabled = TRUE, format = '{point.name}'),
      borderColor = "#FAFAFA", borderWidth = 0.1,
      tooltip = list(valueDecimals = 0, valuePrefix = "€", valueSuffix = "")) %>%
  hc_mapNavigation(enabled = TRUE)
  #hc_legend(enabled = TRUE, format = "{value}B") #basically a placeholder, as I dont know how to proceed
Martin G.
  • 159
  • 1
  • 15
  • Looks like you should pass a labeller to `hc_legend` to create human readable numbers. – Roman Luštrik Jul 06 '17 at 13:52
  • I dont know if i get you right, but the numbers are perfectly readable. Highcharter (or highcharts) did already a good job in trimming the numbers in certain steps and placing "k", "M", and "G" behind them. I just want to change the "G" to a "B". – Martin G. Jul 06 '17 at 14:23
  • 2
    To change the scale suffixes you can manipulate `lang.numericSymbols` - http://api.highcharts.com/highcharts/lang.numericSymbols. Not sure how you pass that into highcharter, however. – wergeld Jul 06 '17 at 16:08
  • 2
    @wergeld like so? https://stackoverflow.com/questions/25266392/how-to-set-highchart-global-options-in-r – Roman Luštrik Jul 06 '17 at 22:37
  • @RomanLuštrik, perhaps. I have not had time to mess with R as much as I would like. – wergeld Jul 07 '17 at 11:53
  • I just confirmed NpT answer as working solution. However, many thanks to wergeld and Roman Luštrik for the help. #EDIT: I can finally upvote posts and comments and so I did! – Martin G. Jul 10 '17 at 17:59

1 Answers1

1

Changing the 'G' to 'B' has to be done as follows:

hcoptslang <- getOption("highcharter.lang")
hcoptslang$numericSymbols <-c( "k", "M", "B" ,"T", "P" ,"E")
options(highcharter.lang = hcoptslang)

By that you change the numberic Symbols for highcharter.

PS: Thanks to @wergeld and @Roman Luštrik for their directions.

NpT
  • 451
  • 4
  • 11