How do I make a smooth line with transparency show transparency in legend?

Hi All,

Does anyone know how to make a smoothed line with transparency show transparency in legend?

Is this a bug, or am I doing something wrong??

See example below

library(ggplot2)
library(palmerpenguins)

ggplot(penguins) +
  geom_smooth(aes(bill_length_mm, body_mass_g, col = species)) +
  scale_color_manual(values = scales::alpha(c("red", "blue", "green"), 0.1)) 

Usually you can do this by overriding aesthetics in guides(), but the alpha transparency seems to only affect the confidence bars - so I'm not sure there is a simple way to do it, but this works:

library(ggplot2)
library(palmerpenguins)

ggplot(penguins, aes(bill_length_mm, body_mass_g, color = species)) +
  geom_smooth(alpha = 0.3, size = 0) +
  stat_smooth(geom = "line", alpha = 0.3) +
  scale_color_manual(values = c("red", "blue", "green"))

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.