change alpha, different lines

Here is a simple example of setting the alpha of each line. I made them all red to ease the comparison of the alpha.

library(ggplot2)
DF <- data.frame(X = rep(1:4, 4),
                 Y = rnorm(16),
                 GRP = rep(c("A","B","C","D"), each = 4))
ggplot(DF, aes(x = X, y = Y, group = GRP, color = GRP, alpha = GRP)) + 
  geom_line(linewidth = 2) +
  scale_color_manual(values = c(A = "red", B = "red", 
                                C = "red", D = "red")) +
  scale_alpha_manual(values = c(A = 0.1, B = 0.3, C = 0.55, D = 0.75))

Created on 2024-03-19 with reprex v2.0.2

1 Like