开发者

show multiple R graphics windows in (r)gedit

开发者 https://www.devze.com 2023-01-13 20:12 出处:网络
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 wind

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.


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.


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)


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.

0

精彩评论

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