user2234497
user2234497

Reputation: 19

R gWidgets package: stop white screen flashing upon updating a ggplot chart in a ggraphis area

How can I omit the white screen which flashes upon the change or update of a ggplot2 chart in a ggraphis area in the R gWidgets package?

When i utilize R plots from the base package of R, the white screen does not appear during the update of charts/plots.

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

-

Upvotes: 2

Views: 575

Answers (1)

ferg
ferg

Reputation: 11

Try changing print(SPC) to print(SPC,newpage=F)

Upvotes: 1

Related Questions