Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset the graphical parameters back to default values without use of dev.off()

Tags:

r

rstudio

Such as margins, orientations and such...

dev.off() does not work for me. I am often using RStudio, with its inbuilt graphics device. I then have plotting functions, which I want to plot either in the default RStudio graphics device, or if I called X11(), before in a new window.

This behaviour doesn't work with dev.off(). If my plotting function always calls dev.off(), it might inadvertently close the X11() window and instead plot in the RStudio device. If I always call dev.off() followed by X11(), it would always plot in a new window, even if I wanted to plot in the RStudio device.

Ordinarily that could be solved with getOption("device"), however, that always returns RStudioGD.

like image 307
Cookie Avatar asked Feb 15 '12 11:02

Cookie


People also ask

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. It is an error to attempt to shut down device 1.

How do I clear a plot window in R?

plots were still resident. Run -> Restart R and clear output did the trick.

What is XPD R?

xpd. parameter. This value specifies where in the plotting device an object can actually be plotted. The default is. xpd = FALSE.


2 Answers

See ?par. The idea is that you save them as they are when you found them, and then restore:

old.par <- par(mar = c(0, 0, 0, 0)) ## do plotting stuff with new settings 

Now restore as they were before we changed mar:

par(old.par) 
like image 80
mdsumner Avatar answered Sep 23 '22 11:09

mdsumner


In RStudio, You can just navigate to 'Plots' and select 'Remove plots'

like image 23
rinzy kutex Avatar answered Sep 24 '22 11:09

rinzy kutex