如何在 R 中绘制 3D 堆叠直方图? [英] How does one plot a 3D stacked histogram in R?

查看:51
本文介绍了如何在 R 中绘制 3D 堆叠直方图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 R 中绘制堆叠的直方图;即在第三维中堆叠单个直方图.

I want to plot stacked histograms in R; i.e. stack individual histograms in the third dimension.

感谢大家的建议,尤其是 Shane 的建议.

thank you all for your suggestions, especially the one by Shane.

@hadley,我同意你的观点,但是,我的情况有所不同:我试图通过绘制四个堆叠的直方图来传达的主要观点是尾部差异很大......会被遮住的部分是在我提供的数据中没有任何影响......此外,能够读取频率轴也不重要,因为我将绘制相对频率......

@hadley, I agree with your points, however, my situation is different: the main point I'm trying to convey by plotting four stacked histograms is that the tails vary significantly....the part that will get obscured is of no consequence in the data I'm presenting....also, being able to read the frequency axis is also not important since I'll be plotting the relative frequencies...

推荐答案

您可以尝试使用 rgl (见这里)或3dscatterplot(如在本例中).莱迪思也支持这一点:

You could try using either rgl (see here) or 3dscatterplot (as in this example). Lattice also supports this:

library(lattice) 
library(latticeExtra) 
?panel.3dbars

你可以看到一个例子 在学习者博客上.

You can see an example of this on the Learnr blog.

我不认为这在技术上是堆叠直方图(堆叠直方图将条形堆叠在彼此的顶部).此外,另一种直方图可能会提供更多信息:查看 ggplot2 此处的文档 一些示例.

I don't believe that's technically a stacked histogram (a stacked histogram stacks the bars on top of each other). Moreover, a different kind of histogram could be more informative: look at the ggplot2 the documentation here for some examples.

 hist_cut <- ggplot(diamonds, aes(x=price, fill=cut)) 
 hist_cut + geom_bar() # defaults to stacking 

另一种选择是使用网格代替,在 ggplot2 中使用 facet_wrap(参见 以这篇文章为例).

Another option is to use latticing instead, with facet_wrap in ggplot2 (see this post as an example).

这篇关于如何在 R 中绘制 3D 堆叠直方图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆