如何使用highchart()和列表更正空白区域

时间:2019-06-11 18:10:36

标签: r r-highcharter

使用堆栈溢出:R highcharts multiple stacked bar chart

我能够使用已有的数据集创建堆积的柱状图。但是,此集合中的数据“类型”是动态的,因此我尝试实现: Highcharter stacked column groupings not using hchart()

但是,当我下载并运行该代码时,虽然我生成的列表看起来与示例相同,但该图显示为空白。正确识别了类型,但未填充图表。我曾尝试在浏览器中运行此程序,以防R Studio无法正确处理它,但无济于事。

我尝试并使用以下方法来解决部分问题: R highcharts multiple stacked bar chart

但是,由于数据的动态类型,我需要更多类似于以下内容的解决方案: Highcharter stacked column groupings not using hchart()

我已经比较了列表,它们看起来是相同的(不同的数据,但结构正确)

data <- data[!duplicated(data$AcctID), ]

data$ExpireDate <- mdy_hm(data$ExpireDate)
data$ExpireDateGroup <- floor_date(data$ExpireDate, "day")

cheeseData <- data %>%
  mutate(Day = as.character(ExpireDateGroup)) %>%
  group_by(Day, Cheese) %>%
  summarise(CheeseWheels = n())

byCheese.list <- cheeseData %>%
  group_by(Cheese) %>%
  do(cheeseData = list_parse2(.[, c('Day', 'CheeseWheels')])) %>%
  rename(name = Cheese) %>%
  mutate(Cheese = 'column') %>%
  list_parse()

highchart() %>%
  hc_xAxis(categories = cheeseData$Day) %>%
  hc_add_series_list(byCheese.list) %>%
  hc_plotOptions(series = list(stacking = 'normal'))

预期结果:应该有堆积的柱状图 Empty Column Chart

样本数据

    data <- structure(list(AcctID = c(251981L, 261775L, 275048L, 282754L, 
                          286490L, 279683L, 277289L, 282031L, 287776L, 284062L), CreatedDate = c("4/2/2019 18:48", 
                                                                                                 "4/18/2019 16:14", "5/10/2019 7:49", "5/22/2019 15:13", "5/29/2019 11:29", 
                                                                                                 "5/17/2019 14:05", "5/14/2019 10:32", "5/21/2019 16:59", "5/31/2019 7:56", 
                                                                                                 "5/24/2019 14:09"), ExpireDate = structure(c(1559642040, 1559642100, 
                                                                                                                                              1559642160, 1559642220, 1559642220, 1559642280, 1559642340, 1559642340, 
                                                                                                                                              1559642400, 1559642460), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
               Cheese = c("Gouda", "Gouda", "Gouda", "Gouda", "Gouda", "Gouda", 
                          "Gouda", "Gouda", "Gouda", "Gouda"), ExpireDateGroup = structure(c(1559606400, 
                                                                                             1559606400, 1559606400, 1559606400, 1559606400, 1559606400, 
                                                                                             1559606400, 1559606400, 1559606400, 1559606400), class = c("POSIXct", 
                                                                                                                                                        "POSIXt"), tzone = "UTC")), row.names = c(1L, 3L, 5L, 6L, 
                                                                                                                                                                                                  8L, 10L, 11L, 12L, 13L, 14L), class = "data.frame")

0 个答案:

没有答案