[R] align two lattice plots with grid

From: baptiste auguie <ba208_at_exeter.ac.uk>
Date: Mon, 01 Dec 2008 16:13:50 +0000


Dear list,

I need to align two plots on top of each other for comparison (they only have the x-axis in common). When the y-labels have a different extent, I cannot find a way to align the x-axes, as illustrated below,

> library(grid)
> library(lattice)
> x <- seq(0, 10, length=100)
> y <- sin(x)
> y2 <- 10*sin(x)
> f <- rep(c("1", "2"), each=50)
>
> p1 <- xyplot(y~x,groups=f, ylab="BIG LABEL",
> # auto.key=list(space="right"),
> par.settings = list(layout.width = list(panel=1, ylab = 2,
> axis.left =1.0, left.padding=1,
> ylab.axis.padding=1, axis.panel=1)))
>
> p2 <- xyplot(y2~x, ylab="a",
> par.settings = list(layout.width = list(panel=1, ylab = 2,
> axis.left =1.0, left.padding=1,
> ylab.axis.padding=1, axis.panel=1)))
>
> 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"))
> upViewport()
> 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"))
> upViewport()

Any help would be greatly appreciated!

baptiste


Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag



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 Mon 01 Dec 2008 - 16:17:45 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 Mon 01 Dec 2008 - 21:30:29 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