如何在 R 中绘制 3D 条形图 [英] How to do 3D bar plot in R

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

问题描述

我想制作这种图表:

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

However, I don't know how to do it using R. I was wondering if someone knew a solution to do it in 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 )

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

However I have found the width of the bars restricted to 6. That could be a limit. Better looking when you have more data.

希望能帮到你.

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

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