Re: [R] Question about graphics in R

From: Jim Lemon <bitwrit_at_ozemail.com.au>
Date: Tue 10 Jan 2006 - 01:47:02 EST

Martin Erwig wrote:
> 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?
>
Hi Martin,

The function color.scale will linearly transform numeric values into colors between arbitrary color endpoints specified as red, green and blue:

Your example would be
redrange=c(0,1),greenrange=c(0,0),bluerange=c(1,0).

For the 2D plot, have a look at color2D.matplot. Both are in the plotrix package.

You might also want to look at colorRampPalette in the grDevices package.

Jim



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Jan 09 09:50:32 2006

This archive was generated by hypermail 2.1.8 : Mon 09 Jan 2006 - 14:17:21 EST