Facet_wrap / facet_grid любая подобная функция в highcharter? - PullRequest
0 голосов
/ 13 ноября 2018

У меня есть нижеприведенный фрейм данных, и построение графиков выполняется с помощью ggplot. Есть ли подобная функция, такая как facet_grid или facet_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)
    )

Plotкод:

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

output

1 Ответ

0 голосов
/ 13 ноября 2018

Лучшее, что я нашел, это.

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

...