19

For example. Assume I do:

dev.new(width=5, height=4)
plot(1:20)

And now I wish to do

plot(1:40)

But I want a bigger window for it.

I would guess that the way to do it would be (assuming I don't want to open a new window) to do

plot(1:40, width=10, height=4)

Which of course doesn't work.

The only solution I see to it would be to turn off the window and start a new one. (Which will end my plotting history)

Is there a better way ?

Thanks.

Tal Galili
  • 24,605
  • 44
  • 129
  • 187
  • Tal-from your example (increase in width by 2x) it seems you want to be able to substantially increase the plot area. If it's a smaller increase in plot area you want, then you can move the four margins back, e.g., par(mar=c(3.0, 3.0, 1.5, 1.5)) – doug Mar 02 '10 at 22:49
  • 2
    You want to resize the current window? – Shane Mar 02 '10 at 22:59
  • Once the window is opened, it "belongs" to the window manager. I am not aware of any call that allows you to resize and already-opened window. You could cheat and simulate in code the 'mouse activates windows and enlarges' but it strikes me as having a poor cost/benefit ratio. – Dirk Eddelbuettel Mar 03 '10 at 01:20
  • Hello Doug, Shane and Firk - Thank you for answering. My situation is that I am to give a lecture on R. And in that lecture I intend to move between: par(mfrow = c(1,1)) to par(mfrow = c(1,2)) back and forth. Which will damage the image proportions and will force me to resize the window. The only solution I found for doing this in the code was by closing and opening a new window but that removes my ability to store the history of the plots. I hope my question was clearer now. Best, Tal – Tal Galili Mar 03 '10 at 07:51
  • 1
    help(dev.new) and help(dev.set) – Dirk Eddelbuettel Mar 03 '10 at 12:43

2 Answers2

13

Some workaround could be rather than using dev.new() R function use this function which should work across platform :

 dev.new <- function(width = 7, height = 7) 
 { platform <- sessionInfo()$platform if (grepl("linux",platform)) 
 { x11(width=width, height=height) } 
 else if (grepl("pc",platform)) 
 { windows(width=width, height=height) } 
 else if (grepl("apple", platform)) 
 { quartz(width=width, height=height) } }
pmr
  • 998
  • 2
  • 13
  • 27
10

Here is a my solution to this:

resize.win <- function(Width=6, Height=6)
{
        # works for windows
    dev.off(); # dev.new(width=6, height=6)
    windows(record=TRUE, width=Width, height=Height)
}
resize.win(5,5)
plot(rnorm(100))
resize.win(10,10)
plot(rnorm(100))
Tal Galili
  • 24,605
  • 44
  • 129
  • 187
  • 5
    That would be 'works only for Windows'. No other system has a function `windows` as Brian Ripley tried to explain to you. – Dirk Eddelbuettel Mar 03 '10 at 20:19
  • Hi Dirk, Thanks for mentioning this (also notice I wrote it in the code). But I guess this is something too... Best, Tal – Tal Galili Mar 03 '10 at 22:03