简体   繁体   中英

Find and set maximum size of plot window in R

What command can I use to find and set plot window to maximum available, ie one that will produce a plot window as one gets after clicking on maximize button of top bar?

I searched and found that while running R on Windows one can use windows(width,height) function while on linux one can use X11.options() . One can also insert a line the file: ~/.Xresources: R_x11*geometry : 600x600 as suggested on this page .
However, I could not find how to get maximum size possible on the computer where the program is run and what is the best way to set the plot window to the maximum size using R commands.

On windows, I'd try getting the screen resolution on dpi first, then set the width/height parameters accordingly:

windowsMax <- function() {
  f <- function(cmd) as.numeric(gsub("\\D", "", system(cmd, intern=TRUE)[2]))
  width <- f("wmic desktopmonitor get screenwidth")
  height <- f("wmic desktopmonitor get screenheight")
  dpi <- f("wmic desktopmonitor get PixelsPerXLogicalInch")
  windows(width = width / dpi, height = height / dpi)
}
windowsMax()

This seems to work 'ok' on Ubuntu 12.04. [I got most details from a post on Rhelp (i think) some time ago]

my.dev.new <- function() { 

  scrn <- system("xdpyinfo  | grep 'dimensions:'", wait=FALSE, intern=TRUE)
  sc.dim <-  as.numeric(unlist(regmatches( scrn, regexec("(\\d+)x(\\d+)",  
                                                                  scrn) ))[-1])

  res <- system("xdpyinfo  | grep 'resolution:'", wait=FALSE, intern=TRUE)
  dpi <-  as.numeric(unlist(regmatches( res, regexec("(\\d+)x(\\d+)",  res) ))[-1])

  wdth <- sc.dim[1]/ dpi[1]
  ht <- sc.dim[2] / dpi[2]
  dev.new(width = wdth, height = ht)
}


my.dev.new()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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