문제

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

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top