我在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)
Run Code Online (Sandbox Code Playgroud) 我试图在这个盒子图上添加两组男性和女性的平均年龄标签.到目前为止,我只能按组进行,而不是按性别和组进行.
我的数据框:
Age=c(60, 62, 22, 24, 21, 23)
Sex=c("f", "m", "f","f","f","m")
Group=c("Old", "Old", "Young", "Young", "Young", "Young")
aging<-data.frame(Age, Sex, Group)
Run Code Online (Sandbox Code Playgroud)
和剧情的命令:
ggplot(data=aging, aes(x=Group, y=Age))+geom_boxplot(aes(fill=Sex))
+geom_text(data =aggregate(Age~Group,aging, mean),
aes(label =round(Age,1), y = Age + 3), size=6)
Run Code Online (Sandbox Code Playgroud)
