[英]R ggplot2 stat_summary legend mean additional to groups
我已經畫出了整個研究人群的平均值(黑線),分別繪制了男性和女性的平均值。
plotYYIR1<- ggplot(data=YYIR1Long, aes(x=TimeValue, y=YYIR1Value)) +
labs(x="Week number", y="YYIR1 distance run (m)") +
theme(plot.title = element_text(hjust = 0, vjust=0))+
theme(legend.title=element_blank())+
theme(legend.key.width = unit(1, "cm"))+
stat_summary(fun.y = mean,geom = "point", size=2) +
stat_summary(fun.y = mean, geom = "line", size=0.7) +
stat_summary(fun.y = mean,geom = "point", size=2, aes(shape=Sex,colour=Sex)) +
scale_shape_manual(values = c("Male"=17, "Female"=15))+
stat_summary(fun.y = mean, geom = "line", size=0.7, aes(colour=Sex)) +
scale_colour_manual(values = c("#009CEF", "#CC0000"))+
stat_summary(fun.data = mean_cl_normal, geom = "errorbar", width =2)+
stat_summary(fun.data = mean_cl_normal, geom = "errorbar", width =2, aes(colour=Sex))
plotYYIR1
圖例僅顯示性別,有人可以幫我在整個組的圖例中添加黑線和點嗎?
您需要添加aes()
以獲取黑色線條/點的圖例。 如果你想傳說是線/形狀組合可以通過添加關閉對形狀的傳說guide = F
到scale_shape_manual
然后用override.aes
在guides
指定圖例中的形狀:
ggplot(data=YYIR1Long, aes(x=TimeValue, y=YYIR1Value)) +
labs(x="Week number", y="YYIR1 distance run (m)") +
theme(plot.title = element_text(hjust = 0, vjust=0))+
theme(legend.title=element_blank())+
theme(legend.key.width = unit(1, "cm"))+
stat_summary(fun.y = mean,geom = "point", size=2, aes(colour = "mean")) +
stat_summary(fun.y = mean, geom = "line", size=0.7, aes(colour = "mean")) +
stat_summary(fun.y = mean,geom = "point", size=2, aes(shape=Sex,colour=Sex)) +
scale_shape_manual(values = c("Male"=17, "Female"=15, "mean"=16), guide = F)+
stat_summary(fun.y = mean, geom = "line", size=0.7, aes(colour=Sex)) +
scale_colour_manual(values = c("#009CEF", "#CC0000", "#000000"))+
stat_summary(fun.data = mean_cl_normal, geom = "errorbar", width =2, aes(colour = "mean"))+
stat_summary(fun.data = mean_cl_normal, geom = "errorbar", width =2, aes(colour=Sex)) +
guides(colour = guide_legend(override.aes = list(shape = c("Male"=17, "Female"=15, "mean"=16))))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.