How to change the order of aesthetic layers in ggplot?

后端 未结 3 414
天涯浪人
天涯浪人 2021-01-15 19:04

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          


        
3条回答
  •  离开以前
    2021-01-15 19:25

    You could re-order the levels of your factor and add the color adjustment:

    dat %>% ggplot(aes(x = rt, 
                       fill = factor(acc, levels = c(1,0)))) + 
      geom_density(aes(y= ..count..*0.03), alpha = 0.6)+
    scale_fill_manual(values = c("1" = "#00BFC4", "0" = "#F8766D"))
    

提交回复
热议问题