[R] Lattice::bwplot unexpected behaviour when using vector of colors

Mehrdad Shamsi Mehrdad.Shamsi at oicr.on.ca
Tue Oct 12 17:55:56 CEST 2010


Hi,
I posted this message on R-devel, but it seems to be more suitable for R-help. So I post it here again.

I'm trying to produce colored boxplots using lattice::bwplot function. I need to plot each boxplot in the panel with a specific color. Naturally, I used a vector of colors and expected to see colored boxplots. Although the boxplots were colored, the color of whiskers and the boxes  do not match. Here is an example:

d = data.frame(y = rnorm(100), x=1:4)
box.color <- c('red','blue','black', 'green')
bwplot(y~x,
        data=d,
        horizontal=FALSE,
        par.settings = list(
        box.rectangle = list(col = box.color),
        box.umbrella = list(col = box.color)
        )
)

I went through the bwplot.panel to figure out what the problem was. It seems that bwplot.panel function is implemented with the assumption that box.rectangle$col and box.umberella$col are not vectors. It would be nice if bwplot.panel could accept vector of colors.

I use R2.11-x64 on a Windows XP machine. The lattice package version is lattice_0.19-13.

--Thanks

-- M.S.



More information about the R-help mailing list