A couple of functions recordPlot()and replayPlot()performs something similar, but not quite so. One difference is that, unlike graphs ggplot2and lattice, the drawing must first be applied to the graphics device before it is recorded.
plot(rnorm(99))
recPlot <- recordPlot()
dev.off()
replayPlot(recPlot)
pdf("eg.pdf")
replayPlot(recPlot)
dev.off()
str(rPlot)
source
share