Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change current Plot Window Size (in R)

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.

like image 459
Tal Galili Avatar asked Mar 02 '10 22:03

Tal Galili


People also ask

How do I increase plot area in R?

Use par(mai = c(bottom, left, top, right)) before the plot. It will create extra space around the plot area.

How do I find the size of a plot in R?

The plotting window size can be found by using dev. size function and we can pass in for inches and cm for centimeters. For example, if we create a plot then we can use dev. size("in") to find the plot size in inches and dev.


2 Answers

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) } }
like image 187
pmr Avatar answered Oct 03 '22 08:10

pmr


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))
like image 33
Tal Galili Avatar answered Oct 03 '22 07:10

Tal Galili