2016-05-17 6 views
0

私は全研究集団(黒線)と男性と女性の平均をプロットしました。R ggplot2 stat_summary凡例グループに追加平均

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()を追加する必要があります。あなたは伝説を組み合わせたライン/シェイプのためになりたい場合は、scale_shape_manualguide = Fを追加することによって、図形の凡例をオフにして、凡例でシェイプを指定するために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

関連する問題