Re: [R] Controlling text and strip arrangement in xyplot

From: hadley wickham <h.wickham_at_gmail.com>
Date: Tue, 19 Jun 2007 10:06:31 +0200

On 6/19/07, Juan Pablo Lewinger <lewinger_at_usc.edu> wrote:
> I've searched the archives and read the xyplot help but can't figure
> out the 2 lattice questions below?
>
> Consider:
>
> library(lattice)
> DF <- data.frame(x=rnorm(20), y=rnorm(20), g1=rep(letters[1:2], 10),
> g2=rep(LETTERS[1:2], each=10),
> g3=rep(rep(letters[3:4],each=5),2))
>
> xyplot(y ~ x | g1 + g2, groups=g3, data=DF)

>
> 1) Is there a way to get one strip per row and column of panels as
> below instead of the default?
>
>
> _|__a__|__b__|
> |
> B
> |
> --
> |
> A
> |

Instead of using lattice, you could use ggplot2 (http://had.co.nz/ggplot2), where this is the default:

(p <- qplot(x, y, data=DF, facets = g1 ~ g2))

> 2) How do I control the text of the strips so that for instance
> instead of "a" and "b" it reads"g1=alpha", "g1=beta" where "alpha"
> and "beta" stand for the corresponding greek symbols? (my difficulty
> here is not with the plotmath symbols but with controlling the text
> of the strips directly from the call to xyplot and not by renaming
> the levels of g1)

It's also possible to do this in ggplot, but some bugs currently stop it from working. It will work in the next version to be released next week:

p$strip.text <- function(variable, value) {

	greek <- c("A" = "alpha", "B" = "beta")[value]
	makelabel <- function(g) substitute(variable == greek,
list(variable=as.name(variable), greek=as.name(g)))

        lapply(greek, makelabel)
}
p

Hadley



R-help_at_stat.math.ethz.ch 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. Received on Tue 19 Jun 2007 - 08:10:50 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 19 Jun 2007 - 08:32:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.