[R] How to colorize the panel backgrounds of pairs()?

Marius Hofert marius.hofert at math.ethz.ch
Fri Mar 2 00:49:05 CET 2012


Dear expeRts,

I would like to colorize the backgrounds of a pairs plot according to the respective panel number. Here is what I tried (without success):

count <- 0
mypanel <- function(x, y, ...){
    count <<- count+1
    bg. <- if(count %in% c(1,4,9,12)) "#FDFF65" else NA
    points(x, y, cex=0.5, bg=bg)
}

U <- matrix(runif(4*500), ncol=4)
pairs(U, panel=mypanel)

I also tried to set par(bg=bg.) before the call to points(), but that didn't work either. The only thing I found is that "bg=" can be used to fill certain plot symbols, but I would like to colorize the background of each panel, not the drawn circles.

Cheers,

Marius



More information about the R-help mailing list