R 项目:使用 Plot3D 包绘制 3d 网格(网格)

R Project: Plot a 3d Mesh (grid) using Plot3D package

我正在尝试绘制一个带有长方体元素的 3d 网格(使用 R 的 Plot3D 包透明,但是我找不到好的解决方案。有什么建议吗?objective 是将 3D 网格添加到使用函数 scatter3D.

的 3d 散点图

我写了下面的代码解决了我的问题。我使用了 Plot3D 包的函数 'lines3D'。如果您能提供更优雅的方法来避免循环,我将不胜感激。

library(plot3D)
library(plot3Drgl)
x_grid <- y_grid  <- seq(0 , 1000, 200)
z_grid<-seq(0 , 500, 100)
# plot a 3-D mesh

M <- mesh(x_grid, y_grid, z_grid)
# plot result

dev.new()
scatter3D(M$x, M$y, M$z, pch = "-", cex = 0.1, colkey = FALSE,ticktype = "detailed")

for(i in 1:length(z_grid)){
for(j in 1:length(y_grid)){
lines3D(x = c(min(x_grid), max(x_grid)), y = c(y_grid[j],y_grid[j]), z = c(z_grid[i],z_grid[i]),colkey = FALSE,add=TRUE)}}

for(i in 1:length(x_grid)){
for(j in 1:length(y_grid)){
lines3D(x = c(x_grid[i],x_grid[i]), y = c(y_grid[j],y_grid[j]), z = c(min(z_grid), max(z_grid)),colkey = FALSE,add=TRUE)}}

for(i in 1:length(x_grid)){
for(j in 1:length(z_grid)){
lines3D(x = c(x_grid[i],x_grid[i]), y = c(min(y_grid), max(y_grid)), z = c(z_grid[j],z_grid[j]),colkey = FALSE,add=TRUE)}}

plotrgl(new = TRUE)