2016-05-17 92 views
0

我绘制了整个研究人群(黑线)和男性和女性分别的平均值。R ggplot2 stat_summary legend为组别

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 

的传说只显示性别,可能有人帮我加黑线和点图例为整个集团?

enter image description here

回答

0

您需要添加aes()得到的黑线/分的传奇人物。如果你想传说中加入guide = Fscale_shape_manual,然后使用guidesoverride.aes在图例指定形状成为线/形状的组合,你可以关闭传说的形状:

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)))) 
+0

真棒,非常感谢你许多! – Laura