将3d形状添加到现有的rgl对象:alphashape3d

我使用’vegan’包中的metaMDS()对物种数据集进行了这种排序分析.我正在使用多个维度,所以我认为在3d图中显示这些维度中的三个是很好的. ‘素食’包具有一些3d功能,但结果不是很清楚.它可以使用orglspider()函数显示这个“蜘蛛”,这个函数很好但是还不是很清楚.我宁愿拥有像’ordihull’这样的东西,而不是像3d图.使用’alphashape3d’包我可以完成这个.它允许我完全按照我的需要绘制一个3d形状.问题是我需要在同一帧中绘制这些形状中的3个.我试过“add = T”,但这不起作用.我想我可能要改变调用第二和第三个形状的方式,但我不知道如何做到这一点.这是我到目前为止所尝试的一个例子:

### Load the packages
require(vegan)
require(alphashape3d)

### Create some data
a <- c(0.5654292, 0.1960973, 0.0000000, 0.2536315, 0.1960973, 0.4658166, 0.3315565, 0.6865024, 0.7044823, 0.4385855)
b <- c(0.7093823, 0.2409255, 0.3269156, 0.0000000, 0.0000000, 0.3269156, 0.0000000, 0.0000000, 0.0000000, 0.4625978)
c <- c(0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.1022538, 0.4618177, 0.0000000, 0.0000000, 0.0000000)
d <- c(0.00000000, 0.16692171, 0.00000000, 0.22649864, 0.09400543, 0.42456471, 0.79331157, 0.72986751, 0.93837435, 0.65106335)
loc <- c("U", "U", "U", "A", "A", "U", "A", "A", "A", "U")

data <- data.frame(a,b,c,d)

#### Run the mds analysis to obtain the points that should be plotted
mdsB <- metaMDS(data, distance = "bray", autotransform = FALSE, trace = 0,k=3)

### Split the points in the mds object up into two groups
mdsBA <- mdsB
mdsBU <- mdsB

mdsBA$points <- mdsBA$points[which(loc=='A'), ]
mdsBU$points <- mdsBU$points[which(loc=='U'), ]

### Create the 3d shape just like the ordihull function does for 2d shapes
ashape3d.A <- ashape3d(unique(as.matrix(mdsBA$points[,1:3])), alpha = 1.19)
ashape3d.U <- ashape3d(unique(as.matrix(mdsBU$points[,1:3])), alpha = 1.19)

### plot the first shape and try to add the second one. 
plot(ashape3d.A,bycom=TRUE,tran=0.2,shininess=0, col="lightgoldenrod")
plot(ashape3d.U,bycom=TRUE,tran=0.2,shininess=0, col="lightgoldenrod", add=T)

最佳答案 我可能应该等待发布我的问题,因为我自己找到了答案.我通过使用不同的包来创建凸包来解决了这个问题,其中add = T部分确实起作用.我使用“几何”包如下:

library("geometry")
A <- mdsBA$points[,1:3]
F <- mdsBU$points[,1:3]

A.surf <- t(convhulln(A))
U.surf <- t(convhulln(U))

rgl.triangles(A[A.surf,1],A[A.surf,2],A[A.surf,3],col="lightgoldenrod",alpha=0.5, add=T)
rgl.triangles(U[U.surf,1],U[U.surf,2],U[U.surf,3],col="lightgoldenrod",alpha=0.5, add=T)
点赞