I'm trying to generate a density plot using ggplot in which the color and fill of the plot is determined by one parameter and the alpha of the fill is determined by a second parameter.
I can get the figure to render the way that I want but in the legend the value of alpha is not depicted.
Since I am setting the values of alpha to 0 and 0.3, I would hope that the legend would show boxes with the corresponding opacity, (i.e. a white one and a gray one). Instead there are two boxes with the same opacity.
Any suggestions will be greatly appreciated.
I have recreated the issue with an example plot using mtcars
ggplot(
mtcars,
aes(
x=wt,
fill=factor(cyl),
color=factor(cyl),
alpha=factor(am)
)
) +
geom_density() +
scale_alpha_discrete(
name="transmission",
labels=c("auto","manual"),
range = c(0,0.3)
) +
theme_bw()
linetype
s orfacets
instead ofalpha
. – Martin Schmelzer