[R] specify breaks in divergent palette in RColorBrewer: was divergent colors around zero in levelplot()

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Tue Nov 26 11:12:51 CET 2013

On Tue, Nov 26, 2013 at 9:58 AM, Prof Brian Ripley
<ripley at stats.ox.ac.uk> wrote:

>>   But the image function (and probably levelplot) doesn't allow that so
> Mis-information alert!   The help says
>       col: a list of colors such as that generated by ‘rainbow’,
>            ‘heat.colors’, ‘topo.colors’, ‘terrain.colors’ or similar
>            functions.
> and look at what they generate.  Or see e.g. ?col2rgb .
> Although base graphics has the concept of a palette of colours, AFAIK it
> has always been bolted on top of a general colour specification,
> originally RGB and for many years already RGBA.

 Yes image allows you to specify col=, but it always specifies a
palette. The matrix values are scaled from 1:length(col) and looked up
in that palette. You can't call image with z as matrix of colours and
get those colours, nor set col to a matrix of colours and a see those
colours laid out. This is unlike points() where specifying col= as a
vector of the same length as the number of points gives you a 1:1
mapping of points to colours.

 To do image() with a 1:1 mapping of cell values to colours requires a
tiny bit of hoop-jumping.


More information about the R-help mailing list