Save Plot in Data Object in Base R (Example)


In this tutorial you’ll learn how to store a graphic in a data object in R programming.

Table of contents:

Let’s jump right to the example!


Example: Save Graphic in Data Object Using recordPlot Function

The following R programming code explains how to record a Base R plot in a data object by applying the recordPlot function.

plot(1:5, 1:5)                 # Create plot


r graph figure 1 save data object base


Figure 1 shows the output of the previous R code – a simple plot created with the basic graphic options of the R programming language.

If we want to save this plot in a data object, we can use the recordPlot function as follows:

my_plot <- recordPlot()        # Save plot in data object

Let’s test if it worked! First, we need to remove the plot that is already drawn in RStudio:                     # Create empty plot window in RStudio

Now, we simply need to call the data object, in which our plot is stored, to recreate the plot:

my_plot                        # Draw saved plot

Our plot should be shown again in your RStudio environment.


Video, Further Resources & Summary

Do you need more info on the content of this tutorial? Then you could have a look at the following video of my YouTube channel. I’m explaining the R syntax of this article in the video.


The YouTube video will be added soon.


Furthermore, you might have a look at some of the other articles that I have published on Statistics Globe. You can find a selection of tutorials about the plotting of data here:


In this tutorial, I explained how to save a Base R plot in a data object in the R programming language. Please let me know in the comments, if you have further questions and/or comments.


Subscribe to my free statistics newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.