Skip to content

2 bwplots - different colors

2 messages · Martina Pavlicova, Deepayan Sarkar

#
Hi all,

I would like to draw one picture which would show two different types of
boxplots using the same axes (kind of on top of each other). However, I
would like to plot each boxplot using a different color or different
shading inside the box, so they could be better distinquished from each
other... Could you help me?

Here is an example of the plot I have so far. I was only able to change
the color the median-dot (to 'red').

library(lattice)
foo1 <- matrix(rnorm(600),30,20)
foo2 <- matrix(rchisq(600,3),30,20)
bwplot(t(foo1)~c(1:20), xlim=as.character(seq(.01, .2, by=.01)),
       horizontal=F, bty=n, ylim=c(-3,11),
       panel=function(x,y,axes=F,...){
         panel.bwplot(x,y,bty=n,...)
         panel.bwplot(x, foo2, bty=n, col="red", ...)
       }
       )

Thank you very much for your help.

Martina Pavlicova

--------------------------------------------------------------------------
Department of Statistics             Office Phone: (614) 292-1567
1958 Neil Avenue, 304E Cockins Hall  FAX: (614) 292-2096
The Ohio State University            E-mail: pavlicov at stat.ohio-state.edu
Columbus, OH 43210-1247              www.stat.ohio-state.edu/~pavlicov
#
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