[R] grid(Base): How to avoid "Figure region too small and/or viewport too large" by specifying 'relative' units?
Marius Hofert
marius.hofert at math.ethz.ch
Sat Oct 20 08:10:56 CEST 2012
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.)
More information about the R-help
mailing list