ggplot() 线条透明度

问题描述 投票:0回答:1

如何更改

ggplot()
图中线条的透明度(即直方图、线图等)?

例如考虑下面的代码:

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)

我期望这些线条是透明的(如

alpha=.4
),但事实并非如此。

enter image description here

r ggplot2 histogram line-plot
1个回答
39
投票

只需遵循@baptiste的指示

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", linewidth=2, alpha=0.4)

Ceci n'est pas une pipe

© www.soinside.com 2019 - 2024. All rights reserved.