【发布时间】:2014-04-27 20:28:16
【问题描述】:
我正在尝试在此箱线图上为 2 组添加带有男性和女性平均年龄的标签。到目前为止,我只能按组进行,但不能按性别和组进行。
我的数据框:
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)
剧情命令:
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)
【问题讨论】:
-
能否提供一些最小的数据,以便我们直接测试代码?
-
@ilir 我在帖子的编辑版本上添加了一些数据
-
@Alba this 可能会有所帮助。