tags:

views:

59

answers:

3

If I create a multi-plot window with par(mfrow=...), is it possible to send data to a specific plot (i.e. "the one in the lower left corner") or is the plotting always necessarily sequential? Is there a package for R that does something like this?

For those that are interested, this problem arises out of the fact that R is a single-threaded application and is not ideal for real-time visualization. I have multiple real-time data streams coming into R from an outside source that produces the data asynchronously (and therefore the data streams don't always come in the same order.) This results in R flipping around the order of the data visualization plots every time it updates.

+1  A: 

Have a look at help(layout). This allows you to specify the what, where and in which sizes.

Once plotted, I don't think you re-plot just partially. But you you can use dev.set() et al to switch between different 'plot devices' (ie windows); see help(dev.list).

Dirk Eddelbuettel
+2  A: 

You could use split.screen():

par(bg = "white") # erase.screen() will appear not to work
                  # if the background color is transparent 
                  # (as it is by default on most devices).
split.screen(c(2,1)) # split display into two screens
split.screen(c(1,3), screen = 2) # now split the bottom half into 3
screen(1) # prepare screen 1 for output
plot(10:1)
screen(4) # prepare screen 4 for output
plot(10:1)
rcs
Notice the importance of using: par(bg="white")
Tal Galili
Much obliged. :)
Jake
A: 

Another option is that of implementing a little GUI e.g. with RGtk2 or RTclTk.

I generally do this for graphs that I want to change in realtime and it works great.

For instance, with RGtk2 and cairoDevice you could just do something like (I assume you have a Glade interface)

# Helper function to get a widget from the Glade interface
getWidget <- function(name)
 {
 return (interface$getWidget(name))
 }

interface <- gladeXMLNew("interface.glade", root="mainWindow")
# Our cairo devices (to draw graphics).
# plot1, plot2, and plot3 are GtkDrawingArea widgets 
asCairoDevice(getWidget("plot1"))
# dev.cur() will give the device number of the last device we created
# You'll use this to switch device when you draw in different plots
# Storing the device number is important because you may have other
# devices open from other unrelated plots 
# (so never assume they'll just start from 1 and be sequential!!!)
plot1.dev <- as.integer(dev.cur())
asCairoDevice(getWidget("plot2"))
plot2.dev <- as.integer(dev.cur())
asCairoDevice(getWidget("plot3"))
plot3.dev <- as.integer(dev.cur())

# To draw in a specific plot you just do
dev.set(plot2.dev)
plot(....)

This has many other advantages, like that of being able to positions the graphs easily where you want (using Glade Interface Designer) and having the possibility of user interaction through specific buttons (e.g. you may have a "pause acquisition" button).

nico