How to save boxplot to as to a variable?

boxplot, r

Solution

The following does it. Call after that recordedPlot

boxplot(count ~ spray, data = InsectSprays, col = "lightgray")
recordedPlot = recordPlot()
dev.off()

Problem

How can I save the box plot as a variable in R? For example, if I did like this, ``` plot <- boxplot(count ~ spray, data = InsectSprays, col = "lightgray") ``` when I call plot, I want it shows the box plot, that I don't need to run the command for plotting boxplot every time. Does anyone have any idea?

Original source