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

时间:2021-09-02 14:58:36

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

我想在R中绘制堆积的直方图;即,在第三维中堆叠各个直方图。


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

2 个解决方案

#1


6  

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

您可以尝试使用rgl(请参阅此处)或3dscatterplot(如本示例中所示)。莱迪思也支持这个:

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).

另一个选择是使用latticing,使用ggplot2中的facet_wrap(作为示例参见此文章)。

#2


8  

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轴读取值。

#1


6  

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

您可以尝试使用rgl(请参阅此处)或3dscatterplot(如本示例中所示)。莱迪思也支持这个:

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).

另一个选择是使用latticing,使用ggplot2中的facet_wrap(作为示例参见此文章)。

#2


8  

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轴读取值。