我正在寻找有关如何使用 Hypervolume 和 rgl 包执行类似于以下 3D 图表的操作的建议,以显示我的数据之间的超体积重叠。:
我正在运行以下代码:
library(hypervolume)
hv1 = hypervolume_svm(specie1, name = "specie1")
summary(hv1)
hv2 = hypervolume_svm(specie2, name = "specie2")
summary(hv2)
hv_set1 <- hypervolume_set(hv1, hv2, check.memory=FALSE)
hypervolume_overlap_statistics(hv_set1)
plot(hv_set1, main="a. Specie 1 vs Specie 2",show.3d=T,
show.axes=T, show.frame=F, show.legend=F, colors = c("green", "red"),
show.centroid = F)
我得到的散点图是错误的 ,
我将获得平滑的 3D 实体。我怎样才能做到这一点?
这是 dput(head(specie1)) 的输出:
> dput(head(specie1))
structure(list(Comp.1 = c(0, 1, 0.782367218362161, 0.0189539143285594,
0.955187776070299, 0.456054304244467), Comp.2 = c(0.506016598824208,
0.216422495760754, 0.919462144900217, 0.681372219919292, 0, 0.476979813131793
), Comp.3 = c(0.435356477269505, 0.537011422304908, 0.738929724677427,
0.289196178254202, 0.621418853480231, 0.603396889027632)), row.names = c(NA,
6L), class = "data.frame")
和 dput(head(specie2)):
> dput(head(specie2))
structure(list(Comp.1 = c(0.472340614903222, 0.325927835046529,
0.245534540132887, 0.272887943374725, 0.384533458010776, 0.439560326282721
), Comp.2 = c(0.719317859710476, 0.225434087659521, 0.476358549235223,
0.323667678599905, 0.803420829967659, 0.48750667692359), Comp.3 = c(0,
0.90482339881728, 0.744437223931766, 0.21705479302961, 0.694891050735555,
0.571969487191824)), row.names = 21:26, class = "data.frame")
您可以使用
alphashape3d
包获得类似的东西。例如,
n <- 200
theta <- seq(0, pi, len = n)
x <- cos(theta) + runif(n, max = 0.5)
y <- sin(theta) + runif(n, max = 0.5)
z <- runif(n, max = 0.5)
xyz <- cbind(x, y, z)
library(rgl)
shape <- alphashape3d::ashape3d(xyz, alpha = 0.5)
plot3d(xyz, pch =".")
aspect3d("iso")
m <- as.mesh3d(shape, smooth = TRUE)
plot3d(m, col = "red", alpha = 0.4, add = TRUE)
创建于 2024-05-06,使用 reprex v2.1.0
你的身材看起来更圆润;如果你可以将它们定义为 x、y 和 z 的某个函数的轮廓,你可以使用
misc3d::contour3d
。