Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

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. It can be closed or copied with R code, with dev.off(), dev.copy() and there are other functions in the family.

Can the device be moved or resized using R code?

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.

like image 780
mdsumner Avatar asked Jun 03 '11 14:06

mdsumner


People also ask

What is a device in R?

Abstract. The R. devices package provides functions for creating plots and image files in a unified way regardless of output format (EPS, PDF, PNG, SVG, TIFF, WMF, etc.). Default device options as well as scales and aspect ratios are controlled in a uniform way across all device types.


2 Answers

If you really wanted to do this, you could use the GTK libraries and the cairoDevice package. Then you can resize things with RGtk2 calls. 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)
like image 78
jverzani Avatar answered Nov 02 '22 23:11

jverzani


A collection of past attempts with few answers but possibly useful:

  • https://stat.ethz.ch/pipermail/r-help/2002-October/025840.html : very old question. Gets the usual snark from BDR. Poster claims "I found in mailing list archives article, that describes how to resize X11 graphical window on *nix through *nix command-line interface from R.:)"
  • this http://finzi.psych.upenn.edu/R/Rhelp01/archive/13765.html may be what he was talking about, which might (?) still work on X11 systems -- haven't tried it
  • How to change current Plot Window Size (in R) gives a (hacked) Windows-specific solution that involves recording the graphics, closing the window, and opening another one ...
  • http://r.789695.n4.nabble.com/Resize-Graphics-Window-td2103378.html (no answer)
  • http://tolstoy.newcastle.edu.au/R/help/05/10/13546.html asks about Quartz, and gets only answers about how to set the size when opening the window initially
like image 43
Ben Bolker Avatar answered Nov 02 '22 23:11

Ben Bolker