2017-06-15 39 views
1
A=seq(10,12) 
B=seq(1,3) 
C=seq(20,22) 
df=melt(data.frame(A,B,C)) 

ggplot(df,aes(variable,value))+ 
stat_summary(
    geom="errorbar", 
    fun.data=mean_se, 
    aes(color="Error bars",group=variable))+ 
scale_color_manual(
    values=c("red","blue"))+ 
geom_point(
    aes(color="Data points")) 

如果您查看图例,图例会显示蓝色和红色的“线条+点”形状。ggplot2:在图例中“un-integrate”不同的几何形状

如果图例显示蓝色匹配到“线条”形状,红色匹配到“点”形状,我希望它。

有没有办法做到这一点?

回答

2

可以重写传奇美学如下

ggplot(df,aes(variable,value))+ 
     stat_summary(
     geom="errorbar", 
     fun.data=mean_se, 
     aes(color="Error bars",group=variable))+ 
     scale_color_manual(
     values=c("red","blue"))+ 
     geom_point(
     aes(color="Data points")) + 
     guides(fill = guide_legend(override.aes = list(linetype = 0, shape='')) 
      , color = guide_legend(override.aes = list(linetype=c(0,1) 
                 , shape=c(16,NA)))) 

生产:

enter image description here

相关问题