Learn R Programming

EpiContactTrace (version 0.8.8)

Animate: Animate

Description

Visualize and animate movements on a map.

Usage

Animate(movements, coords, map,
    interval = c("all", "day", "week", "month", "quarter", "year"),
    outdir = getwd(), title = "Animation of contacts")

Arguments

movements
a data.frame data.frame with movements, see details.
coords
a data.frame data.frame with coordinates, see details.
map
a ggmap object to use as background map, see get_map.
interval
the time interval to aggregate movements in the animation. Can be any of 'all', 'day', 'week', 'month', 'quarter' or 'year'. Defaults to 'all', which aggregates all movements on one map.
outdir
the output directory for the animation, see ani.options. Defaults to getwd().
title
the title of the animation in the HTML, see ani.options. Defaults to 'Animation of contacts'.

Value

  • invisible(NULL)

Details

The argument movements in Animate is a data.frame with the following columns: [object Object],[object Object],[object Object]

The argument coords in Animate is a data.frame with the following columns: [object Object],[object Object],[object Object]

References

  • Yihui Xie (2013). animation: An R Package for Creating Animations and Demonstrating Statistical Methods. Journal of Statistical Software, 53(1), 1-27. URL http://www.jstatsoft.org/v53/i01/
  • Kahle, D. and Wickham, H. Manual package 'ggmap' - A package for spatial visualization with Google Maps and OpenStreetMap. URL http://cran.r-project.org/web/packages/ggmap/ggmap.pdf
  • Widgren, S. and Frossling, J., Spatio-temporal evaluation of cattle trade in Sweden: description of a grid network visualization technique. Geospatial Health 5(1), 2010, pp 119-130. URL http://www.geospatialhealth.unina.it/articles/v5i1/gh-v5i1-12-widgren.pdf

Examples

Run this code
require(ggmap)

data(transfers)

## First extract all source and destination from the dataset
root <- unique(c(transfers$source, transfers$destination))

## For this example, generate a random coordinate for each
## holding. Note that some coordinates might end up in water,
## but the coordinates are only for demonstrating the animation.
ngen <- length(root)
set.seed(123)
lon_min <- 13
lon_max <- 17
lat_min <- 56
lat_max <- 63

lon <- lon_min + runif(ngen) * (lon_max - lon_min)
lat <- lat_min + runif(ngen) * (lat_max - lat_min)
coords <- data.frame(id=root, lon, lat)

## Fetch a map over Sweden
sweden <- get_map('Sweden', zoom=5)

## Select a subset of all movements to visualize
i <- sample(seq_len(nrow(transfers)), 100, replace=FALSE)

## Perform the animation and view the movements aggregated by week
## in a web-browser.
Animate(transfers[i,], coords, sweden, "week")

Run the code above in your browser using DataLab