Dear list,
I have produced a fairly intricate plot arrangement for use in a
publication using layout() and gridBase, and out of curiosity I'd like
to learn whether a more elegant and robust solution could be obtained
with grid to avoid the layout() function.
library(gridBase)
x <- seq(-pi, pi, length=10)
y <- cos(x)
par(mar = c(0, 0, 0, 0), pty = "m", mgp = c(1.8, 0.5, 0))
layout(rbind(c(1, 1), c(2, 2)), widths = c(1, 1),
heights = c(1, 0.5))
oldpar <- par(no.readonly = TRUE)
par(mar = c(0, 3.5, 0, 1), pty = "m", xpd = F, mgp = c(1.8, 0.5, 0))
#
# top graph
#
plot(x, y, xaxt="n", ylab="label1")
axis(1, lab=F)
vps <- baseViewports()
pushViewport(vps$inner, vps$figure, vps$plot)
pushViewport(viewport(x = unit(-1.8, "native"), y = unit(0.7,
"native"),
width = unit(1.5, "native"), height = unit(0.6,
"native")) )
par(plt = gridPLT(), new = TRUE, mgp = c(1.8, 0.5, 0))
#
# small inset at the top-left corner
#
plot(x, y, ylab="label2", cex=0.8)
popViewport()
popViewport(3)
#
# bottom graph
#
par(mar = c(3.5, 3.5, 0, 1), mgp = c(1.8, 0.5, 0), pty = "m", xpd = F)
plot(x, y, ylab="label3")
par(oldpar)
#
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.