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
par('bg') is not what you are looking for - it will set the bg of the whole graphic device, not panels. I think you want: count <- 0 mypanel <- function(x, y, ...){ count <<- count+1 ll<- par('usr') if(count %in% c(1,4,9,12)) bg<- "#FDFF65" else bg<- 'transparent' rect(ll[1],ll[3],ll[2],ll[4],col=bg) points(x, y, cex=0.5) } Cheers On Thu, Mar 1, 2012 at 4:49 PM, Marius Hofert <marius.hofert at math.ethz.ch> wrote:> 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 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Dear Ilai, I tried to also adjust the diagonal panels. However, the variable names are not positioned correctly anymore. Do you know a solution? Cheers, Marius 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) Marius Hofert <marius.hofert at math.ethz.ch> writes:> Indeed, precisely what I was looking for. Many thanks, Ilai. > > ilai <keren at math.montana.edu> writes: > >> par('bg') is not what you are looking for - it will set the bg of the >> whole graphic device, not panels. I think you want: >> count <- 0 >> mypanel <- function(x, y, ...){ >> count <<- count+1 >> ll<- par('usr') >> if(count %in% c(1,4,9,12)) bg<- "#FDFF65" >> else bg<- 'transparent' >> rect(ll[1],ll[3],ll[2],ll[4],col=bg) >> points(x, y, cex=0.5) >> } >> >> Cheers >> >> On Thu, Mar 1, 2012 at 4:49 PM, Marius Hofert >> <marius.hofert at math.ethz.ch> wrote: >>> 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 >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code.
Maybe Matching Threads
- Lattice: How to color the data points in splom() according to the panel they are plotted?
- Seed in 'parallel' vignette
- Why is format(10000, big.mark = "\\,") not 10\,000?
- Quiz: Who finds the nicest form of X_1^\prime?
- How to efficiently compare each row in a matrix with each row in another matrix?