不使用 dev.off() 将图形参数重置回默认值 [英] Reset the graphical parameters back to default values without use of dev.off()

查看:46
本文介绍了不使用 dev.off() 将图形参数重置回默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如边距、方向等等...

Such as margins, orientations and such...

dev.off() 对我不起作用.我经常使用带有内置图形设备的 RStudio.然后我有绘图功能,我想在默认的 RStudio 图形设备中绘图,或者在新窗口中之前调用 X11().

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.

此行为不适用于 dev.off().如果我的绘图函数总是调用 dev.off(),它可能会无意中关闭 X11() 窗口,而是在 RStudio 设备中绘图.如果我总是调用 dev.off() 后跟 X11(),它总是会在新窗口中绘图,即使我想在 RStudio 设备中绘图.

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.

通常可以用 getOption("device") 解决,但是,它总是返回 RStudioGD.

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

推荐答案

参见 ?par.这个想法是你在找到它们时保存它们,然后恢复:

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

现在恢复到我们改变之前的样子mar:

Now restore as they were before we changed mar:

par(old.par)

这篇关于不使用 dev.off() 将图形参数重置回默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆