The following code colorizes the panel backgrounds of a pairs
plot in R
. How can I colorize the diagonal panel (where the variable names are printed)? As you can see, I tried it but the variable names are not correctly aligned (for whatever reason).
count <- 0
mypanel <- function(x, y, ...){
count <<- count+1
bg <- if(count %in% c(1,4,9,12)) "#FDFF65" else "transparent" ll <- par("usr")
rect(ll[1], ll[3], ll[2], ll[4], col=bg) points(x, y, cex=0.5)
}
mydiag.panel <- function(x, ...){
ll <- par("usr")
rect(ll[1], ll[3], ll[2], ll[4], col="#FDFF65") }
U <- matrix(runif(4*500), ncol=4)
pairs(U, panel=mypanel, diag.panel=mydiag.panel)