tags:

views:

53

answers:

3

I'm using rgedit plugin for gedit. I would like to allow more than one graphic (plot) window to show at a time. Currently, whenever I plot(), the plot overwrites the previous plot window.

+1  A: 

Not a gedit issue but a general R feature -- use x11() (or windows()) to create new plot devices.

You can then use dev.set() et al to flip between them.

Dirk Eddelbuettel
can I set it to be done automatically instead of manually each time?
David B
Sure. You could write your own function `myplot(...)` that calls `dev.new()` before calling `plot()` with the rest of the arguments.
Dirk Eddelbuettel
+1  A: 

Just to add to Dirk's answer, you can also plot multiple graphs in the same window, look at ?par, in particular at the mfrow parameter

For instance par(mfrow=c(2,2)) will give you a 2x2 layout for your plot.

For more complex layouts see ?split.screen and ?layout


To switch between devices you can do:

# Create 3 plots
dev.new()  # Or X11()
dev.1 <- as.integer(dev.cur())
dev.new()
dev.2 <- as.integer(dev.cur())
dev.new()
dev.3 <- as.integer(dev.cur())

x <- seq(1, 100, 0.1)

# Switch to device 1
dev.set(dev.1)
plot(x, sin(x), "l")
# Switch to device 3
dev.set(dev.3)
plot(x, cos(x), "l")
# Add something to graph #1
dev.set(dev.1)
points(x, cos(x), "l", col="red")

Note that, although the devices numbers you're storing in dev.1, dev.2 and dev.3 will mostly be sequential (1,2,3) you should always use dev.cur to get the number of the device, as you cannot safely assume they will be exactly 1,2,3 etc... (you may have other devices open)

nico
A: 

Or you could open a new console tab, but this isn't as elegant (you have to submit your code twice) as the suggestions made by Dirk and nico.

Roman Luštrik