View source: R/tmap_animation.R
| tmap_animation | R Documentation |
Create a gif animation or video from an animated tmap plot. First use tm_animate() or tm_animate_fast() to animate the plot, and then apply tmap_animation() to save it as a gif or video file (e.g. mp4).
tmap_animation(
tm,
filename = NULL,
width = NA,
height = NA,
dpi = NA,
outer.margins = NA,
asp = NULL,
scale = NA,
...
)
tm |
tmap or a list of tmap objects. If |
filename |
filename. If omitted (default), the animation will be shown
in the viewer or browser. If specified, it should be a gif file or a video
file (i.e. mp4). The package |
width, height |
Dimensions of the animation file (in pixels).
Required when |
dpi |
dots per inch. By default 100, but this can be set with the option
|
outer.margins |
(passed on to |
asp |
(passed on to |
scale |
(passed on to |
... |
arguments passed on to |
Not only tmap plots are supported, but any series of R plots.
if (interactive()) {
m1 <- tm_shape(NLD_prov) +
tm_polygons("yellow") +
tm_animate(frames = "name")
tmap_animation(m1, filename = "countries.gif")
m2 <- tm_shape(metro) +
tm_symbols(size = paste0("pop", seq(1950, 2030, by=10)),
size.free = FALSE,
size.legend = tm_legend("Population")) +
tm_layout(panel.labels = seq(1970, 2030, by=10)) +
tm_animate()
tmap_animation(m2, filename = "cities.gif")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.