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

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu May 14 19:01:24 CEST 2009


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




More information about the R-help mailing list