Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you delete the current (but not all) plots in the RStudio plotting device?

Tags:

How do you delete the current (but not all) plots in the RStudio plotting device?

dev.off() will remove all plots, but what if I just want to remove one? I don't want to have to press that red 'x' button because I want to remove one plot without pressing a button.

like image 335
Hillary Sanders Avatar asked Jun 23 '15 16:06

Hillary Sanders


People also ask

How do I delete plots in RStudio?

This is equivalent to click on the button clear all plots in the plots panel. This is identical to Ctrl+L or to click on the clear console within the Edit menu. This is equivalent to click on the button clear objects from the workspace in the environment panel.

How do I delete a graph in R?

In R, you would just use dev. new() before each plot, so you dev. off() to only clear the last plot.

What does Dev off do in R?

dev. off shuts down the specified (by default the current) device. If the current device is shut down and any other devices are open, the next open device is made current.


1 Answers

In R, you would just use dev.new() before each plot, so you dev.off() to only clear the last plot.

In RStudio, you can use x11(), windows() or quartz() (depending on your device) before each plot. Then call dev.off() to clear last plot. You can also use dev.set() to choose specific plots that way.

If your question is specifically asking to delete the last plot within the same RStudio window (rather than making new windows), not sure if it's possible, since RStudio treats that window as one device. An idea would be to look at a way to call the C++ function removePlot() in the RStudio project.

I found in the Github repository for RStudio the C++ code:

display.removePlot(display.activePlotIndex()); 

You could output the plots and manage the files that way.

like image 121
haitham Avatar answered Sep 27 '22 22:09

haitham