I have a ggplot that plots 4 different series as lines. I would like to set each line to a different transparency. How do I do this? More specifically, I want two of the lines to be transparent and two lines to be opaque. I am aware of how to set all lines to the same transparency with alpha, but now how to set the transparency individually.
Here is example data and code:
mydata = data.frame(rep(1:4,4),runif(16),c(rep("A",4),rep("B",4),rep("C",4),rep("D",4)))
colnames(mydata) = c("month","price","series")
library(ggplot2)
ggplot(mydata,aes(month,price,color=series))+geom_line()
Direct alpha
to an aesthetic variable and use scale_alpha_manual
ggplot(mydata,aes(month,price,color=series, alpha=series)) +
geom_line() +
scale_alpha_manual(values = c(0.1, 0.1, 1, 1))
The order of c(0.1, 0.1, 1, 1)
will of course depend on which lines you want opaque.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With