View source: R/tmap_animation.R
tmap_animation | R Documentation |
Create a gif animation or video from a tmap plot.
tmap_animation( tm, filename = NULL, width = NA, height = NA, dpi = NA, delay = 40, fps = NA, loop = TRUE, outer.margins = NA, asp = NULL, scale = NA, restart.delay = NULL, ... )
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 |
width and height of the animation file (in pixels). Required when |
dpi |
dots per inch. By default 100, but this can be set with the option |
delay |
delay time between images (in 1/100th of a second). See also |
fps |
frames per second, calculated as |
loop |
logical that determined whether the animation is looped, or an integer value that determines how many times the animation is looped. |
outer.margins |
(passed on to |
asp |
(passed on to |
scale |
(passed on to |
restart.delay |
not used anymore |
... |
arguments passed on to |
Not only tmap plots are supported, but any series of R plots.
## Not run: data(NLD_prov) m1 <- tm_shape(NLD_prov) + tm_polygons("yellow") + tm_facets(along = "name") tmap_animation(m1, delay=40) data(World, metro) m2 <- tm_shape(World, projection = "+proj=eck4", simplify = 0.5) + tm_fill() + tm_shape(metro) + tm_bubbles(size = paste0("pop", seq(1970, 2030, by=10)), col = "purple", border.col = "black", border.alpha = .5, scale = 2) + tm_facets(free.scales.symbol.size = FALSE, nrow=1,ncol=1) + tm_format("World") tmap_animation(m2, delay=100, outer.margins = 0) m3 <- lapply(seq(50, 85, by = 5), function(age) { World$at_most <- World$life_exp <= age World_sel <- World[which((World$life_exp <= age) & (World$life_exp > (age - 5))), ] tm_shape(World) + tm_polygons("at_most", palette = c("gray95", "gold"), legend.show = FALSE) + tm_shape(World_sel) + tm_text("name", size = "AREA", root = 5, remove.overlap = TRUE) + tm_layout(main.title = paste0("Life expectency at most ", age), frame = FALSE) }) tmap_animation(m3, width = 1200, height = 600, delay = 100) m4 <- tm_shape(World) + tm_polygons() + tm_shape(metro) + tm_bubbles(col = "red") + tm_text("name", ymod = -1) + tm_facets(by = "name", free.coords = F, nrow = 1, ncol = 1) + tm_layout(panel.show = FALSE, frame = FALSE) tmap_animation(m4, filename = "World_cities.mp4", width=1200, height = 600, fps = 2, outer.margins = 0) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.