首页 > 解决方案 > R highcharter 向下钻取图表问题

问题描述

我正在按照这个示例构建一个向下钻取的柱形图。一切似乎都很好,除了向下钻取功能不起作用。我的数据框与示例中的数据框之间的主要区别在于我有一个日期列。

library(tidyr)
library(highcharter)
library(dplyr)
library(purrr)
df1 = tibble(Date = c("6/30/2020", "6/30/2020", "6/30/2020", "6/30/2020", "6/30/2020", "5/31/2020","5/31/2020","5/31/2020","5/31/2020"), 
             Class = c("NUS", "NUS", "NUS", "US", "US", "NUS", "NUS", "US", "US"), 
             Type = c("C", "E", "S", "C", "E", "C", "E","C","E"), 
             Value = c(4.6, 1.3, 4.6, 5.0, 2.0, 5.2, 1.2, 5.0,1.9))

#Summarise by Date and Class
df2 <- ddply(df1, c("Date", "Class"), summarise, Sum = sum(Value))
df2$drilldown <- tolower(df2$Class)

#To lists
dsnus <- list_parse2(df1[df1$Class=="NUS",])
dsus <- list_parse2(df1[df1$Class=="US",])

hc <- highchart() %>%
  hc_title(text = "Basic drilldown") %>%
  hc_xAxis(type = "category") %>%
  hc_legend(enabled = FALSE) %>%
  hc_plotOptions(
    series = list(
      boderWidth = 0,
      dataLabels = list(enabled = TRUE))) %>%
  hc_add_series(
    data = df2,
    type = "column",
    hcaes(name = Date, y = Sum, group = Class),
    colorByPoint = TRUE)

hc <- hc %>%
  hc_drilldown(allowPointDrilldown = TRUE,
    series = list(
      list(id = "us",
        data = dsus),
      list(
        id = "nus",
        data = dsnus)))

hc

在此处输入图像描述

标签: rhighchartsr-highcharter

解决方案


推荐阅读