Tcl/Tk 在脚本中引用用户选择的值
Tcl/Tk Referencing user-selected values in script
一个关于 Tcl/Tk 和 R 的快速问题。下面我有一段代码对应于执行 ToDo<-function(){...}
的 Tk 按钮。
我的假设是 summary.myData()
和 ggplot()
命令都将执行。话虽如此,我的问题是我是否已正确编码每个命令以引用正确的选定变量(控制它的 tk 小部件工作正常,因此未描述)。
即每个命令的参数是否有效。
summary.myData<-summarySE(myData, measurevar=paste(tx.choice1), groupvars=paste(tx.choice2),conf.interval=0.95,na.rm=TRUE,.drop=FALSE)
将被 R 读取为
summary.myData<-summarySE(myData, measurevar=Measure, groupvars=Group,conf.interval=0.95,na.rm=TRUE,.drop=FALSE)
和
ggplot(data=summary.myData,aes(x=paste(tx.choice2),y=paste(tx.choice1)))+
geom_errorbar(aes(ymin=formula(paste(tx.choice1),"-ci"),ymax=formula(paste(tx.choice1),"+ci")), colour="black", width=.5, position=pd)+
geom_point(position=pd, size=3)+
labs(title=paste("Interval Plot of",tx.choice1,"By",tx.choice2))
将被解读为
ggplot(data=summary.mydata, aes(x=Group, y=Measure))+
geom_errorbar(aes(ymin=Measure-ci, ymax=Measure+ci), colour="black", width=.5, position=pd)+
geom_point(position=pd, size=3)+
labs(title = "New plot title",x="X",y="y")
参考切片:
ToDo<-function(){
tx.choice1<<-vars.name.num[as.integer(tkcurselection(tl1))+1]
tx.choice2<<-vars.name.fac[as.integer(tkcurselection(tl2))+1]
numb.select.num<<-length(tx.choice1)
numb.select.fac<<-length(tx.choice2)
windows()
if (numb.select.num!=0){
if (numb.select.fac==0){
stop(tkmessageBox(message="Please select at least one categorical variable!", icon="error"))
}
else if (numb.select.fac==1) {
if(tclvalue(intervalplot_title)=="" & tclvalue(intervalplot_x)=="" & tclvalue(intervalplot_y)==""){
summary.myData<-summarySE(myData, measurevar=paste(tx.choice1), groupvars=paste(tx.choice2),conf.interval=0.95,na.rm=TRUE,.drop=FALSE)
ggplot(data=summary.myData,aes(x=paste(tx.choice2),y=paste(tx.choice1)))+
geom_errorbar(aes(ymin=formula(paste(tx.choice1),"-ci"),ymax=formula(paste(tx.choice1),"+ci")), colour="black", width=.5, position=pd)+
geom_point(position=pd, size=3)+
labs(title=paste("Interval Plot of",tx.choice1,"By",tx.choice2))
} else {
summary.myData<-summarySE(myData, measurevar=paste(tx.choice1), groupvars=c(paste(tx.choice2)),conf.interval=0.95,na.rm=TRUE,.drop=FALSE)
ggplot(data=summary.myData,aes(x=paste(tx.choice2),y=paste(tx.choice1)))+
geom_errorbar(aes(ymin=paste(tx.choice1)-ci,ymax=paste(tx.choice1)+ci), colour="black", width=.5, position=pd)+
geom_point(position=pd, size=3)+
labs(title=tclvalue(intervalplot_title),x=tclvalue(intervalplot_x),y=tclvalue(intervalplot_y))
}
tkinsert(txt,"end",paste("\nIntervalplot of", tx.choice1,"By",tx.choice2[1],"\n\n"))
}
}
想通了,正确的用法应该是 paste(tx.choice1,"-ci")
。不需要添加formula()
条件。
一个关于 Tcl/Tk 和 R 的快速问题。下面我有一段代码对应于执行 ToDo<-function(){...}
的 Tk 按钮。
我的假设是 summary.myData()
和 ggplot()
命令都将执行。话虽如此,我的问题是我是否已正确编码每个命令以引用正确的选定变量(控制它的 tk 小部件工作正常,因此未描述)。
即每个命令的参数是否有效。
summary.myData<-summarySE(myData, measurevar=paste(tx.choice1), groupvars=paste(tx.choice2),conf.interval=0.95,na.rm=TRUE,.drop=FALSE)
将被 R 读取为
summary.myData<-summarySE(myData, measurevar=Measure, groupvars=Group,conf.interval=0.95,na.rm=TRUE,.drop=FALSE)
和
ggplot(data=summary.myData,aes(x=paste(tx.choice2),y=paste(tx.choice1)))+
geom_errorbar(aes(ymin=formula(paste(tx.choice1),"-ci"),ymax=formula(paste(tx.choice1),"+ci")), colour="black", width=.5, position=pd)+
geom_point(position=pd, size=3)+
labs(title=paste("Interval Plot of",tx.choice1,"By",tx.choice2))
将被解读为
ggplot(data=summary.mydata, aes(x=Group, y=Measure))+
geom_errorbar(aes(ymin=Measure-ci, ymax=Measure+ci), colour="black", width=.5, position=pd)+
geom_point(position=pd, size=3)+
labs(title = "New plot title",x="X",y="y")
参考切片:
ToDo<-function(){
tx.choice1<<-vars.name.num[as.integer(tkcurselection(tl1))+1]
tx.choice2<<-vars.name.fac[as.integer(tkcurselection(tl2))+1]
numb.select.num<<-length(tx.choice1)
numb.select.fac<<-length(tx.choice2)
windows()
if (numb.select.num!=0){
if (numb.select.fac==0){
stop(tkmessageBox(message="Please select at least one categorical variable!", icon="error"))
}
else if (numb.select.fac==1) {
if(tclvalue(intervalplot_title)=="" & tclvalue(intervalplot_x)=="" & tclvalue(intervalplot_y)==""){
summary.myData<-summarySE(myData, measurevar=paste(tx.choice1), groupvars=paste(tx.choice2),conf.interval=0.95,na.rm=TRUE,.drop=FALSE)
ggplot(data=summary.myData,aes(x=paste(tx.choice2),y=paste(tx.choice1)))+
geom_errorbar(aes(ymin=formula(paste(tx.choice1),"-ci"),ymax=formula(paste(tx.choice1),"+ci")), colour="black", width=.5, position=pd)+
geom_point(position=pd, size=3)+
labs(title=paste("Interval Plot of",tx.choice1,"By",tx.choice2))
} else {
summary.myData<-summarySE(myData, measurevar=paste(tx.choice1), groupvars=c(paste(tx.choice2)),conf.interval=0.95,na.rm=TRUE,.drop=FALSE)
ggplot(data=summary.myData,aes(x=paste(tx.choice2),y=paste(tx.choice1)))+
geom_errorbar(aes(ymin=paste(tx.choice1)-ci,ymax=paste(tx.choice1)+ci), colour="black", width=.5, position=pd)+
geom_point(position=pd, size=3)+
labs(title=tclvalue(intervalplot_title),x=tclvalue(intervalplot_x),y=tclvalue(intervalplot_y))
}
tkinsert(txt,"end",paste("\nIntervalplot of", tx.choice1,"By",tx.choice2[1],"\n\n"))
}
}
想通了,正确的用法应该是 paste(tx.choice1,"-ci")
。不需要添加formula()
条件。