Record and Replay Plots

Functions to save the current plot in an Rvariable, and to replay it.

recordPlot(load=NULL, attach=NULL)
replayPlot(x, reloadPkgs=FALSE)
If not NULL, a character vector of package names, which are saved as part of the recorded plot.
If not NULL, a character vector of package names, which are saved as part of the recorded plot.
A saved plot.
A logical indicating whether to reload and/or reattach any packages that were saved as part of the recorded plot.

These functions record and replay the displaylist of the current graphics device. The returned object is of class "recordedplot", and replayPlot acts as a print method for that class.

The returned object is stored as a pairlist, but the usual methods for examining Robjects such as deparse and str are liable to mislead.


  • recordPlot returns an object of class "recordedplot".

    replayPlot has no return value.


The format of recorded plots may change between Rversions, so recorded plots should not be used as a permanent storage format for Rplots. As of R3.3.0, it is possible (again) to replay a plot from another Rsession using, for example, saveRDS and readRDS. It is even possible to replay a plot from another Rversion, however, this will produce warnings, may produce errors, or something worse.


Replay of a recorded plot may not produce the correct result (or may just fail) if the display list contains a call to recordGraphics which in turn contains an expression that calls code from a non-base package other than graphics or grid. The most well-known example of this is a plot drawn with the package ggplot2. One solution is to load the relevant package(s) before replaying the recorded plot. The load and attach arguments to recordPlot can be used to automate this - any packages named in load will be reloaded, via loadNamespace, and any packages named in attach will be reattached, via library, as long as reloadPkgs is TRUE in the call to replayPlot. This is only relevant when attempting to replay in one R session a plot that was recorded in a different R session.

See Also

The displaylist can be turned on and off using dev.control. Initially recording is on for screen devices, and off for print devices.

  • replayPlot
  • recordPlot
  • print.recordedplot
Documentation reproduced from package grDevices, version 3.3, License: Part of R 3.3

Community examples

Looks like there are no examples yet.