我正在尝试在 ggplot2 中创建堆积密度图,并且我还试图了解 qplot 相对于 ggplot 的工作原理。
我在网上找到了下面的例子:
qplot(depth, ..density.., data=diamonds, geom="density",
fill=cut, position="stack")
我尝试将其转换为对 ggplot 的调用,因为我想了解它是如何工作的:
ggplot(diamonds, aes(x=depth, y=..density..)) +
geom_density(aes(fill=cut, position="stack"))
这会创建一个密度图,但不会not堆叠它。
qplot 创建的内容和 ggplot 创建的内容有什么不同?
这是堆积密度图:
![stacked density](https://i.stack.imgur.com/quzkI.png)
非堆叠密度图:
![enter image description here](https://i.stack.imgur.com/cwRFc.png)
原来的例子是here
从 @kohske 的评论来看,这个位置不是审美的,所以不应该在aes
call:
ggplot(diamonds, aes(x=depth, y=..density..)) +
geom_density(aes(fill=cut), position="stack")
![enter image description here](https://i.stack.imgur.com/RTHM0.png)
或使用电影数据(您的示例图表使用):
ggplot(movies, aes(x=rating, y=..density..)) +
geom_density(aes(fill=mpaa), position="stack")
![enter image description here](https://i.stack.imgur.com/WxStr.png)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)