# [R] persp plot question..

Ross Ihaka ihaka at stat.auckland.ac.nz
Thu Oct 26 21:28:47 CEST 2000

```On Fri, Oct 27, 2000 at 12:42:41AM +1300, Ross Ihaka wrote:

Bill Simpson points out that I messed up in my code (never make last minute
readability changes).  Here is a correct version (with the function changed

#  Create a simple surface  f(x,y) = x^2 - y^2

nx <- 21
ny <- 21
x <- seq(-1, 1, length = nx)
y <- seq(-1, 1, length = ny)
z <- outer(x, y, function(x,y) x^2 - y^2)

#  Average the values at the corner of each facet
#  and scale to a value in [0, 1].  We will use this
#  to select a gray for colouring the facet.

hgt <- 0.25 * (z[-nx,-ny] + z[-1,-ny] + z[-nx,-1] + z[-1,-1])
hgt <- (hgt - min(hgt))/ (max(hgt) - min(hgt))

#  Plot the surface with the specified facet colours.

persp(x, y, z, col = gray(1 - hgt), theta = 35)
persp(x, y, z, col = cm.colors(10)[floor(9 * hgt + 1)], theta = 35)

Ross
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```