简体   繁体   中英

Control color transparency in 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'))

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,控制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'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM