GGPLOT2 3D条形图条形图

2023-09-07 17:26:17 作者:时光冷透少年郎

我知道这听起​​来很简单,但是有一个一直在寻找字面上一个多小时,现在都没有成功。我只是想要绘制三维条形图中的'R'使用'GGPLOT2'包。我的数据框看起来是这样的:

I Know this sounds basic, but have a been searching for literally more than an hour now without success. I'm simply trying to plot a 3D bar plot in 'R' using the 'ggplot2' package. My dataframe looks something like this:

 x   y     z
t1   5   high
t1   2   low
t1   4   med
t2   8   high
t2   1   low
t2   3   med
t3  50   high
t3  12   med
t3  35   low

和我想绘制这样的事情就可以了:

and I want to plot something like this on it:

任何帮助超过AP preciated !!

Any help is more than appreciated!!

推荐答案

正如评论,3D绘图通常不是一个好的选择(当其他选项),因为它们往往给数据的失真/模糊看法

As mentioned in comments, 3D plots usually aren't a good choice (when other options are available) since they tend to give a distorted/obscured view of data.

这是说,这里是根据需要与 latticeExtra 如何绘制你的数据:

That said, here's how you can plot your data as desired with latticeExtra:

d <- read.table(text=' x   y     z
t1   5   high
t1   2   low
t1   4   med
t2   8   high
t2   1   low
t2   3   med
t3  50   high
t3  12   med
t3  35   low', header=TRUE)

library(latticeExtra)

cloud(y~x+z, d, panel.3d.cloud=panel.3dbars, col.facet='grey', 
      xbase=0.4, ybase=0.4, scales=list(arrows=FALSE, col=1), 
      par.settings = list(axis.line = list(col = "transparent")))