ggplot legend key color and transparency
Asked Answered
C

1

5

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

transparent lines and transparent legend colors

Cheers

Carey answered 7/2, 2019 at 18:43 Comment(2)
Perhaps guides(color = ... rather than guides(fill = ...? Otherwise, we need a reproducible example.Korney
champion - that did it. would you like to post it as an answer and I'll accept it. thank you!!Carey
K
6

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.

Korney answered 7/2, 2019 at 19:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.