Hi
Apologies for the slow response.
This part of the problem is I think just a bit of a misunderstanding. The
diagram drawn by grid.show.viewport() is drawn within a *subset* of the current
page (or viewport), to allow room for labelling, which is why your subsequent
"real" viewports do not align with the diagram.
If you change your grid.show.layout() call to the following (which "removes" the
normal margin used by grid.show.layout()) ...
grid.show.layout(gl, vp=viewport(width=1.25, height=1.25))
... then you should find your viewports line up with the diagram properly.
Paul
On 20/10/12 19:10, Marius Hofert wrote:
In the meanwhile, I found a more minimal example which shows the problem (just
change 'inch' to TRUE to see the difference):
require(grid)
inch <- FALSE # TRUE
d <- if(inch) 5 else 1
pspc <- d*c(0.3, 0.3) # width, height of panels
spc <- d*c(0.05, 0.05) # width, height of space
axlabspc <- d*c(0.1, 0.1) # width y label, height x label
labspc <- d*c(0.05, 0.05) # width label boxes, height label boxes
par. <- par(no.readonly=TRUE)
gl <- grid.layout(5, 5, default.units=if(inch) "inches" else "npc",
widths=c(axlabspc[1], pspc[1], spc[1], pspc[1], labspc[1]),
heights=c(labspc[2], pspc[2], spc[2], pspc[2], axlabspc[2]))
grid.show.layout(gl)
pushViewport(viewport(layout=gl))
for(i in 1:2) {
for(j in 1:2) {
pushViewport(viewport(layout.pos.row=2*i, layout.pos.col=2*j, name="foo"))
grid.rect()
upViewport()
}
}
par(par.)