[R] Colour filling in panel.bwplot from lattice

Rainer Hurling rhurlin at gwdg.de
Tue Nov 2 22:08:50 CET 2010


On 02.11.2010 21:43 (UTC+1), David Winsemius wrote:
>
> On Nov 2, 2010, at 4:07 PM, Rainer Hurling wrote:
>
> snipped quite a bit of talking past each otther
>>
>> Of course your example with eight colours works, too. But as you can
>> see in the plot, the colours have different order then in the vector
>> 'colors()[(2:9)*10]' itself. I expected the first box (bass2) coloured
>> "bisque1", the second box (bass1) "blue4" and so on.
>
> Oh. Try putting the fill argument outside the panel and see if the panel
> handles it in the manner you expect:
>
> bp3 <- bwplot(voice.part ~ height, data = singer, main = "fill arg
> outside bwplot\n1] 'bisque1' 'blue4' 'burlywood3' 'chartreuse3' 'coral3'
> 'cyan2' 'darkgray' 'darkorange", fill=colors()[(2:11)*10],
> panel = function(...) {
> panel.grid(v = -1, h = 0)
> panel.bwplot( ...)
> })
> bp3
>
>>
>> I hope, this explaination is a bit clearer than my preceding ones.
>
> And I hope my suggestion now "works".

Thank you for the hint, that it works also outside of the panel. It 
looks like I missed the wood for trees here ;-)

In your latest, special case the colours work. After having a nearer 
look at it I found that your colour vector has length 10 (2:11), and 
only the first eight colours are filled in the boxes.

This seems to be reproducable:

### NOT WORKING: 8 colours in the not in order of given vector
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"))

### WORKING: 10 (8+2*NA) colours in order of given vector
bwplot(voice.part ~ height, data = singer,
   main = "RIGHT ORDER OF COLOURS\n'yellow' 'blue' 'green' 'red' 'pink' 
'violet' 'brown' 'gold'",
   fill=c("yellow","blue","green","red","pink","violet","brown","gold", 
NA, NA))

I really do not understand what is going on here,
Rainer

> David Winsemius, MD
> West Hartford, CT



More information about the R-help mailing list