[R] questions about image()

Paul Murrell paul at stat.auckland.ac.nz
Thu Feb 3 22:17:03 CET 2000


> 1.  How do I get a color key on the plot?

its possible, but you'll have to do it by hand.  take a look at
filled.contour() and see if that does the sort of key you are after.  If so,
look at the filled.contour() code (e.g., by typing "filled.contour<return>")
for an example of how to produce such a key using the layout() and rect()

if you want a quick, dirty fix, you can piggy-back on the filled.contour()
code.  for example:

filled.contour(volcano, color = terrain.colors,
                     plot.axes={ image(volcano, add=T,
                                       axis(1); axis(2); })

but you would have to be careful to coordinate the colours used by
filled.contour() and the colours used by image(), and this is not a
long-term solution, and figuring out how it works may be just as much work
as writing your own function :)

> 2.  What I'd like to have is 0=white, 1=red, -1=blue (or any other color),
> and numbers in between represented by different shade (e.g., 0.1 would be
> light pink, -0.1 would be light blue, etc.).  Is this possible?

you can specify an arbitrary range of colours using the rgb() function.  for
example, try

points(1:10, col=rgb(10:1/10, rep(0,10), 1:10/10))


image(volcano, col=rgb(10:1/10, rep(0,10), 1:10/10))

hope that is of some help


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

More information about the R-help mailing list