0

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

Lorenzo
  • 17
  • 4
  • Hi, are you looking for something like this? https://jsfiddle.net/BlackLabel/xv4g2cma/ 2 stacked series and one separate non-stacked? – raf18seb Jun 19 '20 at 12:55
  • Hi @raf18seb, thanks for your help: something kinda like what you have shown! "series1" and "series2" of your chart are perfect. Instead of "series 3", I would need something like series1&2 (let's call'em "series3" and "series4", so two stacked area charts) which overlaps "series1&2". So, as if series1&2 have their independent y axis, and series3&4 have their own y axis. Hope I explained myself a bit more clear :) – Lorenzo Jun 20 '20 at 13:09
  • Am I getting closer? https://jsfiddle.net/BlackLabel/43ncukmw/ --- after you approve the JavaScript version, I will help you rewrite it to R – raf18seb Jun 22 '20 at 11:51
  • @raf18seb yes! Exactly like that! – Lorenzo Jun 23 '20 at 21:42
  • Sorry for a late reply, I am adding the answer – raf18seb Jul 03 '20 at 11:12

1 Answers1

1

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)
raf18seb
  • 2,096
  • 1
  • 7
  • 19