ggplot legend showing transparency and fill color

后端 未结 1 1308
执笔经年
执笔经年 2020-12-18 22:45

I\'m plotting two semi-transparent ribbons together. Using the code below, without the scale_fill_manual portion, I get basically what I want, with a legend cal

相关标签:
1条回答
  • 2020-12-18 23:17

    You can override the aesthetics in the legend by adding:

    + guides(fill = guide_legend(override.aes= list(alpha = 0.4)))
    

    to your ggplot call.

    But as with most things in ggplot, it is probably simpler to arrange your data in a way that makes the multiple geom_ribbon calls unnecessary:

    dt1 <- data.frame(x = c(x,x),
                      ymin = c(y1,y3),
                      ymax = c(y2,y4),
                      grp = rep(c('red','blue'),each = 10))
    ggplot(data = dt1,aes(x = x,ymin = ymin, ymax = ymax,fill = grp)) + 
        geom_ribbon(alpha = 0.4) + 
        scale_fill_manual(name = "legendname",
                          values = c('red','blue'),
                          labels = c('one','two'))
    

    enter image description here

    0 讨论(0)
提交回复
热议问题