与 {highcharter} 等效的 highcharts 地图
Equivalent of highcharts map with {highcharter}
谁能帮我用 highcharter 包做一个相当于这张卡的东西?
文档中没有太多说明...
https://www.highcharts.com/maps/demo/data-class-ranges
非常感谢!
您可以使用 HighChater 内置的辅助函数来完成此操作:
library(tidyverse)
library(viridis)
library(highcharter)
mapdata <- get_data_from_map(download_map_data("countries/us/us-all"))
set.seed(1234)
data_fake <- mapdata %>%
select(code = `hc-a2`) %>%
mutate(value = 1e5 * abs(rt(nrow(.), df = 10)))
color_classes(c(0, 100000, 200000, 500000))
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(
minColor = "gray",
maxColor = "yellow",
dataClasses = color_classes(c(0, 100000, 200000, 500000))
)
重要的部分是 color_classes
列表。在此示例中,我制作了 3 个分段(0-100k、100k-200k 和 200k-500k)。您可以自己为颜色数组中的颜色或通过其他方式设置颜色。
您可以在官方 Highcharter 网站上找到更多示例:http://jkunst.com/highcharter/highmaps.html
这些参考了JavaScript,但是你可以在R中使用几乎所有的:
您可以在此处找到所有 Highcharts API 属性:https://api.highcharts.com/highcharts/ and more docs (including colorAxis) you can find here: https://www.highcharts.com/docs/index
谁能帮我用 highcharter 包做一个相当于这张卡的东西?
文档中没有太多说明...
https://www.highcharts.com/maps/demo/data-class-ranges
非常感谢!
您可以使用 HighChater 内置的辅助函数来完成此操作:
library(tidyverse)
library(viridis)
library(highcharter)
mapdata <- get_data_from_map(download_map_data("countries/us/us-all"))
set.seed(1234)
data_fake <- mapdata %>%
select(code = `hc-a2`) %>%
mutate(value = 1e5 * abs(rt(nrow(.), df = 10)))
color_classes(c(0, 100000, 200000, 500000))
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(
minColor = "gray",
maxColor = "yellow",
dataClasses = color_classes(c(0, 100000, 200000, 500000))
)
重要的部分是 color_classes
列表。在此示例中,我制作了 3 个分段(0-100k、100k-200k 和 200k-500k)。您可以自己为颜色数组中的颜色或通过其他方式设置颜色。
您可以在官方 Highcharter 网站上找到更多示例:http://jkunst.com/highcharter/highmaps.html
这些参考了JavaScript,但是你可以在R中使用几乎所有的: 您可以在此处找到所有 Highcharts API 属性:https://api.highcharts.com/highcharts/ and more docs (including colorAxis) you can find here: https://www.highcharts.com/docs/index