R Highchart //在x轴上分组

时间:2016-10-20 07:31:00

标签: r highcharts

我想创建一个带有分组类别的堆积条形图,例如there

这是我的示例数据框:

region <- c("bavaria", "bavaria", "bavaria", "bavaria", "berlin", "berlin", "berlin", "berlin")
year <- c(2016, 2016, 2017, 2017, 2016, 2016, 2017, 2017)
month <- c(11, 12, 01, 02, 11, 12, 01, 02)
sales <- c(20, 17, 10, 5, 18, 16, 10, 7)
inc_sales <- c(3, 2, 1, 0, 4, 3, 2, 0)
df <- data.frame(region, year, month, sales, inc_sales)

x轴应按月/年/地区分组,其中月份位于最前面。

我已将此编码仅使用月份作为x轴:

library(tidyr)
library(dplyr)
library(highcharter)

highchart() %>% 
      hc_chart(type = "column") %>% 
      hc_title(text = "Sales") %>% 
      hc_xAxis(categories = df$month) %>%
      hc_yAxis(title = list(text = "Sales")) %>% 
      hc_plotOptions(column = list(
        dataLabels = list(enabled = FALSE),
        stacking = "normal",
        enableMouseTracking = TRUE)
      ) %>% 
      hc_series(list(name="sales",data=df$inc_sales),
                list(name="inc_sales",data=df$sales))

有人可以帮我分类吗?

2 个答案:

答案 0 :(得分:1)

您可以找到&#39; Grouped Categories&#39;选项有用: highcharter examples

答案 1 :(得分:0)

也许你可以尝试这样的事情:

chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security