我该如何在R中绘制三维函数?

5

我有一个涉及3D的函数,我们称之为De Jong函数:

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

我该如何在3D中绘制它的图像?我想要实现与维基百科类似的效果: http://en.wikipedia.org/wiki/File:Sphere_function_in_3D.pdf

请查看emdbook包中的curve3d()函数。 - Ben Bolker
stackoverflow.com/questions/11875941/3d-equivalent-of-the-curve-function-in-r/ - Ben Bolker
2个回答

9

尝试这个:

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


这几乎是我想要的,但是否有办法像维基百科中的图表那样给它着色(颜色取决于函数值)? - SathOkh
+1 使用基本函数!! - Shambho

8

您还可以使用Lattice的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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接