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