[R] Colour filling in panel.bwplot from lattice

Deepayan Sarkar deepayan.sarkar at gmail.com
Wed Nov 3 10:23:01 CET 2010


On Wed, Nov 3, 2010 at 4:11 AM, Dennis Murphy <djmuser at gmail.com> wrote:
> Hi:
>
> I don't know why, but it seems that in
>
> bwplot(voice.part ~ height, data = singer,
> main = "NOT THE RIGHT ORDER OF COLOURS\n'yellow' 'blue' 'green' 'red'
> 'pink' 'violet' 'brown' 'gold'",
> fill=c("yellow","blue","green","red","pink","violet","brown","gold"))
>
> the assignment of colors is offset by 3:
>
> Levels: Bass 2 Bass 1 Tenor 2 Tenor 1 Alto 2 Alto 1 Soprano 2 Soprano 1
> fillcol <- c("yellow","blue","green","red","pink","violet","brown","gold")
>
> In the above plot,
>
> yellow -> Bass 2  (1)
> blue -> Tenor 1     (4)
> green -> Soprano 2  (7)
> red -> Bass 1 (10 mod 8 = 2)
> pink -> Alto 2 (13 mod 8 = 5)
> etc.
>
> It's certainly curious.

Curious indeed. It turns out that because of the way this was
implemented, every 11th color was used, so you end up with the order

> sel.cols <- c("yellow","blue","green","red","pink","violet","brown","gold")
> rep(sel.cols, 100) [ seq(1, by = 11, length.out = 8) ]
[1] "yellow" "red"    "brown"  "blue"   "pink"   "gold"   "green"  "violet"

It's easy to fix this so that we get the expected order, and I will do
so for the next release.

Having said that, it should be noted that any vectorization behaviour
in lattice panel functions is a consequence of implementation and not
guaranteed by design (although certainly useful in many situations).
In particular, it is risky to depend on vectorization in multipanel
plots, because the vectorization starts afresh in each panel for
whatever data subset happens to be in that panel, and there may be no
relation between the colors and the original data.

One alternative is to use panel.superpose with panel.groups=panel.bwplot:

bwplot(voice.part ~ height, data = singer, groups = voice.part, panel
= panel.superpose, panel.groups = panel.bwplot, fill = sel.cols)

-Deepayan



More information about the R-help mailing list