这里是highcharter
软件包网站上的一些开源代码,详细说明了如何使用hcmap
加载到地图中。
library(highcharter)
# produces the following map inline
hcmap("countries/us/us-all", data = data_fake, value = "value",
joinBy = c("hc-a2", "code"), name = "Fake data",
dataLabels = list(enabled = TRUE, format = '{point.name}'),
borderColor = "#FAFAFA", borderWidth = 0.1,
tooltip = list(valueDecimals = 2, valuePrefix = "$", valueSuffix = " USD"))
我想知道是否/如何更改右下角图例的比例。如果我想要对数刻度或一些自定义值怎么办?有没有办法用这个软件包做到这一点?
对于对数刻度,尝试用管道传输到hc_colorAxis(type = "logarithmic")
:
library(highcharter)
library(dplyr)
data("USArrests", package = "datasets")
USArrests <- mutate(USArrests, `woe-name` = rownames(USArrests))
set.seed(1)
data_fake <- tibble(test = sample(1:300000, 50, replace = TRUE),
`woe-name` = USArrests$`woe-name`)
hcmap(map = "countries/us/us-all", data = data_fake,
joinBy = "woe-name", value = "test", name = "woe-name",
dataLabels = list(enabled = TRUE, format = '{point.name}'),
borderColor = "#FAFAFA", borderWidth = 0.1,
tooltip = list(valueDecimals = 2, valuePrefix = "$", valueSuffix = " USD")
) %>% hc_colorAxis(type = "logarithmic")
编辑:也可以自定义色阶,请参见https://www.highcharts.com/forum/viewtopic.php?t=33569。