drawing scatterplot 3D in r

元气小坏坏 提交于 2019-12-13 12:50:38

问题


I would like to visualize my data in a scatterplot3d

On my X and Y axis, I would like the same lables. Something like this:

x<-c("A","B","C","D")
y<-c("A","B","C","D")

on the Z axis, I would like to show the comparision between lables in X and Y

A with A
A with B
A with c
A with D
B with B
B with C
B with D
C with C
C with D
D with D

#altogether 10 values in Z
z<-c(0.25, 0.7, 0.35, 1.14, 0.85, 0.36, 0.69, 0.73, 0.023, 0.85) 

Now I want to draw all of of these infos on scatterplot3d. How can I implement this concept on scatterplot3d?


回答1:


If you want to plot points, you need to match triplets of (x,y,z) values. You can create x and y values matching the positions in z with

xx <- factor(rep(x, 4:1), levels=x)
yy <- factor(unlist(sapply(1:4, function(i) y[i:4])), levels=y)

Then you can draw the plot with

library(scatterplot3d)
scatterplot3d(xx,yy,z, 
    x.ticklabs=c("",x,""), y.ticklabs=c("",y,""), 
    type="h", lwd=2,
    xlim=c(0,5), ylim=c(0,5))

to get

But honestly this doesn't seem like a particularly effective visualization.



来源:https://stackoverflow.com/questions/24721271/drawing-scatterplot-3d-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!