[英]3d scatterplot in R using rgl plot3d - different size for each data point?
我在用
plot3d(x,y,z, col=test$color, size=4)
使用R绘制我的数据集的三维散点图,但使用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
为了防止其他人在这些年后偶然发现,现在完全有可能将变量传递给size参数,例如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
应该仍然只能看到每个绘制点的单个大小值。 自从我花了一个多小时左右摆弄这里发布的解决方法之后才意识到这是不必要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.