2017-06-15 86 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

相關問題