简体   繁体   中英

ggplot legend key color and transparency

I'm plotting multiple lines together and they are transparent. However, I do not want the legend color to have any transparency. I attempted the override.aes but without success. This is similar to this question , but essentially the opposite.

Currently I have this

# plot all the lines
plt <- ggplot(dt_plot,aes(x = x, y = mean_change, color = model)) +
        geom_line(aes(group = interaction(model, boot)), alpha = 0.3) +
        xlab('houses/acre') + 
        ylab('change in % prevalance') +
        scale_colour_manual(values=cbbPalette) + 
        theme_few()  + 
        theme(text=element_text(size=10),legend.title = element_blank()) + 
        guides(fill = guide_legend(override.aes= list(alpha = 1)))

透明线条和透明图例颜色

Cheers

Your approach is perfectly fine except for one small issue: you need

guides(color = guide_legend(override.aes = list(alpha = 1)))

instead as geom_line doesn't have the fill aesthetic.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM