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.
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.
In R, you would just use dev. new() before each plot, so you dev. off() to only clear the last plot.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With