Legend with geom_line and geom_ribbon

前端 未结 3 1379
误落风尘
误落风尘 2020-12-30 07:08

I am creating a figure where I have a line and confidence bands around it. To do this, I am using both geom_line and geom_ribbon in ggplot2

3条回答
  •  鱼传尺愫
    2020-12-30 08:02

    You can make to separate legends - one for the color of line and one for the fill of the ribbon. Then with scale_... set the names for the legend to blank. Only problem is that legend keys will be separated.

    ggplot(plotdata) + geom_line(aes(y=y, x=x, colour = "sin"))+
          geom_ribbon(aes(ymin=lower, ymax=upper, x=x, fill = "band"), alpha = 0.3)+
          scale_colour_manual("",values="blue")+
          scale_fill_manual("",values="grey12")
    

    enter image description here

提交回复
热议问题