开发者

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.

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

x<-c(1:10)
y<-s开发者_运维百科in(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)


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


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

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

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


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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜