R gWidgets包:在ggraphis区域更新ggplot图表时停止白屏闪烁

时间:2013-05-30 16:51:05

标签: r ggplot2 gwidgets

如何在R ggplot2包裹的ggraphis区域中更改或更新gWidgets图表时,如何省略闪烁的白色屏幕?

当我使用R的base包中的R图时,在更新图表/图表时不会出现白屏。

### datos
library(cairoDevice)
library(ggplot2)
library(gWidgets)
library(gWidgetsRGtk2)
library(animation)
require(RGtk2)

variable <-rnorm(100)
datetime <-1:100

data=data.frame(variable=variable,datetime=datetime)

options(guiToolkit = "RGtk2")
window <- gwindow ("My first GUI",parent=c(1,1))
group1   <- ggroup(cont = window, horizontal=F,label="Variable1")
option                   <- glayout(cont=group1,horizontal=T ,spacing=0)
option[1,1:6,expand=T]   <-gb<- gbutton("Variable1", cont = option)
font(gb)                 <-c(weight="ultra-bold",size=11)
option[1,1:6,expand=T]  <-g1<-ggraphics(cont = option)
oopt = ani.options(interval = 1,loop =TRUE)
n=dim(data)[1]
for(i in 1:n){
  dev.hold()
  data2=data[which(data$datetime>=(i) & data$datetime<=(i+10)),]
  SPC <- ggplot(data2,aes(x=datetime,y=variable,group=1))+
    geom_line(size=1)+geom_point(size=3)+ 
    geom_line(aes(y=mean(variable),x=datetime[1:length(datetime)]),size=1,colour="green")+
geom_line(aes(y=mean(variable)+((3*sd(variable))/sqrt(length(variable))),x=datetime[1:length(datetime)]),size=1,colour="red")+
geom_line(aes(y=mean(variable)-((3*sd(variable))/sqrt(length(variable))),x=datetime[1:length(datetime)]),size=1,colour="red")+
scale_x_continuous(limits=c(i,i+10),breaks=c(seq(i,i+10,1)))+
theme_bw(base_size=12,base_family="")  
  print(SPC)

  ani.pause()
}
ani.options(oopt)

-

1 个答案:

答案 0 :(得分:0)

尝试改变 打印(SPC) 至 打印(SPC,NEWPAGE = F)