How to change the order of aesthetic layers in ggplot?
问题 How can I change the order of aestetics layers? Here's and example dat <- tibble (acc = rep(c(0,1), 200), rt = rnorm(400, 0.5, 0.1)) dat %>% ggplot(aes(x = rt, fill = factor(acc))) + geom_density(aes(y= ..count..*0.03), alpha = 0.6) This code plots this image. Here, the green (1) layer is above the red (0) layer. How can I place the red (0) layer on top of the green (1)? I have tried dat %>% ggplot(aes(x = rt, fill = factor(acc, levels = c(1,0)))) + geom_density(aes(y= ..count..*0.03), alpha