Clear All Plots in RStudio Using R Code (Example)
This article shows how to remove all plots that are shown in RStudio in the R programming language.
Table of contents:
Let’s get started…
Creation of Example Plots
As a first step, we can create some plots in RStudio:
plot(1:10) # Plot No. 1 plot(10:1) # Plot No. 2 plot(1) # Plot No. 3
Have a look at your RStudio plots window.
It should show the last graphic that we have created above (i.e. plot(1)) and you should be able to switch back to the other two graphs in the plots window.
Example: Remove All Plots from RStudio Using dev.off() & dev.list() Functions
This example explains how to clear all plots from the RStudio plots window using R programming code.
Have a look at the following R syntax:
dev.off(dev.list()["RStudioGD"]) # Apply dev.off() & dev.list()
After executing this R code, all plots should be removed from RStudio.
Video & Further Resources
I have recently published a video instruction on my YouTube channel, which shows the R code of this article. You can find the video below.
Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.
If you accept this notice, your choice will be saved and the page will refresh.
Furthermore, you may have a look at the related tutorials on my website. I have published several tutorials already:
To summarize: In this R tutorial you have learned how to remove all graphs that are shown in RStudio. Let me know in the comments section below, in case you have any additional questions.
Statistics Globe Newsletter