[R] align two lattice plots using grid

From: baptiste auguie <ba208_at_exeter.ac.uk>
Date: Thu, 20 Nov 2008 20:16:11 +0000

Dear list,

I'm trying to get two lattice plots aligned on a page. They should share a common x axis, hence the need for perfect alignment, but the data is taken from unrelated, separate sources (it is therefore inappropriate to combine them and use facetting to get an automatic layout: the legend and y axis need to be different). I can get the panels to be of the same size, but they have an horizontal offset due to a differing size of the legend / ylabel.

Here's an example of what I've tried,


x <- seq(0, 10, length=100)
y <- sin(x)
f <- rep(c("1", "2"), each=50)

p1 <- xyplot(y~x,groups=f, ylab="BIG LABEL", auto.key=list(space="right"))
p2 <- xyplot(y~x, ylab="a")

pushViewport(viewport(layout=grid.layout(nrow = 2, ncol = 1 ,

						widths=unit(6, "inches"),
                           heights=unit(c(3, 2), "inches"))))
pushViewport(viewport(layout.pos.col=1, layout.pos.row=1, just="center", name = "top"))

print(p1, newpage=F, panel.width=list(4, "inches"), panel.height=list(2.5, "inches"))
pushViewport(viewport(layout.pos.col=1, layout.pos.row=2, just="center", name = "bottom"))

print(p2, newpage=F, panel.width=list(4, "inches"), panel.height=list(1.5, "inches"))

I'm sure there is a clever trick to get the panels to be aligned as opposed to the whole plots, but I can't see it.

Many thanks,


Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,

Phone: +44 1392 264187


R-help_at_r-project.org 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 20 Nov 2008 - 20:20:16 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 20 Nov 2008 - 20:30:30 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.

list of date sections of archive