问题
Using the gWidgets package I have made a R widget that shows a lattice graphic when the user click on a button.
The function producing the graphic (fgraph()
below) runs well outside the widget. However the graphic at the topleft corner does not appear in the widget.
Here is a reproducible code:
library(lattice)
sims <- data.frame(
y=rnorm(8),
A=factor(c(1,1,1,1,2,2,2,2)),
B=factor(c(1,1,2,2,1,1,2,2)),
C=factor(c(1,2,1,2,1,2,1,2))
)
fgraph <- function(sims){
plot(
dotplot(y ~ A | B+C , data = sims,
ylab="Zeta (mV)",
panel = function(...){
panel.abline(v=c(1,2), col = "grey", lty = 2)
panel.grid(col = "grey", lty = 2, v=0)
panel.xyplot(..., pch = 16, col="black")
}
)
)
}
library(gWidgetsRGtk2)
options(guiToolkit = "RGtk2")
win <- gwindow("Simulation")
GROUP <- ggroup(cont=win)
graphwindow <- ggraphics(container = GROUP,
expand = TRUE, ps = 11)
GoGroup <- ggroup(horizontal=FALSE, container = GROUP)
addSpring(GoGroup)
Simulates <- gbutton(text="Simulates", container = GoGroup,
handler = function(h, ...) {
fgraph(sims)
}
)
来源:https://stackoverflow.com/questions/14281135/lattice-graphics-in-a-r-widget