我在用
plot3d(x,y,z, col=test$color, size=4)
使用 R 绘制我的数据集的 3d 散点图,但使用
rgl
size
参数只需要一种尺寸。是否可以为每个数据点设置不同的大小,也许使用另一个库,或者是否有简单的解决方法?
谢谢你的想法!
最佳答案
这是与 Etienne 建议的相同路线的解决方法。关键思想是设置情节,然后单独调用 points3d()
绘制每个尺寸类中的点。
# Break data.frame into a list of data.frames, each to be plotted
# with points of a different size
size <- as.numeric(cut(iris$Petal.Width, 7))
irisList <- split(iris, size)
# Setup the plot
with(iris, plot3d(Sepal.Length, Sepal.Width, Petal.Length, col=Species, size=0))
# Use a separate call to points3d() to plot points of each size
for(i in seq_along(irisList)) {
with(irisList[[i]], points3d(Sepal.Length, Sepal.Width,
Petal.Length, col=Species, size=i))
}
(FWIW,似乎没有办法让
plot3d()
直接做到这一点。问题是 plot3d()
使用辅助函数 material3d()
来设置点大小,如下所示,material3d()
只想取单个数值。)material3d(size = 1:7)
# Error in rgl.numeric(size) : size must be a single numeric value
关于r - R中使用rgl plot3d的3d散点图-每个数据点的大小不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10341963/