[Rd] Colour Schemes

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu May 21 21:45:30 CEST 2009


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



More information about the R-devel mailing list