我想在这个boxplot上为2个组添加男性和女性平均年龄的标签。到目前为止,我只能通过小组来完成,而不是通过性别和小组来完成。在ggplot2 boxplot上添加多个标签
我的数据帧:
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
@ilir我在编辑后的版本 – Alba
@Alba [this](http://stackoverflow.com/a/13370258/640783)上添加了一些数据可能会有所帮助。 –