[Rd] Colour Schemes
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Thu May 21 16:12:54 CEST 2009
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
More information about the R-devel
mailing list