Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control color transparency in ggplot2

Tags:

r

ggplot2

I want to control the transparency of manually specified colors using a column 'x' with values 1 to 10. I can do so by adding 'alpha = x' but in that case I see dark color dots in my scatter plot. Can anybody help?

Here is my code:

plot1 <- qplot(data=srna[srna$norm_sum > 0 & srna$len > 18 & srna$len < 25, ], x=position,y=norm_sum,colour= len)
plot1 + geom_point(size=4) +
  theme_bw()+
#   scale_alpha_continuous(range = c(0.1, 0.8))+
  scale_colour_manual(values = c("19" = "pink","20" = "blue","21" = "green", "22" = "yellow","23" = "violet", "24" = "red"))+
  theme(panel.grid.minor.x = element_line(colour='grey94'),panel.grid.minor.y = element_line(colour='grey94'),
        panel.grid.major.x = element_line(colour='lightgrey'),panel.grid.major.y = element_line(colour='lightgrey'))
like image 781
Bade Avatar asked Dec 14 '25 13:12

Bade


1 Answers

Tried to reproduce your question (code below) using the default data from the ggplot2 manual and I got this result. Maybe you can point out what the problems are here?

geom_point, control color transparency in ggplot2

# install.packages("ggplot2", dependencies = TRUE)
library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg))
p + geom_point(size=4, alpha = 0.5, aes(colour = factor(cyl))) + 
       theme_bw() + 
   scale_colour_manual(values = c("4" = "pink","6" = "blue", "8" = "green")) +
    theme(panel.grid.minor.x = element_line(colour='grey94'),
           panel.grid.minor.y = element_line(colour='grey94'),
           panel.grid.major.x = element_line(colour='lightgrey'),
           panel.grid.major.y = element_line(colour='lightgrey'))
like image 175
Eric Fail Avatar answered Dec 16 '25 06:12

Eric Fail



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!