r - R中使用rgl plot3d的3d散点图-每个数据点的大小不同?

标签 r scatter-plot rgl

我在用

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/

相关文章:

r - 按向量 R 的顺序查找先前最大值的列表

r - 在 Mac/Linux 上从 R 连接到 MS SQL Server

R:使用索引向量中的值将列添加到数据框,包括 NA

javascript - Plotly x轴悬停文本问题

python - matplotlib 3D 散点图,标记颜色对应于 RGB 值

python - 在单轴上绘制值和标签(一维散点图)

r - 在 RGL 中将立方体绘制到 3D 散点图中

r - 通过 R-CMD-check 在 R Mac OS 中安装 rgl 软件包

r - 如何导出交互式 rgl 3D 绘图以共享或发布?

r - 将 R 中具有不同范围间隔的 2 个数据集组合起来,创建一个新数据集,其范围可解释原始数据集中的重叠