我想生成这样的图表:
但是,我不知道如何使用 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 )
但是我发现条形的宽度限制为 6。这可能是一个限制。当你有更多数据时更好看。
希望它能有所帮助。
关于r - 如何在 R 中绘制 3D 条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29011418/