From deepayan.sarkar at gmail.com  Thu May 21 18:29:58 2009
From: deepayan.sarkar at gmail.com (Deepayan Sarkar)
Date: Thu, 21 May 2009 09:29:58 -0700
Subject: [Rd] Colour Schemes
In-Reply-To: <d8ad40b50905210712k128ecfa2vff2dd178f946680d@mail.gmail.com>
References: <d8ad40b50905210444q406e1a2ak8313d495975d1919@mail.gmail.com>
	<OFDAD6BC3C.A2BA778D-ON802575BD.004783B8-802575BD.00491507@hsl.gov.uk>
	<d8ad40b50905210712k128ecfa2vff2dd178f946680d@mail.gmail.com>
Message-ID: <eb555e660905210929l13c59870v13c4e17cafa7f90f@mail.gmail.com>

On 5/21/09, Barry Rowlingson <b.rowlingson at lancaster.ac.uk> wrote:
> 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.

But you could specify an explicit 'at' vector specifying the color
breakpoints: effectively, you want at = do.breaks(zlim, 5).

lattice does have a function called 'level.colors' that factors out
the color assignment computation.

-Deepayan

>
>
>   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
>
>
>  ______________________________________________
>  R-devel at r-project.org mailing list
>  https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] Colour Schemes
Deepayan Sarkar