[R] levelplot question

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu May 7 02:13:21 CEST 2009


On Tue, May 5, 2009 at 12:00 AM, Antje <niederlein-rstat at yahoo.de> wrote:
> Hi Greg and all the others,
>
> thanks for your answer. The color-vector has the same length like the
> at-vector but the recycling cannot be the reason, because only values
> slightly above my "threshold" doe not appear blue.
> I cannot find a good explanation of which colors are assigned to which value
> ranges.
>
> I've made little example:
>
> #--------------------------------------------------------
> mat <- matrix(seq(1,5, length.out = 12), nrow = 3)
> mat[1,2] <- 3.5
>
> my.at <- seq(0.5,5.5)
> my.col.regions <- rainbow(6)
>
> graph <- levelplot(t(mat[nrow(mat):1, ] ), at = my.at, col.regions =
> my.col.regions)
> print(graph)
>
> windows()
> plot(1:10)
> legend("topleft", legend = as.character(my.col.regions), col =
> my.col.regions, pch = 18)
> #--------------------------------------------------------
>
> As you can see the green (position 3 in my.col.regions) disappears
> completely in the levelplot (look at the color range at the right side!).
> I guess it might also happen in my case...
>
> I've tested several cases and it looks like the length of the color-vector
> should be one less than the at vector (which would make sense).
>
> Then, the rule might apply:
>
> [ at[1],at[2] ] = color[1]
> ( at[2],at[3] ] = color[2]
> ...
> ( at[n-1],at[n] ] = color[n-1]
>
>
> Please correct me if I'm wrong!!!

Nope, that's exactly what is happening. A more intutive explanation is:

  If 'at' has length n, then it defines n-1 intervals.

  Each interval gets a color. If there are exactly n-1 colors in col.regions,
  everything's fine. If there are fewer than n-1 colors, col.regions gets
  recycled. If there are more, a more or less "equally spaced" subset
  is chosen (this is what levelplot expects, as it was designed for smooth
  surfaces).

  As Greg pointed out, this all happens in level.colors().

-Deepayan




More information about the R-help mailing list