# A Slider to Control Two Plotting Windows

[This article was first published on

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**Statistics, R, Graphics and Fun » R Language**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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 their blog:**Statistics, R, Graphics and Fun » R Language**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.