[R-sig-Geo] Help: create an animated GIF file from PNG files

Yihui Xie xie at yihui.name
Wed Jan 25 23:39:22 CET 2012


You can try the animation package with the function saveGIF(); see the
help page for more info. Basically you just put the code in

saveGIF({
  whatever code that produces plots
})

and you do not need to take care of the issues like opening the
graphical devices; the process is automatic.

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA



On Wed, Jan 25, 2012 at 3:44 PM, Zia Ahmed <zua3 at cornell.edu> wrote:
> I am trying to create an animated GIF file from a set of PNG files
> created from number realization.  Itried with animation ( depend -
> ImageMagick) and caTools packages, but I did not successful to make the
> GIS file.  Is  there any way to do this?
> Thanks
> Zia
>
> # GIF animation
>
> library(sp)
> library(gstat)
> library(lattice)
> library(RColorBrewer)
> library(maptools)
> library(maps)
> library(ggplot2)
> library(lubridate)
> library(animation)
> library(fields) # for tim.colors
> library(caTools) # for write.gif
> library(raster)
>
> data(meuse)
> data(meuse.grid)
> coordinates(meuse) <- ~x+y
> coordinates(meuse.grid) <- ~x+y
> gridded(meuse.grid) <- TRUE
>
> lzn.vgm <- variogram(log(zinc)~1, meuse)
> lzn.fit <- fit.variogram(lzn.vgm, model = vgm(1, "Sph", 900, 1))
>
> ns=4
>
> sim_ns = krige(log(zinc)~1, meuse, meuse.grid, model = lzn.fit,
> nmax = 30, nsim = ns)
>
> # Save figures as PNG files
>
> rgb.palette <- colorRampPalette(c("lightyellow","green","orange","brown"),
> space = "rgb")
>
> setwd("C:/sim")
>
> for (i in 1:ns){
> png(filename = paste("sim",i,".png",sep=""), width=400, height=500,
> units="px",
> pointsize=12, bg="transparent", res=NA)
> print(spplot(sim_ns[,i], main = list(label=paste("SIS",i),cex=1.5),
> par.settings=list(axis.line=list(col=NA)),
> col.regions=rgb.palette(22)))
> dev.off()
> }
>
> # Creat a gif.file
> system("convert -delay 40 *.png sim.gif") #
> Source(http://ryouready.wordpress.com/2010/11/21/animate-gif-images-in-r-imagemagick/)
> Invalid Parameter - 40
> Warning message:
> running command 'convert -delay 40 sim*.png plot.gif', invisible = F,
> wait=T' had status 4
>
>
>
> ---------------------
> Zia Ahmed, PhD
> Research Associate
> Department of Crop and Soil Sciences
> 1002 Bradfield Hall, Cornell University
> Ithaca, NY 14853-4203
> t. 607.255.9387
> f. 607.255.3207
> email zua3 at cornell.edu
>
>
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list