我正在使用
plot3d(x,y,z, col=test$color, size=4)
我想使用R绘制我的数据集的三维散点图,但是使用rgl
时,size
参数只能接受一个大小。
是否可能为每个数据点设置不同的大小,也许使用另一个库,或者有简单的解决方法吗?
感谢您的建议!
我正在使用
plot3d(x,y,z, col=test$color, size=4)
我想使用R绘制我的数据集的三维散点图,但是使用rgl
时,size
参数只能接受一个大小。
是否可能为每个数据点设置不同的大小,也许使用另一个库,或者有简单的解决方法吗?
感谢您的建议!
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))
}
plot3d()
实现这一点的方法。问题在于plot3d()
使用辅助函数material3d()
设置点大小,如下所示,material3d()
只想要一个单一的数值。)material3d(size = 1:7)
# Error in rgl.numeric(size) : size must be a single numeric value
rgl
。否则,你可以尝试类似于scatterplot3d
的东西。可以想象,rgl
可以被黑客攻击/更新以允许有效的每点大小规格,但值得知道为什么值得这样做... - Ben Bolker以防其他人在几年后遇到此问题,现在完全可以将变量传递到大小参数中,例如:with(test, plot3d(x,y,z, col=test$color, size=test$size))
。
实际上,您可以对传递给大小的数据进行操作,它也可以正常工作。我成功地使用了类似于 size = x/(max(x,na.rm=TRUE)-min(x,na.rm=TRUE))
的基本大小比例。
虽然 material3d
只接受单个数字值,但应先评估 with 语句中传递给大小的表达式或变量,因此 material3d
对于每个绘制点仍然只会看到单个大小值。只是提醒一下,因为我花了大约一个小时左右尝试这里发布的解决方法,然后才意识到它是不必要的。