[R] lattice: aligning independent graphs
Sebastian P. Luque
spluque at gmail.com
Thu May 31 08:45:36 CEST 2007
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
More information about the R-help
mailing list