Highcharter/Highmap: 更改图例标签格式为十亿
Highcharter/Highmap: change legend label format for billions
我想更改高宪章地图中图例的标签格式。我的值从 0 到 2000 亿不等。第一步,即千 (k) 和百万 (M),没问题,但我需要更改 billion "G".
的缩写
我在 javascript 方面不是很擅长,因此我不知道如何在 hc_legend() 函数中编写格式命令来将 "G" 更改为 "B",同时留下 "k" 千和 "M" 百万。
这是一个小例子,可以看出 highcharter 使用 "G" 来获得数十亿。
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
将 'G' 更改为 'B' 必须按如下方式完成:
hcoptslang <- getOption("highcharter.lang")
hcoptslang$numericSymbols <-c( "k", "M", "B" ,"T", "P" ,"E")
options(highcharter.lang = hcoptslang)
这样你就可以更改 highcharter 的数字符号了。
PS:感谢@wergeld 和@Roman Luštrik 的指导。
我想更改高宪章地图中图例的标签格式。我的值从 0 到 2000 亿不等。第一步,即千 (k) 和百万 (M),没问题,但我需要更改 billion "G".
的缩写我在 javascript 方面不是很擅长,因此我不知道如何在 hc_legend() 函数中编写格式命令来将 "G" 更改为 "B",同时留下 "k" 千和 "M" 百万。
这是一个小例子,可以看出 highcharter 使用 "G" 来获得数十亿。
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
将 'G' 更改为 'B' 必须按如下方式完成:
hcoptslang <- getOption("highcharter.lang")
hcoptslang$numericSymbols <-c( "k", "M", "B" ,"T", "P" ,"E")
options(highcharter.lang = hcoptslang)
这样你就可以更改 highcharter 的数字符号了。
PS:感谢@wergeld 和@Roman Luštrik 的指导。