change colors' order in each plot of facet_wrap separately when plots are created by geom_area

25 Views Asked by At

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?

0

There are 0 best solutions below