[R] questions about image()

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


hi


> 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()
functions.

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

data(volcano)
filled.contour(volcano, color = terrain.colors,
                     plot.axes={ image(volcano, add=T,
col=terrain.colors(21));
                                       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

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

or

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

hope that is of some help

paul


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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