Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

animation in knitr document with ggplot figures

I am trying to use the following chunk in my knitr document that creates a pdf

<<animate_gg,fig.show='animate', eval=TRUE>>=
gg.list<-list()
for (w.it in w.vals){
sub.final.pts.lf.logical<-all.final.pts.lf$w %in% w.it
sub.final.pts.lf<- all.final.pts.lf[sub.final.pts.lf.logical,]
levels(sub.final.pts.lf$w)<- paste("w=",levels(sub.final.pts.lf$w))

g1<-ggplot(sub.final.pts.lf,aes(x=x,y=y,colour=pt.name))+geom_point(alpha = 1/5) +scale_shape(solid = FALSE)
gg.list<-c(gg.list,list(g1))
}
for (gg in gg.list){
gg  
}

however this doesn't create any corresponding section in latex. I assume the problem is that if I use gg inside brackets, R doesn't evaluate that line.The following creates the animation with one plot

 {
g1<-ggplot(sub.final.pts.lf,aes(x=x,y=y,colour=pt.name))+geom_point(alpha = 1/5) +scale_shape(solid = FALSE)

}
g1 

How do I create an animation with all of the created plots?

like image 321
statistician_in_training Avatar asked Nov 16 '13 06:11

statistician_in_training


1 Answers

The top FAQ (7.22) for grid-based graphics: print(gg)

like image 197
Yihui Xie Avatar answered Oct 15 '22 17:10

Yihui Xie