在 R 曲面图中插入 "cut off" 字段

Insert "cut off" field in R surface plot

我正在使用 persp() 创建 3d 图(但我愿意接受任何可以完成工作的方法)。现在我想添加一个 2d 字段以明确 3d 图在特定 Z 值上方的位置。有没有办法做到这一点?理想情况下,它应该是类似于半透明表面的东西,您可以在其中看到表面下方和上方的质量。

使用 persp 文档中的示例

f <- function(x, y) { r <- sqrt(x^2+y^2); 10 * sin(r)/r }

x <- seq(-10, 10, length= 30)
y <- x
z <- outer(x, y, f)
z[is.na(z)] <- 1

persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue",
      ltheta = 120, shade = 0.75, ticktype = "detailed",
      xlab = "X", ylab = "Y", zlab = "Sinc( r )"
) 

如何插入一个在 z 轴的特定点对图形进行切片的字段?

这个怎么样 - 使用 rgl 包有更多的可能性,但它有一个 persp3d 功能可以从基础 graphics.[=15= 轻松升级]

library(rgl)

f <- function(x, y) { r <- sqrt(x^2+y^2); 10 * sin(r)/r }
x <- seq(-10, 10, length= 30)
y <- x
z <- outer(x, y, f)
z[is.na(z)] <- 1

persp3d(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue",
      ltheta = 120, shade = 0.75, ticktype = "detailed",
      xlab = "X", ylab = "Y", zlab = "Sinc( r )")

# Here we add a transparent purple square to mark the top

# x and y mark the corners of the purple square, z is its height
sqdf <- data.frame(x=c(-10,-10,10,10,-10),
                   y=c(-10, 10,10,-10,-10),
                   z=c(5,5,5,5,5))

# now draw the purple square, 
#    note:
#    -  the "add=T" parameter that appends it to the previous 3d-plot
#    -  the coord paramter tells it what two planes to use when 
#        tesselating the polygon into triangles 
#        (a necessary step and expensive to calculate)

polygon3d(sqdf$x,sqdf$y,sqdf$z,coord=c(1,2),alpha=0.5,color="purple",add=T)

产量: