r - highcharter 中的 Facet_wrap/facet_grid 有类似的功能吗?

标签 r r-highcharter

我有下面的数据框,并且已使用 ggplot 完成绘图..是否有类似的函数,如 facet_gridfacet_wrap highcharter

df1<-data.frame(
      Year=sample(2016:2018,100,replace = T),
      Month=sample(month.abb,100,replace = T),
      category1=sample(letters[1:6],100,replace = T),
      catergory2=sample(LETTERS[8:16],100,replace = T),
      lic=sample(c("P","F","T"),100,replace = T),
      count=sample(1:1000,100,replace = T)
    )

绘图代码:

ggplot(df1,aes(Year,count,fill=factor(lic))) +
      geom_bar(stat = "identity",position = "stack") +
      facet_grid(~category1)

output

最佳答案

我发现的最好的就是这个。

df2 <- df1 %>% 
  group_by(Year,category1  ,lic) %>% 
  summarise(count=sum(count)) 
map(unique(df2$category1), function(x){
  df2 %>% filter(category1 == x) %>% 
    hchart(., "column", hcaes(x = Year, y = count, group = lic),showInLegend = FALSE) %>% 
    hc_plotOptions(column = list(stacking = "normal")) %>% 
    hc_add_theme(hc_theme_smpl()) %>% 
    hc_title(text = x) %>% 
    hc_yAxis(title = list(text = ""))
  }) %>% 
  hw_grid(rowheight = 150) %>% htmltools::browsable()

enter image description here

关于r - highcharter 中的 Facet_wrap/facet_grid 有类似的功能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53277199/

相关文章:

javascript - 用 highcharts r 中的自定义替换轴标签

r - 如何根据条件将向量拆分为 R 中的不相等 block ?

r - 如何从 R 中的数据框中去除美元符号 ($)?

r - 如何在 R 中使用 gmp 库

javascript - 高宪章: capture currently selected min and max dates in stock plot

javascript - R 中的 Highcharts 依赖轮

r - HighcharterR : plotband and plotline not working

r - ggplot 和 R : Issue with barplot and the width of the bars when certain x values are missing

r - 指示条形图基数 R 的统计显着差异

r - 如何使用 Highcharter 创建两个独立的向下钻取图?