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
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.