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,

library(grid)
library(lattice)
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"))
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()

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




_____________________________

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@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.

Reply via email to