Re: [R] lattice: aligning independent graphs

From: Sebastian P. Luque <spluque_at_gmail.com>
Date: Thu, 31 May 2007 01:45:36 -0500

On Thu, 31 May 2007 00:26:00 -0500,
"Sebastian P. Luque" <spluque_at_gmail.com> wrote:

[...]

> which gives wrong width and placement. How can this be modified so it
> places the labels close to the axis annotation, centered on each panel?
> Thanks in advance.

Ok, this is it I think:

---<---------------cut here---------------start-------------->---
ylabGrob <- function(...) {             # ...is lab1, lab2, etc
    labs <- lapply(list(...), textGrob, rot=90)
    nlabs <- length(labs)
    lab.widths <- lapply(labs,
                         function(lab) unit(1, "grobwidth", data=list(lab)))
    lab.layout <-
        grid.layout(ncol=1, nrow=nlabs,
                    heights=unit(1, "null"),
                    widths=do.call(max, lab.widths),
                    respect=TRUE)

    lab.gf <- frameGrob(layout=lab.layout)     for (i in seq_len(nlabs))
        {
            lab.gf <- placeGrob(lab.gf, labs[[i]], row=i, col=1)
        }

    lab.gf
}

xyplot(1:9 ~ 1:9 | gl(3, 1, 9), layout=c(1, 3),

       ylab=myXlabGrob('Trial number', 'Subject number',
           'Experimental condition'), strip=FALSE)
---<---------------cut here---------------end---------------->---



-- 
Seb

______________________________________________
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 Thu 31 May 2007 - 07:02:31 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 Thu 31 May 2007 - 07:33:19 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.