R 如何将指南添加到ggplot2?

R 如何将指南添加到ggplot2?,r,ggplot2,R,Ggplot2,我有以下代码: ggplot() + stat_smooth(data=fd.area.dfa.quant,aes(x=area,y=q50),alpha=0.6,colour="Red")+ stat_smooth(data=fd.area.dfb.quant,aes(x=area,y=q50),alpha=0.6,colour="Green")+ stat_smooth(data=fd.area.cfa.quant,aes(x=area,y=q50),alpha=0.6,col

我有以下代码:

ggplot() + 
  stat_smooth(data=fd.area.dfa.quant,aes(x=area,y=q50),alpha=0.6,colour="Red")+
  stat_smooth(data=fd.area.dfb.quant,aes(x=area,y=q50),alpha=0.6,colour="Green")+
  stat_smooth(data=fd.area.cfa.quant,aes(x=area,y=q50),alpha=0.6,colour="Purple")+
  stat_smooth(data=fd.area.csb.quant,aes(x=area,y=q50),alpha=0.6,colour="Blue")+
  stat_smooth(data=fd.area.bsk.quant,aes(x=area,y=q50),alpha=0.6,colour="Orange")+
  scale_x_log10("xlab",expand = c(0, 0),labels=comma)+
  scale_y_log10("ylab", expand = c(0, 0.05),labels=comma)+
  theme(aspect.ratio=1)+
  ggtitle("title")+
  ggsave("save2.png")
这就是数字

我想

  • 在五行中分别添加一个名称(例如:DFA、DFB、CFA、CSB、BSK)
  • 之后,我想在show_指南中用相应的颜色显示名称
  • 另外,所有生产线都有不同的尺寸,因此我避免熔化


    我该怎么做呢?

    既然您没有共享任何示例数据以使代码成为a,我将使用我自己的,您可以修改它

    d1<-data.frame(x=1:10, y=cumsum(runif(10)))
    d2<-data.frame(x=1:10, y=cumsum(runif(10)))
    
    ggplot() + 
      stat_smooth(data=d1,aes(x,y,colour="mya"),alpha=0.6)+
      stat_smooth(data=d2,aes(x,y,colour="myb"),alpha=0.6)+
      scale_color_manual(name="Line",values=c(mya="red",myb="green"))
    

    d1融合和使用
    NA
    即使在不同的域中也能正常工作。