简体   繁体   English

如何在R中绘制3D堆积直方图?

[英]How does one plot a 3D stacked histogram in R?

I want to plot stacked histograms in R; 我想在R中绘制堆积的直方图; ie stack individual histograms in the third dimension. 即在第三维中堆叠单个直方图。


thank you all for your suggestions, especially the one by Shane. 谢谢大家的建议,特别是谢恩的建议。

@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... @hadley,我同意你的观点,但是,我的情况有所不同:我试图通过绘制四个叠加的直方图来传达的主要观点是尾部变化很大......被遮挡的部分无关紧要在我提出的数据中......同样,能够读取频率轴也不重要,因为我将绘制相对频率......

One doesn't. 一个没有。 This is a terrible display of data because the front histograms obscure the rear histograms and the perspective makes it just about impossible to read the values off the y-axis. 这是一个糟糕的数据显示,因为前直方图遮挡了后方直方图,而透视使得几乎不可能从y轴读取值。

You could try using either rgl ( see here ) or 3dscatterplot (as in this example ). 您可以尝试使用rgl请参阅此处 )或3dscatterplot (如本示例所示 )。 Lattice also supports this: 莱迪思也支持这个:

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

You can see an example of this on the Learnr blog . 您可以在Learnr博客上看到此示例。

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. 此外,不同类型的直方图可能会提供更多信息:请参阅ggplot2这里的文档以获取一些示例。

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

Another option is to use latticing instead, with facet_wrap in ggplot2 (see this post as an example ). 另一种选择是使用facet_wrap ,使用facet_wrap中的facet_wrap( 作为示例参见本文 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM