![](/img/trans.png)
[英]Individually change x labels using expressions in ggplot2 boxplot with facet_grid in R
[英]Highlight data individually with facet_grid in R
我在R中使用facet_grid来绘制5个不同组的RT数据。 我想强调每个组的5%到95%之间的数据。
在下面的代码中,我使用的是整个数据帧的百分位数,而不是每个组的百分位数。 关于如何仍然可以使用facet_grid并在图表中突出显示每个组的唯一百分位数的任何想法。
rect <- data.frame (xmin=quantile(ss$RT, c(0.05)),
xmax=quantile(ss$RT, c(0.95)),
ymin=-Inf, ymax=Inf)
qplot(prevRT, RT, group=ss, color = prim,
geom = c("smooth"),
method="lm", data =ss) +
facet_grid(~ Groupe) +
geom_rect(data=rect,
aes(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax),
color="grey20", alpha=0.5, inherit.aes = FALSE)
多亏了DWin的建议,我使用ave分别找到每个组的xmin和xmax并将其直接合并到绘图命令中。
可能有一种更优雅的方法(欢迎提出建议),但是它可行。
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.