Skip to content
Prev 32793 / 398525 Next

persp & colors

Timur is this what you are looking for?

from Rtips at

http://lark.cc.ukans.edu/~pauljohn/R/statsRus.html#5.42

---------------------------------- Question: is it
possible to shade the 3d surface like a contour plot?
i.e. black for large z, white for small z, say 

Answer: 

# 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)

(from Ross Ihaka) 

Regards,
Michael Grant
--- Timur Elzhov <Timur.Elzhov at jinr.ru> wrote:
https://www.stat.math.ethz.ch/mailman/listinfo/r-help