Learn R Programming

terra (version 1.9-11)

animate: Animate a map

Description

Animate (sequentially plot) the layers of a SpatRaster, or the variables or geometries of a SpatVector, to create a movie.

Usage

# S4 method for SpatRaster
animate(x, pause=0.25, main, range=NULL, maxcell=50000, n=1, ...)

# S4 method for SpatVector animate(x, pause=0.25, main="", n=1, vars=NULL, range=NULL, add=NULL, ...)

Value

None

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 NULL the range of all layers is used for rasters, or all variables for vectors if they are all numeric. If NA the 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 plot? When looping over geometries: if TRUE, add all geometries to the current plot. If NULL, add is set to FALSE for the first geometry and TRUE for the remaining ones. This argument is ignored when vars is not NULL

...

additional arguments passed to plot

Author

Márcia Barbosa, Robert J. Hijmans

See Also

Examples

Run this code
s <- rast(system.file("ex/logo.tif", package="terra"))   
animate(s, n=1)

v <- vect(system.file("ex/lux.shp", package="terra"))
animate(v[1:3, ], n=1)
# animate(v, vars=names(v))

# you can save an animation to file like this
# animation::saveGIF(terra::animate(v), "animation.gif")

Run the code above in your browser using DataLab