Reputation: 501
In developing a gWidgets interface to plotting data and model results, I create a plot page and with par(mfrow=c(4,1))
to put 4 plots stacked up.
The first plot (a simple y vs. x on the top) works fine, but the remaining 3 plots in the loop create axes but plot no data. To test the code, I tried opening a new plot window before looping through the plots, and all worked fine.
Is there something in gwdigets
interaction with plot(...)
that would be useful to know?
EDIT a reproducible example:
doesn't work:
library(gWidgets)
options(guiToolkit="RGtk2") ## "Qt"
w <- gwindow("brush example", visible=FALSE)
g <- ggroup(container=w)
gg <- ggraphics(container=g)
addHandlerChanged(gg, handler=function(h,...) {
par(mfrow=c(2,2))
plot(mpg ~ wt, mtcars)
plot(mpg ~ wt, mtcars,col='blue')
plot(mpg ~ wt, mtcars,col='red')
plot(mpg ~ wt, mtcars,col='green')
})
visible(w) <- TRUE
should look like this (normal R graphics window:
Not like this
Upvotes: 1
Views: 1515
Reputation: 5700
There are two issues. One might be related to the cairo implementation on windows. This can be tested by avoiding gWidgets altogether:
make_plot <- function() {
par(mfrow=c(2,2))
plot(mpg ~ wt, mtcars)
plot(mpg ~ wt, mtcars,col='blue')
plot(mpg ~ wt, mtcars,col='red')
plot(mpg ~ wt, mtcars,col='green')
}
require(RGtk2)
require(cairoDevice)
w <- gtkWindow(show=FALSE)
da <- gtkDrawingArea()
w$add(da)
w$show(TRUE)
asCairoDevice(da)
make_plot()
The other issue is putting the graphics drawing call inside the handler. For ggraphics, the change handler is called after one finishes rubber banding, not when the graphic itself changes. Not sure this is the most useful thing, but is meant to call some handler after a selection is made through rubber banding. The addHandlerClicked might be of more interest.
Upvotes: 1
Reputation: 121568
For some reasons the plot can't be refreshed. You can ou can use multiple ggraphics instances or maybe you can use ggraphicsnotebook
.
Here a solution using many instances of ggraphics
.
library(gWidgets)
options(guiToolkit="RGtk2") ## "Qt"
w <- gwindow("brush example", visible=FALSE)
gg <- ggroup(container=w,horizontal=F,use.scrollwindow = T)
down.group <- ggroup(container = gg)
up.group <- ggroup(container = gg)
devs.up <- lapply(1:2, function(i)
ggraphics(container=down.group,label=as.character(i)))
devs.down <- lapply(3:4, function(i)
ggraphics(container=up.group,label=as.character(i)))
visible(w) <- TRUE
lapply(c(devs.up,devs.down), function(gg)
addHandlerChanged(gg, handler=function(h,...) {
par(mfrow=c(1,1))
plot(mpg ~ wt, mtcars)
}))
Upvotes: 1