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

On Thu, May 21, 2009 at 10:53 AM, Barry Rowlingson
<b.rowlingson at lancaster.ac.uk> wrote:
> On Thu, May 21, 2009 at 5:29 PM, Deepayan Sarkar
> <deepayan.sarkar at gmail.com> wrote:
>
> [oops I didnt reply-to-all]
>
>> 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.
>>
> ?Yes, but these things are all at the wrong conceptual level. What you
> are constructing here is a function that maps value to colour, but
> keeping it as breaks and cut values and colours instead of
> representing it as a function. Wouldn't it be nicer to build a real
> function object and have that to pass around?

If that tickles your fancy, it's not a big stretch to get to

----
library(lattice)

continuousColours <- function(at, col.regions, ...)
{
    function(x) {
        level.colors(x, at = at, col.regions = col.regions, ...)
    }
}

## caveat: level.colors requires 'at' values to be unique, hence the 999,1001
scheme2 <-
    continuousColours(at = list(-1000, 0, 400, 999, 1001, 10000),
                      col.regions = c("blue", "sandYellow",
"grassGreen", "rockBrown", "white"))

## you could do something similar with your list format too, of course.

---

which gives

> scheme2(c(-500, -200, 200, 2000))
[1] "blue"       "blue"       "sandYellow" "white"

But generally speaking, I wouldn't presume to dictate that any given
approach is universally "nicer" than another; I don't expect others to
have the same tastes as me, and conversely, don't expect to be told
what my tastes should be (if I did, I would probably be using Excel).

-Deepayan



[Rd] Colour Schemes
Deepayan Sarkar