在R中创建明细图

时间:2019-02-25 14:45:14

标签: r r-highcharter

您好,我想用R从here重新创建高图地图,在其中我将能够看到每个州或县的Num

我的示例数据框是:

State<-c("ALABAMA","ALABAMA","ALASKA","ALASKA")
StateCode<-c("AL","AL","AK","AK")
County<-c("AUTAUGA","BALDWIN","ANCHORAGE","BETHEL")
CountyCode<-c("AL001","AL003","AK020","AK050")
Num<-c(5,6,7,8)
d<-data.frame(State,StateCode,County,CountyCode, Num)

直到现在,我一直在尝试使用highcharter包来创建向下钻取条,但是我还没有找到如何将其转换为向下钻取图的方法。

library(highcharter)
library(dplyr)

hc <- highchart() %>%
  hc_chart(type="column") %>%
  hc_xAxis(type="category") %>%
  hc_add_series(
    data = d,
    name = "States",
    type = "column",
    hcaes(x = State, y = Num)
  )%>%
  hc_drilldown(
    series = list(
      list(
        name = "ALABAMA",
        id = "alabama",
        data = list(list(name = "AUTAUGA", y = 5), list(name = "BALDWIN", y = 6))
      ),
      list(
        name = "ALASKA",
        id = "alaska",
        data = list(list(name = "ANCHORAGE", y = 7), list(name = "BETHEL", y = 8))
      )
    )
  )
hc

0 个答案:

没有答案