1

使用 gWidgets 包,我制作了一个 R 小部件,当用户单击按钮时,它会显示格子图形。生成图形(fgraph()下图)的函数在小部件之外运行良好。但是左上角的图形不会出现在小部件中。这是一个可重现的代码:

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)
    }
) 

在此处输入图像描述

4

0 回答 0