如何更改当前的绘图窗口大小(在R中)

时间:2021-11-22 23:15:18

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.

谢谢。

2 个解决方案

#1


13  

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

一些解决方法可能是使用dev.new()R函数而不是使用此函数,该函数应该跨平台工作:

 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) } }

#2


9  

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))

#1


13  

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

一些解决方法可能是使用dev.new()R函数而不是使用此函数,该函数应该跨平台工作:

 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) } }

#2


9  

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))