类别的Highcharter地图

时间:2019-06-13 11:17:13

标签: r r-highcharter

我正在尝试用R而不是数字创建R的欧洲海图地图。

可以说我下面有数据集,我希望地图显示每个类别的颜色。类别为:“红色”,“蓝色”,“绿色”。

library(highcharter)
mapData <- data_frame(country = c("PT", "FR", "IT", "DE"), 
value = c("Red","Blue","Green","Red"))

然后我需要地图来显示类别:

hcmap(map = 'custom/europe', data = mapData,
  joinBy = c("iso-a2","country"), value = "value")

问题是,结果使我的data frame中的每个国家/地区都变得黑了。

1 个答案:

答案 0 :(得分:2)

以下是可能解决方案的建议:

mapData <- tibble(country = c("PT", "FR", "IT", "DE"),  
                  value = c(1, 2, 3, 1))

hcmap(map = 'custom/europe', data = as.data.frame(mapData),
  joinBy = c("iso-a2","country"), value = "value") %>%
  hc_colorAxis(dataClassColor="category", 
     dataClasses = list(list(from=1, to=1, color="red", name="PT-DE"),
                        list(from=2, to=2, color="blue", name="FR"),
                        list(from=3, to=3, color="green", name="IT")))

enter image description here