Highcharter stacked column groupings not using hchart()

前端 未结 1 1515
挽巷
挽巷 2020-12-19 16:07

I\'m trying to create a stacked bar chart with groupings using Highcharter, and need to create it without using the hchart() function. I have the following code

相关标签:
1条回答
  • 2020-12-19 16:56

    Something like this?

    library(highcharter)
    library(dplyr)
    
    data <- data.frame(
      building = c("Building A", "Building A", "Building B", "Building B"),
      type = c("Rent", "Owned"),
      measure = c(100, 35, 124, 150),
      measure_target = c(95, 20, 122, 145)
    )
    
    data_lst <- data %>% 
      group_by(type) %>% 
      do(data = list_parse2(.[, c('building', 'measure')])) %>% 
      rename(name = type) %>% 
      mutate(type = 'column') %>% 
      list_parse()
    
    
    data_lst2 <- data %>% 
      group_by(type) %>% 
      do(data = list_parse2(.[, c('building', 'measure_target')])) %>% 
      rename(name = type) %>% 
      mutate(type = 'scatter') %>% 
      list_parse()
    
    
    highchart() %>%
      hc_xAxis(categories = data$building) %>%
      hc_add_series_list(data_lst)%>%
      hc_add_series_list(data_lst2)%>%
      hc_plotOptions(series=list(stacking='normal'))
    

    0 讨论(0)
提交回复
热议问题