在R裡面做動畫是一件有點複雜的事 首先必須要下載並安裝ImageMagick這個軟體 然後用以下的指令ani.options指定這個軟體的存放位置 以下以scanning window為例

首先造出一個網絡資料

library(igraph)
g <- graph.lattice( c(5,5) )
lg=layout.grid(g)
plot(g,layout=lg)

設定Scan Window的型態,這邊的例子是圓形 以中心為13半徑為1的Window如下

sp=shortest.paths(g)
WIN=NULL
for(k in 1:4)
{
disk=apply(sp,1,function(x)which(x<=k))
WIN=c(WIN,list(disk))
}
mg1=list(c(WIN[[1]][[13]]))
plot.igraph(g,mark.groups=mg1,layout=lg)

完整Scan的結果如以下動畫所示

library(animation)
ani.options(convert = 'C:/Program Files/ImageMagick-6.8.9-Q16/convert.exe')
saveGIF({
  for(D in 1:4)
    {
        for (center in 1:25) 
        {
            mg1=list(c(WIN[[D]][[center]]))
            plot(g,mark.groups=mg1,layout=lg)
        }
    }
},movie.name = "c:\\rtest\\gridnetwork.gif",convert ="convert")
## Executing: 
## "C:/Program Files/ImageMagick-6.8.9-Q16/convert.exe" -loop 0
##     -delay 100 Rplot1.png Rplot2.png Rplot3.png Rplot4.png
##     Rplot5.png Rplot6.png Rplot7.png Rplot8.png Rplot9.png
##     Rplot10.png Rplot11.png Rplot12.png Rplot13.png Rplot14.png
##     Rplot15.png Rplot16.png Rplot17.png Rplot18.png Rplot19.png
##     Rplot20.png Rplot21.png Rplot22.png Rplot23.png Rplot24.png
##     Rplot25.png Rplot26.png Rplot27.png Rplot28.png Rplot29.png
##     Rplot30.png Rplot31.png Rplot32.png Rplot33.png Rplot34.png
##     Rplot35.png Rplot36.png Rplot37.png Rplot38.png Rplot39.png
##     Rplot40.png Rplot41.png Rplot42.png Rplot43.png Rplot44.png
##     Rplot45.png Rplot46.png Rplot47.png Rplot48.png Rplot49.png
##     Rplot50.png Rplot51.png Rplot52.png Rplot53.png Rplot54.png
##     Rplot55.png Rplot56.png Rplot57.png Rplot58.png Rplot59.png
##     Rplot60.png Rplot61.png Rplot62.png Rplot63.png Rplot64.png
##     Rplot65.png Rplot66.png Rplot67.png Rplot68.png Rplot69.png
##     Rplot70.png Rplot71.png Rplot72.png Rplot73.png Rplot74.png
##     Rplot75.png Rplot76.png Rplot77.png Rplot78.png Rplot79.png
##     Rplot80.png Rplot81.png Rplot82.png Rplot83.png Rplot84.png
##     Rplot85.png Rplot86.png Rplot87.png Rplot88.png Rplot89.png
##     Rplot90.png Rplot91.png Rplot92.png Rplot93.png Rplot94.png
##     Rplot95.png Rplot96.png Rplot97.png Rplot98.png Rplot99.png
##     Rplot100.png "c:\rtest\gridnetwork.gif"
## Output at: c:\rtest\gridnetwork.gif
## [1] FALSE

接著就到你指定的資料夾找你造出來的動畫啦