ggplot legend showing transparency and fill color

假装没事ソ 提交于 2019-11-29 09:23:47

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'))

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!