[R] lattice: superposed boxplots with same colors for rectanglesand umbrellas and filled boxes

Gerrit Eichner Gerrit.Eichner at math.uni-giessen.de
Mon Dec 9 23:17:42 CET 2013


Dear R-list,

I've been trying to produce a sort of an interaction plot wherein colored 
stripplots and boxplots are superposed. In particular, I want the colors 
of the (transparently) filled boxes to be the same as the colors of the 
box borders (rectangle) and their whiskers (umbrella). Below I'm going to 
create an artificial data set and provide the code with which I've come up 
so far, and which is a fusion and adaptation of a few pieces of code I've 
found in the help pages and the mail archives. It does almost what I want, 
but still colors the rectangles and the umbrellas in black (of course, 
because it is the setting in the example presented below). However, the 
latter is what I want to change.

x <- c( rep( 1:4, each = 10), rep( -2, 40))
Data <- data.frame( F1 = gl( 4, 10, length = 80, labels = LETTERS[ 1:4]),
                     F2 = gl( 2, 40), Y = x + rnorm( length( x)))

mycolors <- c( "red", "blue")
myalpha <- 0.33
bwplot( Y ~ F1, groups = F2, data = Data,
         col = mycolors, fill = mycolors, jitter.data = TRUE,
         panel = panel.superpose,
         panel.groups = function(..., pch, col, alpha){
             panel.stripplot(...)
             panel.bwplot(..., do.out = FALSE)
         },
         par.settings = list( box.dot = list( alpha = myalpha),
                              box.rectangle = list( col = "black",
                                                    alpha = myalpha),
                              box.umbrella = list( col = "black",
                                                   alpha = myalpha))
         )


If I'd provide mycolors instead of "black" to the col-component of the 
(sub-)lists given to par.settings, the coloring of the respective 
components of the boxplots would not be what I want. Having studied the 
code of panel.superpose() and panel.bwplot() it appears to me that 
panel.bwplot() cannot access the settings created by panel.supperpose when 
it comes to drawing the rectangle and umbrella of a boxplot. It only 
accesses box.[dot, rectangle, umbrella], which does not give what I need.

I may have overlooked the obvious and would be quite grateful if somebody 
could give me a hint where to look further. Or is a workaround necessary 
(and available)?

Thanks a lot in advance!

  Best Regards  --  Gerrit

---------------------------------------------------------------------
Dr. Gerrit Eichner                   Mathematical Institute, Room 212
gerrit.eichner at math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109        http://www.uni-giessen.de/cms/eichner



More information about the R-help mailing list