R中使用rgl plot3d的3d散点图-每个数据点的大小不同? [英] 3d scatterplot in R using rgl plot3d - different size for each data point?

查看:51
本文介绍了R中使用rgl plot3d的3d散点图-每个数据点的大小不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

plot3d(x,y,z, col=test$color, size=4) 

使用 R 绘制我的数据集的 3d 散点图,但使用 rglsize 参数仅采用一种尺寸.

to plot a 3d scatterplot of my dataset with R, but with rgl the size argument only takes one size.

是否可以为每个数据点设置不同的大小,也许使用另一个库,或者是否有简单的解决方法?

Is it possible to have different sizes for each data point, perhaps with another library, or is there a simple workaround?

感谢您的想法!

推荐答案

这里有一个与 Etienne 建议的方法相同的解决方法.关键思想是设置绘图,然后使用对 points3d() 的单独调用来绘制每个尺寸类中的点.

Here's a work-around along the same lines suggested by Etienne. The key idea is to set up the plot, then use a separate call to points3d() to plot the points in each size class.

# 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() 只想取一个数值.)


(FWIW, it does appear that there's no way to get plot3d() to do this directly. The problem is that plot3d() uses the helper function material3d() to set point sizes and as shown below, material3d() only wants to take a single numeric value.)

material3d(size = 1:7)
# Error in rgl.numeric(size) : size must be a single numeric value

这篇关于R中使用rgl plot3d的3d散点图-每个数据点的大小不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆