如何在多個窗口中創建繪圖並在R中保持它們的獨立性

[英]How to create plots in multiple windows and keep them separate in R


I'm sure this is an easy problem, but my google / help foo has failed me, so it's up to you.

我確信這是一個簡單的問題,但是我的谷歌/ help foo辜負了我,所以這取決於你。

I have an R script that generates several plots, and I want to view all the plots on screen at once (in separate windows), but I can't work out how to open multiple graphics windows. I'm using ggplot2, but I feel this is a more basic problem, so I'm just using base grapics for this simple example

我有一個R腳本,它可以生成幾個圖,我想要同時查看屏幕上的所有情節(在單獨的窗口中),但是我不知道如何打開多個圖形窗口。我用的是ggplot2,但我覺得這是一個更基本的問題,所以我只是在這個簡單的例子中使用基葡萄藤

x<-c(1:10)
y<-sin(x)
z<-cos(x)
dev.new()
plot(y=y,x=x)
dev.off()
dev.new()
plot(x=x,y=z) 

But this doesn't work. I'm on Windows if this matters (Windows + Eclipse + StatEt)

但這是行不通的。如果這很重要,我在Windows上(Windows + Eclipse + StatEt)

3 个解决方案

#1


22  

This works fine if you remove the line with dev.off().

如果您使用dev.off()刪除了這條線,那么它就可以正常工作。

#2


11  

If you are working in Rstudio, this might not work as they dont support multiple graphical devices (as of now).

如果您在Rstudio中工作,這可能不會工作,因為它們不支持多個圖形設備(目前為止)。

To have plots open in separate windows, use x11() after every plot command

要在單獨的窗口中打開圖,請在每個plot命令之后使用x11()

x<-c(1:10)
y<-sin(x)
z<-cos(x)
plot(y=y,x=x)
x11()
plot(x=x,y=z)

#3


3  

I know that this is very late since you asked your question nearly 5 years ago, but if you are trying to compare two graphs in the same window (which is something that I do often) the use the function: par(mfrow=c(1,2))

我知道這已經很晚了,因為你五年前問過這個問題,但是如果你想在同一個窗口中比較兩個圖(我經常這么做),那么使用函數:par(mfrow=c(1,2))

This compares 2 separate graphs. If you want 4 graphs in a single line like the other one: par(mfrow=c(1,4)) If you want 4 graphs in a 2 x 2 setup: par(mfrow=c(2,2))

比較兩個單獨的圖。如果你想要在一行中有4個圖,就像另一個一樣:par(mfrow=c(1,4))如果你想在2×2的設置中有4個圖:par(mfrow=c(2,2))


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2010/05/14/72572712a36c155c41fc6db94af5d769.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com