Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot() lines transparency

How to change the transparency level of lines in ggplot() diagram (i.e. histogram, line plot, etc.)?

For instance consider the code below:

data <- data.frame(a=rnorm(100), b = rnorm(100,.5,1.2)) data <- melt(data) colnames(data) <- c("Category", "Intensity") p <- ggplot(data, aes(x=Intensity)) p <- p + geom_density(aes(color=Category), size=2, alpha=.4) print(p) 

I expected the lines would be transparent (as alpha=.4), but they're not.

enter image description here

like image 373
Ali Avatar asked Jan 19 '13 05:01

Ali


People also ask

What does Alpha do in Ggplot?

Alpha refers to the opacity of a geom. Values of alpha range from 0 to 1, with lower values corresponding to more transparent colors.

How do you make a Boxplot transparent in R?

Be default, the boxplot created in base R or by using ggplot2 are not transparent in nature. If we want to create a transparent boxplot then we can use bwplot function from lattice package.


1 Answers

Simply following @baptiste's directions,

data <- data.frame(a=rnorm(100), b = rnorm(100,.5,1.2)) data <- melt(data) colnames(data) <- c("Category", "Intensity") p <- ggplot(data, aes(x=Intensity)) p + geom_line(aes(color=Category), stat="density", size=2, alpha=0.4) 

Ceci n'est pas une pipe

like image 134
Eric Fail Avatar answered Sep 29 '22 06:09

Eric Fail