PaulHurleyuk
PaulHurleyuk

Reputation: 8159

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

Upvotes: 35

Views: 50827

Answers (3)

Doc McStuffins
Doc McStuffins

Reputation: 41

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

Upvotes: 4

Anusha
Anusha

Reputation: 1726

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)

Upvotes: 14

Shane
Shane

Reputation: 100164

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

Upvotes: 27

Related Questions