我想要一个表面图,但是我的网格不完整。我搜索了但没有成功。我该如何做以下工作:
x = c(10L, 20L, 30L, 40L, 50L, 60L, 70L, 80L, 90L, 100L, 30L, 40L,
50L, 60L, 70L, 80L, 90L, 100L, 50L, 60L, 70L, 80L, 90L, 100L,
70L, 80L, 90L, 100L, 90L, 100L)
y = c(10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 30L, 30L, 30L, 30L, 30L, 30L,
40L, 40L, 40L, 40L, 50L, 50L)
z = c(6.093955007, 44.329214443, 149.103755156, 351.517349974,
726.51174655, 1191.039562104, 1980.245204702, 2783.308022984,
6974.563519067, 5149.396230019, 142.236259009, 321.170609648,
684.959503897, 1121.475597135, 1878.334840961, 2683.116309688,
4159.60732066, 5294.774284119, 687.430547359, 1119.765405426,
1876.57337196, 2685.951176024, 3945.696884503, 5152.986796572,
1870.78724464, 2677.744176903, 3951.928931107, 5160.295960254,
3957.503273558, 5147.237754092)
# OK but not a surface plot
scatterplot3d::scatterplot3d(x, y, z,
color = "blue", pch = 19,
type = "h",
main = "",
xlab = "x",
ylab = "y",
zlab = "z",
angle = 35,
grid = FALSE)
# Not working:
M <- plot3D::mesh(x, y, z)
R <- with (M, sqrt(x^2 + y^2 +z^2))
p <- sin(2*R)/(R+1e-3)
plot3D::slice3D(x, y, z, colvar = p,
xs = 0, ys = c(-4, 0, 4), zs = NULL)
plot3D::isosurf3D(x, y, z, colvar = p, level = 0, col = "red")
最佳答案
对于这种问题,我可以推荐使用deldir软件包,该软件包可以进行“Delaunay三角剖分和Dirichlet分割”。由此计算出给出表面图的空间三角形。
rgl-package提供了将三角形添加到散点图中的可能性。甚至更好-生成的绘图具有动画效果,因此您可以旋转和缩放以获得更好的概览。
x = c(10L, 20L, 30L, 40L, 50L, 60L, 70L, 80L, 90L, 100L, 30L, 40L,
50L, 60L, 70L, 80L, 90L, 100L, 50L, 60L, 70L, 80L, 90L, 100L,
70L, 80L, 90L, 100L, 90L, 100L)
y = c(10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 30L, 30L, 30L, 30L, 30L, 30L,
40L, 40L, 40L, 40L, 50L, 50L)
z = c(6.093955007, 44.329214443, 149.103755156, 351.517349974,
726.51174655, 1191.039562104, 1980.245204702, 2783.308022984,
6974.563519067, 5149.396230019, 142.236259009, 321.170609648,
684.959503897, 1121.475597135, 1878.334840961, 2683.116309688,
4159.60732066, 5294.774284119, 687.430547359, 1119.765405426,
1876.57337196, 2685.951176024, 3945.696884503, 5152.986796572,
1870.78724464, 2677.744176903, 3951.928931107, 5160.295960254,
3957.503273558, 5147.237754092)
# create spacial triangles
del <- deldir::deldir(x, y, z = z)
triangs <- do.call(rbind, triang.list(del))
# create plot
rgl::plot3d(x, y, z, size = 5, xlab = "my_x", ylab = "my_y", zlab = "my_z", col = "red")
rgl::triangles3d(triangs[, c("x", "y", "z")], col = "gray")
我希望这有帮助。