grid.echo: Echo 'graphics' output using 'grid' graphics

Description Usage Arguments Details Value Author(s) Examples

View source: R/graphics.R

Description

Convert a scene that was drawn using the graphics package to an identical scene drawn with the grid package.

Usage

1
2
3
grid.echo(x = NULL, newpage = TRUE, prefix = NULL, device = offscreen)

echoGrob(x = NULL, prefix = NULL, device = offscreen, name = NULL) 

Arguments

x

Either NULL, a recorded plot, or a function. If NULL, the current graphics device is echoed.

newpage

A logical value indicating whether to start a new page. If FALSE, echoing occurs in the current grid viewport.

prefix

A character value used as a prefix for all grob and viewport names. The default prefix is "graphics".

device

A function that opens a graphics device for grid.echo() to work on. By default this is an off-screen, in-memory device based on the pdf device. This default device may not be satisfactory when using custom fonts.

name

A character identifier.

Details

If the first argument is a function, it must be a function with zero arguments. If the function needs access to non-global data, use a closure. The function should not call functions that create or destroy graphics devices, or change the current graphics device.

Value

The echoGrob function returns a grob that will echo x when it is drawn.

The grid.echo function is called for its side-effect of drawing on the current graphics device.

Author(s)

Paul Murrell

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## Not run: 
# Echo existing drawing
plot(1)
grid.echo()

# Echo result of call to a plotting function
plotfun <- function() plot(1:10)
grid.echo(plotfun)

# Echo result of a plotting function (anonymous) into current viewport
grid.newpage()
pushViewport(viewport(x=0, width=.5, just="left"))
grid.rect(gp=gpar(col=NA, fill="grey"))
grid.echo(function() plot(1:10), newpage=FALSE)

## End(Not run)

Example output

Loading required package: grid
Warning message:
In grid.echo.recordedplot(recordPlot(), newpage, prefix) :
  No graphics to replay

gridGraphics documentation built on Dec. 15, 2020, 5:10 p.m.