如何在r中绘制3D功能?

时间:2014-06-05 16:36:06

标签: r plot

我有一个3D功能 - 让我们说De Jong功能:

fdejong <- function (x, y) {
   return (x^2 + y^2)
}

我如何在3D中绘制它的情节?我想从维基百科中获得类似的效果:

http://en.wikipedia.org/wiki/File:Sphere_function_in_3D.pdf

2 个答案:

答案 0 :(得分:6)

试试这个:

fdejong <- function (x, y) {
   return (x^2 + y^2)
}


x <- seq(-10, 10, length= 30)
y <- x
z <- outer(x, y, fdejong)
z[is.na(z)] <- 1
op <- par(bg = "white")
persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue")

fdejong persp plot

答案 1 :(得分:4)

您也可以使用莱迪思wireframe功能。 (使用@ user1020027的数据)

fdejong <- function (x, y) {
   return (x^2 + y^2)
}

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

require(lattice)
wireframe(z, drape=T, col.regions=rainbow(100))

lattice wireframe color plot