[R] Colour filling in panel.bwplot from lattice

David Winsemius dwinsemius at comcast.net
Tue Nov 2 19:08:59 CET 2010


On Nov 2, 2010, at 1:19 PM, Rainer Hurling wrote:

> Inspired by colouring the dots of box-whisker plots I am trying to  
> also fill the boxes (rectangles) with different colours. This seems  
> not to work as I expected.
>
> Looking at the help page of panel.bwplot it says: 'fill - color to  
> fill the boxplot'. Obviously it is only intended to fill all boxes  
> with only one colour?
>
> Nevertheless the following example shows, that 'fill' from  
> panel.bwplot is able to work with more than one colour. But this  
> only works with one colour or multiples of 5 colours:
>
>
> -------------------------------------------------
> bp1 <- bwplot(voice.part ~ height, data = singer, main="1 color  
> works",
>              panel = function(...) {
>                panel.bwplot(col=c("yellow"),
>                             fill=c("yellow"), ...)
>              })
>
> bp2 <- bwplot(voice.part ~ height, data = singer, main = "3 colors  
> do NOT work",
>              panel = function(...) {
>                panel.grid(v = -1, h = 0)
>                panel.bwplot(col=c("yellow","blue","green"),
>                             fill=c("yellow","blue","green"), ...)
>              })
>
> bp3 <- bwplot(voice.part ~ height, data = singer, main = "5 colors  
> do work",
>              panel = function(...) {
>                panel.grid(v = -1, h = 0)
>                 
> panel.bwplot(col=c("yellow","blue","green","pink","red"),
> fill=c("yellow","blue","green","pink","red"), ...)
>       })
>
> plot(bp1, split=c(1,1,1,3))
> plot(bp2, split=c(1,2,1,3), newpage=FALSE)
> plot(bp3, split=c(1,3,1,3), newpage=FALSE)
> -------------------------------------------------
>
>
> Is there any chance to use more than one filling colour correctly?


You have eight boxes to fill and 8 dots to color. You can either  
supply 8 distinct colors or you can supply some lesser number and they  
will be recycled across the entire 8 boxes and dots. What you cannot  
do ( and expect to see the dots against the fill background) is plot  
the dots as the same colors as the fill.

This will let you see all colors of dots and fill with only 4 colors  
because I set it up so there was no two identical colors in teh  
sequence of dots and fill during hte reculing:

bp4 <- bwplot(voice.part ~ height, data = singer, main = "5 colors do  
work",
               panel = function(...) {
                 panel.grid(v = -1, h = 0)
                  
panel.bwplot(col=rev(c("yellow","blue","green","pink")),
  fill=c("yellow","blue","green","pink"), ...)
        })
  bp3


>
> Thanks in advance,
> Rainer Hurling
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list