我正在使用 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
功能,可以轻松地从基础图形升级
.
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)
产量:
关于r - 在 R 曲面图中插入 "cut off"字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36043991/