在r中绘制散点图3D

时间:2014-07-13 09:27:48

标签: r plot visualization scatter-plot scatter3d

我想在scatterplot3d中可视化我的数据

在我的X和Y轴上,我想要相同的标签。像这样:

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

在Z轴上,我想展示X和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) 

现在我想在scatterplot3d上绘制所有这些信息。如何在scatterplot3d上实现这个概念?

1 个答案:

答案 0 :(得分:2)

如果要绘制点,则需要匹配(x,y,z)值的三元组。您可以使用

创建与x中的位置匹配的yz
xx <- factor(rep(x, 4:1), levels=x)
yy <- factor(unlist(sapply(1:4, function(i) y[i:4])), levels=y)

然后你可以用

画出情节
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))

获取

enter image description here

但老实说,这似乎并不是一种特别有效的可视化。