John Maindonald
2009-May-09 10:45 UTC
[R] Strip labels: use xyplot() to plot columns in parallel with outer=TRUE
The following tinkers with the strip labels, where the different panels are for different levelf of a conditioning factor. 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, strip=strip.custom(strip.names=TRUE, var.name="Add error with SD", sep=expression(" = "), factor.levels=as.expression(lab))) 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" == A*s[z], list(A=x)))) form <- formula(paste("y ~ ", paste(paste("X", tau, sep=""), collapse="+"))) 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, var.name=as.expression(lab2))) 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.
Deepayan Sarkar
2009-May-14 17:01 UTC
[R] Strip labels: use xyplot() to plot columns in parallel with outer=TRUE
On 5/9/09, John Maindonald <john.maindonald at anu.edu.au> wrote:> The following tinkers with the strip labels, where the > different panels are for different levelf of a conditioning > factor. > > 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, > strip=strip.custom(strip.names=TRUE, > var.name="Add error with SD", sep=expression(" = "), > factor.levels=as.expression(lab))) > 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" == A*s[z], > list(A=x)))) > form <- formula(paste("y ~ ", paste(paste("X", tau, sep=""), > collapse="+"))) > 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, > var.name=as.expression(lab2)))Didn't you mean xyplot(form, data=df, outer=TRUE, strip=strip.custom(strip.names=TRUE, var.name="Add error with SD", sep=expression(" = "), factor.levels=as.expression(lab2))) ? (Seems to work.) -Deepayan