Skip to content
Prev 44302 / 398506 Next

2 bwplots - different colors

On Monday 16 February 2004 10:37, Martina Pavlicova wrote:

            
Your code doesn't work for me as it is.

bwplot isn't really designed for grouped displays. Why don't 
you plot them in different panels ? I don't see any point 
in superposing them. For example,


library(lattice)
foo1 <- rnorm(600)
foo2 <- rchisq(600, 3)
bwplot(foo1 + foo2 ~ gl(20, 30), allow.m = T, outer = T)



If you really want to superimpose them, I would suggest 
using the following approach:



bwplot(foo1 + foo2 ~ gl(20, 30), allow.m = T, outer = F,
       panel =
       function(x, y, subscripts, groups, ...) {
           opar <- trellis.par.get()
           x <- as.numeric(x)
           y <- as.numeric(y)

           settings <- list()
           settings[[1]] <- 
               list(box.rectangle = list(col = "cyan"),
                    box.umbrella = list(col = "cyan"),
                    plot.symbol = list(col = "cyan"),
                    box.dot = list(col = "blue"))

           settings[[2]] <- 
               list(box.rectangle = list(col = "pink"),
                    box.umbrella = list(col = "pink"),
                    plot.symbol = list(col = "pink"),
                    box.dot = list(col = "red"))

           vals <- levels(groups)
           for (i in 1:2)
           {
               lset(settings[[i]])
               id <- groups[subscripts] == vals[i]
               panel.bwplot(x = x[id], y = y[id], ...)
               lset(opar)
           }
       })



Note that there are too many graphical parameters 
controlling boxplots to be included in panel.bwplot, and 
you need to modify the global settings to get anything 
useful. The relevant parameters that you may want to modify 
are given by

trellis.par.get("box.rectangle")
trellis.par.get("box.umbrella")
trellis.par.get("box.dot")
trellis.par.get("plot.symbol")


Hope that helps,

Deepayan