capture_base_plot {multipanelfigure}R Documentation

Capture a base plot

Description

Capture a plot drawn using base graphics as a grid grob.

Usage

capture_base_plot(expr)

Arguments

expr

A expression that draws a plot using base graphics.

Value

An object of class gTree.

Note

A side effect of this function is that plots get drawn twice: once as a base plot, and secondly as a grid plot.

References

Graumann, J., and Cotton, R.J. (2018). multipanelfigure: Simple Assembly of Multiple Plots and Images into a Compound Figure. Journal of Statistical Software 84. doi: 10.18637/jss.v084.c03

See Also

grid.echo, grid.grab

Examples

p <- capture_base_plot(hist(rnorm(1000), seq(-4, 4, 0.2)))
grid::grid.draw(p)
# If the plot takes multiple lines to draw, then wrap the code in braces.
p2 <- capture_base_plot({
  par(las = 1)
  plot(1:5)
  title("One to five")
})
grid::grid.draw(p2)

[Package multipanelfigure version 2.1.6 Index]