Is it possible to make a graphic port portable like ggplot?

Is it possible to make the base graphics port portable in the same way as ggplot graphics? That is, you can transfer the graph to various functions and cause printing (graph) without an error.

+3
source share
1 answer

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 and then record a figure
plot(rnorm(99))
recPlot <- recordPlot()
dev.off()

# Plot recorded figure to default graphics device
replayPlot(recPlot)

# Plot recorded figure to the pdf graphics device
pdf("eg.pdf")
replayPlot(recPlot)
dev.off()

# Look at the data structure that stores the plot
str(rPlot)
+4
source

All Articles