在dygraphs中实现堆叠柱状图时遇到数值类型报错的求助
在dygraphs中实现堆叠柱状图时遇到数值类型报错的求助
我有一个xts格式的数据框,结构如下:
structure(c("May 2022", "Jun 2022", "Jul 2022", "Aug 2022", "Sep 2022", "Oct 2022", "Nov 2022", "Dec 2022", " 3035.199", " 5500.000", "11568.750", " 2510.000", " 6999.999", "21792.149", " 9750.000", " 5624.999", " 2250.000", " 4136.975", " 6525.500", " 2771.875", " 4637.500", "16273.499", " 6000.000", " 4494.649", " 2500.000", " 0.000", " 3029.000", " 2803.500", " 0.000", "14481.250", " 4374.998", " 4062.498", " 0.000", " 3075.000", " 6939.249", " 1500.000", " 4183.157", " 5769.000", " 3559.500", " 3250.000" ), class = c("xts", "zoo"), index = structure(c(1651363200, 1654041600, 1656633600, 1659312000, 1661990400, 1664582400, 1667260800, 1669852800 ), tzone = "UTC", tclass = "yearmon"), .Dim = c(8L, 5L), .Dimnames = list( NULL, c("Month", "Cat 1", "Cat 2", "Cat 3", "Cat 4")))
我想用dygraphs库创建一个堆叠柱状图,目前写的代码是这样的:
library(dygraphs) library(lubridate) today <- as.Date(Sys.time()) last_6 <- today+months(-6) dygraph(df) %>% dyAxis("y", label= "Total") %>% dyRangeSelector(dateWindow = c(last_6, today)) %>% dyMultiColumnGroup(c("Cat 1", "Cat 2", "Cat 3", "Cat 4"))
这段代码能生成普通的分组柱状图,但我想要的是堆叠样式的。
之后我尝试把dyMultiColumnGroup那一行替换成dyStackedBarGroup(c("Cat 1", "Cat 2", "Cat 3", "Cat 4")),结果直接报错了:
Error in cumulativeYval + points : non-numeric argument to binary operator
我查了一些教程,很多都提到要用到plotters,但讲得太笼统了,我完全搞不懂具体该怎么操作。有没有大佬能给我一些实用的建议呀?
备注:内容来源于stack exchange,提问作者alec22
相关产品推荐
相关产品推荐

