Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
548 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...