[Rd] Colour Schemes
deepayan.sarkar at gmail.com
Thu May 21 18:29:58 CEST 2009
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.
> The base graphics "image" function has zlim arguments which let you do:
> 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.
> R-devel at r-project.org mailing list
More information about the R-devel