I'm trying to create a stacked density graph in ggplot2, and I am also trying to understand how qplot works relative to ggplot.
I found the following example online:
qplot(depth, ..density.., data=diamonds, geom="density",
fill=cut, position="stack")
I tried translating this into a call to ggplot because I want to understand how it works:
ggplot(diamonds, aes(x=depth, y=..density..)) +
geom_density(aes(fill=cut, position="stack"))
This creates a density graph, but does not stack it.
What is the different between what qplot is creating and what ggplot is creating?
Here is a stacked density graph:
Non-stacked density graph:
Original example is here
From @kohske's comment, the position is not an aesthetic, and so should not be inside the
aes
call:or using the movies data (which your example graphs use):