
Animate a map
animate.RdAnimate (sequentially plot) the layers of a SpatRaster, or the variables or geometries of a SpatVector, to create a movie.
Usage
# S4 method for class 'SpatRaster'
animate(x, pause=0.25, main, range=NULL, maxcell=50000, n=1, ...)
# S4 method for class 'SpatVector'
animate(x, pause=0.25, main="", n=1, vars=NULL, range=NULL, add=NULL, ...)Arguments
- x
SpatRaster or SpatVector
- pause
numeric. How long should the pause be between layers?
- main
title for each layer. For SpatRaster, if not supplied, the z-value is used if available. Otherwise the names are used.
- range
numeric vector of length 2. Range of values to plot, If
NULLthe range of all layers is used for rasters, or all variables for vectors if they are all numeric. IfNAthe range of each individual layer is used- maxcell
positive integer. Maximum number of cells to use for the plot. If
maxcell < ncell(x),spatSample(type="regular")is used before plotting- n
integer > 0. Number of plotting loops
- vars
numeric or character to indicate the variables to animate. If this is NULL, the geometries are animated instead
- add
logical. Add the geometries to the current map? When looping over variables:
NULLis equivalent toTRUE. When looping over geometries: ifTRUE, add all geometries to the current plot. IfNULL,addis set toFALSEfor the first geometry andTRUEfor the remaining ones.- ...
additional arguments passed to
plot
Examples
s <- rast(system.file("ex/logo.tif", package="terra"))
animate(s, n=1)
v <- vect(system.file("ex/lux.shp", package="terra"))
animate(v, n=2)
animate(v, n=1, vars=names(v))
# you can save an animation to file like this
# animation::saveGIF(terra::animate(v, n=1), "animation.gif")