0

我想使用googleVis(R 包)将堆叠条彼此相邻绘制,因为我有一些子类别我想在条形图中彼此相邻堆叠。这可能吗?例如:我有三个类别(CatACatBCatC,它们都有三个子类别。我有几个月(或以下示例中的几年)的数据,我想堆叠每个类别的子类别,但将每年的类别彼此相邻绘制。这可能googleVis吗?我想您可以通过选择正确的填充参数来使用 ggplot 执行此操作,但不确定如何在googleVis.

library(googleVis)

Test <- data.frame(Year = c("2011", "2012", "2013"), CatA_1 = ceiling(runif(3, 0, 10)),CatA_2 = ceiling(runif(3, 0, 10)), CatA_3 = ceiling(runif(3, 0, 10)), CatB_1 = ceiling(runif(3, 0, 10)), CatB_2 = ceiling(runif(3, 0, 10)), CatB_3 = ceiling(runif(3, 0, 10)), CatC_1 = ceiling(runif(3, 0, 10)), CatC_2 = ceiling(runif(3, 0, 10)), CatC_3 = ceiling(runif(3, 0, 10)))

GooglePlot <- gvisComboChart(Test, xvar = "Year", yvar = c(colnames(Test)[2:9]), options=list(title='Test - GoogleBarplot (stacked?)',legend='right', width=800, height=800, hAxes = "[{slantedText: true, slantedTextAngle: 60}]", seriesType = "bars"))
plot(GooglePlot)

所以我想要类别CatA_1,CatA_2和堆叠,但在,CatA_3旁边(应该再次堆叠)。我知道我的数据框的格式不理想,但是应该怎么做呢?CatB_1CatB_2CatB_3

干杯,

4

0 回答 0