将animate()与R raster中的一系列关卡图一起使用 [英] Use animate() with series of levelplots in R raster

查看:154
本文介绍了将animate()与R raster中的一系列关卡图一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按时间顺序排列的每年25个土地覆盖栅格的时间序列.由于这是分类数据,因此我使用levelplot(inputRaster)(rasterVis库的一部分)来绘制单个栅格.但是,我想依次绘制年度栅格,就像栅格库的animate函数一样.当我使用

I have a time series of 25 yearly land cover rasters. As this is categorical data, I use levelplot(inputRaster) (part of the rasterVis library) to plot a single raster. However, I would like to sequentially plot the yearly rasters, as the animate function of the raster library does. When I use

rasStack <- stack(listOfRasters) animate(rasStack)

rasStack <- stack(listOfRasters) animate(rasStack)

结果没有分类图例. 简而言之:我该如何结合levelplotanimate的功能?

The result does not have a categorical legend. So in short: how can I combine the functionalities of levelplot and animate?

推荐答案

函数animate仅接受栅格对象作为输入.您可以尝试saveGIF为关卡设置动画:

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

这篇关于将animate()与R raster中的一系列关卡图一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆