我正在使用 gWidgetsRGtk2 构建 GUI,并且在单击 gbutton 时无法显示 ggplot。绘图功能自己工作(即当您键入“plotData()”时),但我无法让它与 gWidgets 一起工作。gWidgets 和 ggplot2 是否存在兼容性问题,或者我没有正确调用该函数?我已经从 GUI 中剥离了所有其他内容,以使代码更短更简单。情节应该是这样的:
library(ggplot2)
library(gWidgets)
library(gWidgetsRGtk2)
require(gWidgets)
options("guiToolkit"="RGtk2")
X<-cbind(runif(120,min=-22,max=-17),runif(120,min=6,max=12))
MU<-matrix(c(-18.96,-15.86,-24.67,4.04,13.57,9.69),nrow=3,ncol=2)
SIG<-matrix(c(0.6,0.77,0.85,0.85,0.55,0.90),nrow=3,ncol=2)
plotData = function(h,...)
{
C_err <- 0.3
N_err <- 1.0
df <- data.frame(x = X[,1],
y = X[,2],
ymin = X[,2] - N_err,
ymax = X[,2] + N_err,
xmin = X[,1] - C_err,
xmax = X[,1] + C_err)
df_MU <- data.frame(x=MU[,1], y=MU[,2],
ymin = MU[,2] - SIG[,2],
ymax = MU[,2] + SIG[,2],
xmin = MU[,1] - SIG[,1],
xmax = MU[,1] + SIG[,1])
ggplot(data = df,aes(x = x,y = y)) +
geom_point() +
geom_errorbar(aes(ymin = ymin,ymax = ymax)) +
geom_errorbarh(aes(xmin = xmin,xmax = xmax)) +
geom_pointrange(data=df_MU,aes(ymin=ymin,ymax=ymax),colour=c('red','blue','green'),size=1) +
geom_errorbarh(data=df_MU,aes(xmin=xmin,xmax=xmax),colour=c('red','blue','green'),size=1,height=0) +
ggtitle("Isotope Data") +
ylab("d15N (%)") +
xlab("d13C (%)") +
theme_bw()
}
win<-gwindow()
grp_all <- ggroup(container=win, horizontal=F)
plot_button <- gbutton(
text = "Plot data",
container = grp_all,
expand = TRUE,
handler = plotData
)