[R] Colors in bwplot with drop.unused.levels=F

Cram Rigby cram.rigby at gmail.com
Thu Feb 24 06:22:52 CET 2011


Hi,

I see an inconsistency with how color vectors are handled in bwplot.
I wanted to create side-by-side boxplots with alternating colors so I
used the interaction command to create an interaction of two factors.

bwplot(value ~ interaction(response,dose), data=test,
drop.unused.levels=F,fill=c("blue","red"))

By using drop.unused.levels=F, what I was hoping for was an
alternating color for each interaction level.  This works when there
is data for each level.  However, when a level is unused, the next
color in the sequence is not used and then my alternating colors go
out of sync.  Note that the standard boxplot command does do the
expected thing by "applying" a color for every level, even when a
level has no data: E.g.

boxplot(value ~ interaction(response,dose), data=text, col=cols)

Is there a way to force bwplot to apply a color for every level,
including the unused levels?

Thanks!



More information about the R-help mailing list