Learn R Programming

tmap (version 1.2)

animation_tmap: Create animation

Description

Create a gif or mpeg animation from a tmap plot. The free tool ImageMagick is required.

Usage

animation_tmap(tm, filename = "animation.gif", width = 1000,
  height = 1000, delay = 40)

Arguments

tm
tmap object. In order to create a series of tmap plots, which will be the frames of the animation, it is important to set nrow and ncol in tm_facets, for otherwise a small multiples plot is generated. Com
filename
filename of the video (should be a .gif or .mpg file)
width
width of the animation file (in pixels)
height
height of the animation file (in pixels)
delay
delay time between images (in 1/100th of a second)

Examples

Run this code
require(dplyr)
data(World, metro, Europe)

(tm_shape(Europe) + 
	tm_fill("yellow") + 
	tm_borders() + 
	tm_facets(by = "name", nrow=1,ncol=1) + 
	tm_layout(scale=2, outer.margins=0,asp=0)) %>%
animation_tmap(filename="European countries.gif", width=1200, height=800, delay=100)

(tm_shape(World) +
  tm_polygons() +
tm_shape(metro) + 
  tm_bubbles(paste0("pop", seq(1970, 2030, by=10)), border.col = "black", border.alpha = .5) +
tm_facets(free.scales.bubble.size = FALSE, nrow=1,ncol=1) + 
tm_format_World(scale=2, outer.margins=0,asp=0)) %>%
animation_tmap(filename="World population.gif", width=1200, height=550, delay=100)

Run the code above in your browser using DataLab