Title: Integration of base and grid graphics
Version: 0.4-7
Author: Paul Murrell
Depends: R (≥ 2.3.0)
Imports: graphics, grid
Suggests: lattice
Description: Integration of base and grid graphics
Maintainer: Paul Murrell <paul@stat.auckland.ac.nz>
License: GPL-2 | GPL-3 [expanded from: GPL]
Packaged: 2014-02-24 01:35:23 UTC; EC\pmur002
NeedsCompilation: no
Repository: CRAN
Date/Publication: 2014-02-24 07:20:37

Set Base Plotting Regions from Grid Viewport

Description

These functions can be used to align base plotting regions with the current grid viewport. This can be used to draw base plots within a grid viewport.

Usage

gridOMI()
gridFIG()
gridPLT()
gridPAR()

Details

For this to be useful, you will have to make liberal use of par(new=TRUE) to prevent base from moving to a new page.

With care, these can even be used to draw multiple base plots within a grid viewport (see the examples below), but in general, base plotting functions that draw multiple panels (e.g., coplot) should not be expected to work.

Value

gridOMI returns a value that can be used to set the par(omi) parameter.

gridFIG returns a value that can be used to set the par(fig) parameter.

gridPLT returns a value that can be used to set the par(plt) parameter.

gridPAR returns a value that can be used to set some graphical parameters (currently, lwd, lty, and col).

Warning

If you resize the device, all bets are off!

Author(s)

Paul Murrell

See Also

Grid, viewport

Examples

library(grid)
opar <- par(no.readonly=TRUE)
# gridFIG
grid.newpage()
pushViewport(viewport(width=0.5, height=0.5))
grid.rect(gp=gpar(col="grey", lty="dashed"))
par(fig=gridFIG())
par(new=TRUE)
plot(1:10)
# multiple plots
# NOTE the use of par(mfg)
# gridOMI
par(opar)
grid.newpage()
pushViewport(viewport(width=0.5, height=0.5))
grid.rect(gp=gpar(col="grey", lty="dashed"))
par(omi=gridOMI())
par(mfrow=c(2, 2), mfg=c(1, 1), mar=c(3, 3, 1, 0))
for (i in 1:4) {
  plot(i)
}
# gridPLT
par(opar)
grid.newpage()
pushViewport(viewport(width=0.5, height=0.5))
grid.rect(gp=gpar(col="grey", lwd=5))
par(plt=gridPLT())
par(new=TRUE)
plot(1:10)
# gridFIG with par(omi) set
par(opar)
grid.newpage()
par(omi=rep(1, 4))
pushViewport(viewport(width=0.5, height=0.5))
grid.rect(gp=gpar(col="grey", lwd=5))
par(fig=gridFIG())
par(new=TRUE)
plot(1:10)
# gridPLT with par(omi) set
par(opar)
grid.newpage()
par(omi=rep(1, 4))
pushViewport(viewport(width=0.5, height=0.5))
grid.rect(gp=gpar(col="grey", lwd=5))
par(plt=gridPLT())
par(new=TRUE)
plot(1:10)
# gridPAR
par(opar)
grid.newpage()
pushViewport(viewport(width=0.5, height=0.5,
  gp=gpar(col="red", lwd=3, lty="dotted")))
grid.rect(gp=gpar(col="grey", lwd=5))
par(fig=gridFIG())
par(gridPAR())
par(new=TRUE)
plot(1:10, type="b")

Generate grid Viewports from Base Plot

Description

This will generate a list of grid viewports which correspond to the current inner, figure, and plot regions of the current base plot.

Usage

baseViewports()

Details

The figure region is relative to the inner region so you must push the inner region before pushing the figure region. Similarly, the plot region is relative to the figure region so this should only be pushed after the previous two.

Value

A list with three elements:

inner

A viewport corresponding to the inner region of the current plot.

figure

A viewport corresponding to the figure region of the current plot.

plot

A viewport corresponding to the plot region of the current plot.

Warning

If you resize the device, all bets are off!

Author(s)

Paul Murrell

See Also

Grid, viewport

Examples

library(grid)
par(oma=rep(1, 4), mfrow=c(1, 2), xpd=NA)
plot(1:10)
vps <- baseViewports()
pushViewport(vps$inner)
grid.rect(gp=gpar(lwd=3, col="red"))
pushViewport(vps$figure)
grid.rect(gp=gpar(lwd=3, col="green"))
pushViewport(vps$plot)
grid.rect(gp=gpar(lwd=3, col="blue"))
grid.points(1:10, 10:1)