r - 如何在 R 中绘制 3D 条形图

标签 r plot 3d

我想生成这样的图表:

3D bar plot

但是,我不知道如何使用 R 来做到这一点。我想知道是否有人知道在 R 中做到这一点的解决方案?

最佳答案

我会使用包 rgl。

library(rgl)

# load your data
X= c(1:6)
Y=seq(10,70, 10)
Z=c(-70, -50, -30, -20, -10, 10)

# create an empty plot with the good dimensions
plot3d(1,1,1, type='n', xlim=c(min(X),max(X)), 
                        ylim=c(min(Y),max(Y)), 
                        zlim=c(min(Z),max(Z)), 
                        xlab="", ylab="", zlab="", axe=F )

# draw your Y bars
for(i in X){ segments3d(x = rep(X[i],2), y = c(0,Y[i]), z=0, lwd=6, col="purple")}

# do the same for the Z bars
plot3d(X,0,Z, add=T, axe=F, typ="n")
for(i in X){segments3d(x = rep(X[i],2), y = 0, z=  c(0,Z[i]), lwd=6, col="blue" )}

# draw your axis
axes3d()
mtext3d(text = "Time (days)", edge = "y+", line =3, col=1 )
mtext3d(text = "Change %", edge = "z++", line = 5, col=1 )

view plot

但是我发现条形的宽度限制为 6。这可能是一个限制。当你有更多数据时更好看。

希望它能有所帮助。

关于r - 如何在 R 中绘制 3D 条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29011418/

相关文章:

iphone - iPhone 上的 3D 头部追踪

python - 如何根据从文件读取的数据 z=f(x,y) 在 matplotlib 中制作 3D 绘图

r - 如何使用 R DBI 保护数据库用户名和密码?

r - ggplot2 中具有两种色阶的并排堆叠条形图

r - 在给定日期-30天之内对学生的最新分数进行排名

r - 修改 R 包的源代码

python - 当 x 轴不等距时,Matplotlib 不会连接数据点

r - 如何使用灰度按原样在 R 中绘制矩阵?

javascript - CSS3 Transform Matrix3D 动画故障,为什么?

r - 绘制一个变量变化而其他变量不变的模型的函数