Skip to content

Instantly share code, notes, and snippets.

@sebble
Created July 22, 2011 12:54
Show Gist options
  • Save sebble/1099393 to your computer and use it in GitHub Desktop.
Save sebble/1099393 to your computer and use it in GitHub Desktop.
Drawing some plots in a gWidgets window
library(gWidgets)
plots.gui <- function(toolkit, resize) {
options("guiToolkit"=toolkit)
window <- gwindow("plots.gui - gWidgets")
wgroup <- ggroup(horizontal=FALSE, cont=window)
pgroup <- gpanedgroup(container=wgroup)
add(pgroup, ggraphics()); ggmain <- dev.cur()
rgroup <- ggroup(horizontal=FALSE, cont=pgroup)
add(rgroup, ggraphics()); ggsub1 <- dev.cur()
add(rgroup, ggraphics()); ggsub2 <- dev.cur()
if(resize) size(pgroup) <- c(75*9, 75*6)
updatePlots <- function(...) {
y <- rnorm(100);
x <- pnorm(y);
dev.set(ggmain); plot(x,y)
dev.set(ggsub1); hist(x)
dev.set(ggsub2); hist(y)
}
tmp <- ggroup(cont=wgroup)
add(tmp, gbutton("Draw Plots", handler=updatePlots))
add(tmp, gbutton("Close", handler=function(...) dispose(window)))
updatePlots()
}
plots.gui("RGtk2", FALSE)
plots.gui("RGtk2", TRUE)
plots.gui("Qt", FALSE)
plots.gui("Qt", TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment