From b.rowlingson at lancaster.ac.uk  Thu May 21 16:12:54 2009
From: b.rowlingson at lancaster.ac.uk (Barry Rowlingson)
Date: Thu, 21 May 2009 15:12:54 +0100
Subject: [Rd] Colour Schemes
In-Reply-To: <OFDAD6BC3C.A2BA778D-ON802575BD.004783B8-802575BD.00491507@hsl.gov.uk>
References: <d8ad40b50905210444q406e1a2ak8313d495975d1919@mail.gmail.com>
	<OFDAD6BC3C.A2BA778D-ON802575BD.004783B8-802575BD.00491507@hsl.gov.uk>
Message-ID: <d8ad40b50905210712k128ecfa2vff2dd178f946680d@mail.gmail.com>

On Thu, May 21, 2009 at 2:18 PM,  <Richard.Cotton at hsl.gov.uk> wrote:

> Most of the plots where colour is typically used to signify a variable
> already do map colours to data values. ?Take a look at help pages for
> levelplot/contourplot/wireframe from the lattice package, and image from
> base graphics.
>
> (The format is typically slightly different to your suggested
> specification, though the principle is the same. ?The functions take a
> vector of cut points, and a vector of colours.)

 The problem here is that the user doesn't have exact control of the
mapping from value to colour. For example (using a slightly more
safe-for-use-after-lunch version of the levelplot example grid):

     x <- seq(pi/4, 5 * pi, length.out = 100)
     y <- seq(pi/4, 5 * pi, length.out = 100)
     r <- as.vector(sqrt(outer(x^2, y^2, "+")))
     grid <- expand.grid(x=x, y=y)
     grid$z <- r
     grid$z2 = r *0.5


Then I do:

  levelplot(z~x*y, grid, cuts = 5, col.regions=rainbow(5))

 very nice, but suppose I want to show $r2 on the same colour scale, I
can't just do:

 levelplot(z2~x*y, grid, cuts = 5, col.regions=rainbow(5))

 because that looks the same as the first one since levelplot uses the
whole colour range.


 The base graphics "image" function has zlim arguments which let you do:

 z=outer(1:10,1:10,"*")
 image(z)
 image(z/2, zlim=range(z))

 but again, not obvious, and complex/impossible when using more
sophisticated colour mappings.

> There may be some utility in creating functions to generate these colour
> maps outside of the plotting functions, if only so that the code can be
> recycled for new functions.

 Exactly, it would make a new package.

Barry



[Rd] Colour Schemes
Barry Rowlingson