我正在尝试在此箱形图上为 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)