A Slider to Control Two Plotting Windows

September 28, 2010
By

(This article was first published on Statistics, R, Graphics and Fun » R Language, and kindly contributed to R-bloggers)

One of my readers asked two weeks ago how to control two graphics windows with the slider in gWidgets. Here is a simple example:

if (!require("gWidgetsRGtk2")) install.packages("gWidgetsRGtk2")
library(gWidgetsRGtk2)
options(guiToolkit = "RGtk2")
graphics.off()
x11()
x11()
dev.set()

gslider(from = 1, to = 100, value = 10,
    container = gwindow("Two Plotting Windows"),
    handler = function(h, ...) {
        n = 10 * svalue(h$obj)
        plot(rnorm(n), main = "the 1st plot")
        dev.set()
        plot(hist(runif(n)), main = "the 2nd plot")
        dev.set()
    })

The basic idea is to use dev.set() function to set focus on different graphics devices. After one plot has been drawn, go to the next device to draw the next plot. That’s it.

Related Posts

To leave a comment for the author, please follow the link and comment on his blog: Statistics, R, Graphics and Fun » R Language.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , , ,

Comments are closed.