[R] Strip labels: use xyplot() to plot columns in parallel with outer=TRUE

John Maindonald john.maindonald at anu.edu.au
Sat May 9 12:45:45 CEST 2009

The following tinkers with the strip labels, where the
different panels are for different levelf of a conditioning

tau <- (0:5)/2.5; m <- length(tau); n <- 200; SD <- 2
x0 <- rnorm(n, mean=12.5, sd=SD)
matdf <- data.frame(
    x = as.vector(sapply((0:5)/2.5, function(s)x0+rnorm(n, sd=2*s))),
    y <- rep(15+2.5*x0, m), taugp = factor(rep(tau, rep(n,m))))
names(matdf) <- c("x","y","taugp")
lab <- c(list("0 (No error in x)"),
         lapply(tau[-1], function(x)substitute(A*s[z], list(A=x))))
xyplot(y ~ x | taugp, data=matdf,
         var.name="Add error with SD", sep=expression(" = "),
Is there any way to get custom labels when the same is done by
plotting, variables in parallel?:

df <- unstack(matdf, x ~ taugp)
df$y <- 15+2.5*x0
lab2 <- c(list("0 (No error in x)"),
         lapply(tau[-1], function(x)substitute("Add error with SD" ==  
form <- formula(paste("y ~ ", paste(paste("X", tau, sep=""),
xyplot(form, data=df, outer=TRUE)

I'd hoped that the following would do the trick, but the first label
is repeated in each panel, and the variable names are added:

xyplot(form, data=df, outer=TRUE, strip=strip.custom(strip.names=TRUE,

John Maindonald             email: john.maindonald at anu.edu.au
phone : +61 2 (6125)3473    fax  : +61 2(6125)5549
Centre for Mathematics & Its Applications, Room 1194,
John Dedman Mathematical Sciences Building (Building 27)
Australian National University, Canberra ACT 0200.

More information about the R-help mailing list