0

I want to change the color's order in geom_area based on the size of the plot. In fact, I want to put the smaller plot forward and send the larger plot back.

If I run the following code, the orange plot in the right panel is covered completely by the green plot.


x = c(1:20)
y1 = c(1:10, 10:1)
y2 = c(seq(1,5, length.out = 10), seq(5,1, length.out = 10))
y3 = c(seq(1,15, length.out = 10), seq(15,1, length.out = 10))
df = data.frame(x = x, y = c(y1,y2,y1,y3), type = rep(c('type1', 'type2'), each = 20), status = rep(c('status1','status2'), each = 40))

library(dplyr)
library(ggplot2)
df %>%
  ggplot2::ggplot(.,aes(x = x, y = y)) +
  geom_area(aes(fill = type, group = type), alpha = 1,position = 'identity') +
  scale_fill_manual(values = c('orange', 'lightgreen')) +
  facet_wrap(~status)+
  theme_bw()

enter image description here

I do not want to change the alpha. Is there any way to change the color's order for each plot in facet_wrap?

ADEN
  • 99
  • 4
  • A brute force approach would be to filter your dataset and use two `geom_area` layers, one for the larger, one for the smaller ones. For more help please provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data best shared via `dput`, i.e. run `dput(df)` and copy the output into your post. – stefan May 31 '23 at 12:56
  • 1
    Have you tryed changing the levels of your 'type' ? – pbraeutigm May 31 '23 at 13:22
  • This question should be closed. The difference between this and the one that is provided in the 'R Order of stacked areas with ggplot geom_area' is that I want to change order in each facet_wrap separately, meaning each plot of the facet_wrap has its own color's order. – ADEN May 31 '23 at 17:47

0 Answers0