Use animate() with series of levelplots in R raster

Deadly 提交于 2019-12-05 12:35:16

Function animate only accepts raster objects as input. You can try saveGIF to animate levelplots:

library(raster)
library(rasterVis)
library(animation)
library(classInt)

r <- raster(ncol=40, nrow=20)
r[] <- rnorm(n=ncell(r))
s <- stack(x=c(r, r*r, r*r*r, r*r*r*r))

classes <- classIntervals(values(r), n=5, style="fisher", precision = 3)
brks <- classes$brks
brks <- round(brks, 2)

saveGIF({
  for(i in c(1:nlayers(s))){
    l <- levelplot(s[[i]], colorkey=list(at=brks, labels=c(as.character(brks))), margin=FALSE)
    plot(l)
  }
}, interval=0.2, movie.name="animation.gif")

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!