[Rd] Bug: persp and colors (PR#1476)
Wed, 24 Apr 2002 12:07:46 +1200
> I am working with the persp command. I want to change to color of the
> to their z-value. The colors seems to be transposed, i.e. the color of a
> to be used for a facet B which is a (defined?) way off....
> An example:
> 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)
> hgt <- z / max(z)
> persp(x, y, z, col = gray(1 - hgt), theta = 70, phi = 40, expand = 0.4)
> Now the z-value should define the color, but the color pattern seems to be
I don't think this is a bug -- I think the problem is that the surface
produced for the z of dimension 21x21 has only 20x20 facets. For example,
the following is not a solution, but it shows that a 20x20 colour matrix
produces the expected result ...
persp(x, y, z, col = gray(hgt[1:20,1:20]), theta = 0, phi = 40, expand =
... now, what you really want I guess is to calculate hgt to be some
interpolation of the four z values at the four corners of each face. I am
due somewhere so this calculation is left as an exercise ...
r-devel 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: email@example.com