[R] Question about graphics in R

Martin Erwig erwig at eecs.oregonstate.edu
Sat Jan 7 18:47:11 CET 2006

Considering the R function/plot shown below, I wonder whether
it is possible to do the following changes:

(1) Change the color of each point to be picked from
list of colors according to its z-value. (The range
should be from blue (z=0) to red (z=1).) The grid
should then be omitted. [I have seen "terrain.colors", but
don't know how to use it for this purpose.]

(2) Add two lines to the surface for, say z=0.8 and
z=0.3. [Can contour or contourLines be used?]


x <- seq(0, 1, length = 50)
y <- x
f <- function(x,y) { sin ((1-x)*y) }
z <- outer(x,y,f)

persp(x, y, z,
	theta = 30, phi = 30,
	shade = 0.3, col = "red"


Finally, I would also produce a flattened 2D map
of the same function, i.e. a map in which each point
(x,y) is mapped to a color in a range according to
f(x,y). Also two lines for f(x,y)=c1 and f(x,y)=c2
should be added.

Is this possible?

I would be grateful for any hints.


More information about the R-help mailing list