我将尝试为这两组的箱线图添加男性和女性平均年龄标签。到目前为止,我只能按组别而不是按性别和组别来做到这一点。
我的数据框如下:
我的数据框如下:
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)