简体   繁体   English

是否可以使用 R 代码调整交互式 R 图形设备的大小?

[英]Is it possible to resize an interactive R graphics device with R code?

When using R within an interactive windowing system (such as Windows, Ubuntu, MacOSX) the default behaviour for plot(x) is to open an interactive graphics device (with plot.new() under the hood), and draw stuff on it. When using R within an interactive windowing system (such as Windows, Ubuntu, MacOSX) the default behaviour for plot(x) is to open an interactive graphics device (with plot.new() under the hood), and draw stuff on it. The device can be interactively moved, resize and closed, and (depending on the platform) presents other GUI-based operations.设备可以交互移动、调整大小和关闭,并且(取决于平台)呈现其他基于 GUI 的操作。 It can be closed or copied with R code, with dev.off() , dev.copy() and there are other functions in the family.可以使用 R 代码关闭或复制它,使用dev.off()dev.copy()以及该系列中的其他功能。

Can the device be moved or resized using R code?可以使用 R 代码移动设备或调整设备大小吗?

I realize that this question may have many platform-specific answers, and all and any detail is welcome.我意识到这个问题可能有许多特定于平台的答案,欢迎提供所有细节。 I am most interested in the default Windows install options for the latest version of R, but keen to learn more about the differences between OS environments and other options.我对最新版本的 R 的默认 Windows 安装选项最感兴趣,但渴望了解有关操作系统环境和其他选项之间差异的更多信息。

If you really wanted to do this, you could use the GTK libraries and the cairoDevice package.如果你真的想这样做,你可以使用 GTK 库和 cairoDevice package。 Then you can resize things with RGtk2 calls.然后您可以使用 RGtk2 调用来调整大小。 It isn't the default install, but is cross platform.它不是默认安装,而是跨平台的。

library(RGtk2)
library(cairoDevice)
w = gtkWindow()
da <- gtkDrawingArea()
asCairoDevice(da)
w <- gtkWindow(show=FALSE)
w$add(da)
w$show()
hist(rnorm(100))
w$resize(500, 500)
w$move(200,200)

A collection of past attempts with few answers but possibly useful:过去尝试的集合,答案很少,但可能有用:

Have you look at the excellent packages by Felix Andrews which bring much interactivity to lattice devices:你有没有看过 Felix Andrews 的优秀包,它们为 lattice 设备带来了很多交互性:

If your question is about the physical size of the window on the screen: I don't think so.如果您的问题是关于屏幕上 window 的物理尺寸:我不这么认为。 That is a window manager task, and you would have to write (very platform dependent, I suspect) code to alter the window once drawn.这是一个 window 管理器任务,您必须编写(我怀疑非常依赖于平台)代码来更改 window 绘制后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM