Search code examples
rggplot2highchartsaesinteraction

R Highcharter hcaes- Area chart staking by only 1 factor... with 2 grouping factors


I am trying to achieve something like what is reported in this post (group by two columns in ggplot2), but with an additional feature.

I am currently creating my highchart grouping by 2 factors: this solution is working just fine.

What I would like to achieve is: I would like to stack the area chart by only 1 of the 2 factors, and use the other one to have 2 overlapping "stacked" area charts

Do you have any clue how to make it?

Best, Lorenzo


Solution

  • Based on your comments, you approved that you are trying to achieve something like this: https://jsfiddle.net/BlackLabel/43ncukmw/

    Here you have the R code of this chart:

    library(highcharter)
    
    highchart() %>%
      hc_plotOptions(series = list(stacking = 'normal')) %>%
      hc_yAxis_multiples(
        list(min = 0, max = 20),
        list(min = 0, max = 16, opposite = TRUE)
      ) %>% 
      hc_add_series(data = c(1, 2, 3, 4, 5, 6), type = 'area') %>% 
      hc_add_series(data = c(10, 10, 10, 10, 10, 10), type = 'area') %>% 
      hc_add_series(data = c(1, 3, 2, 3, 5, 3), type = 'column', yAxis = 1) %>% 
      hc_add_series(data = c(2, 3, 2, 3, 2, 3), type = 'column', yAxis = 1)