Highlight data individually with facet_grid in R

后端 未结 1 1663
耶瑟儿~
耶瑟儿~ 2021-01-18 10:24

I am using facet_grid in R to plot RT data for 5 different groups. I would like to highlight the data between 5 and 95% for each group.

With the code below, I am usi

相关标签:
1条回答
  • 2021-01-18 10:46

    Thanks to DWin's suggestion, I used ave to find xmin and xmax for each group individually and incorporated that directly into the command for the plot.

    There is probably a more elegant way to do that (and suggestions are welcome), but it works.

    qplot(prevRT, RT, group=ss, color = prim, 
     geom = c("smooth"), 
     method="lm", data =ss) + 
     facet_grid(~ Groupe) + 
     geom_rect(data=ss, 
          aes(xmin=ave(ss$RT, ss$Groupe, FUN = function(x)quantile(x,c(0.05))),      
          xmax=ave(ss$RT, ss$Groupe, FUN = function(x)quantile(x,c(0.95))),
          ymin=-Inf,ymax=Inf), color="green", alpha=1/280, inherit.aes = FALSE)
    

    enter image description here

    0 讨论(0)
提交回复
热议问题