Learn R Programming

choroplethr (version 3.7.3)

choroplethr_animate: Animate a list of choropleths

Description

Given a list of choropleths, represented as ggplot2 objects

  1. Save the individual images to the working directory with the naming convention "choropleth_1.png", "choropleth_2.png", etc.

  2. Write a file called "animated_choropleth.html" which contains a viewer which animates them.

Usage

choroplethr_animate(choropleths)

Value

Nothing. However, a variable number of files are written to the current working directory.

Arguments

choropleths

A list of choropleths represented as ggplot2 objects.

Author

Ari Lamstein (R code) and Brian Johnson (JavaScript, HTML and CSS code)

Examples

Run this code
if (FALSE) {
data(df_president_ts)
?df_president_ts # time series of all US presidential elections 1789-2012

# create a list of choropleths of presidential election results for each year
choropleths = list()
for (i in 2:(ncol(df_president_ts))) {
  df           = df_president_ts[, c(1, i)]
  colnames(df) = c("region", "value")
  title        = paste0("Presidential Election Results: ", colnames(df_president_ts)[i])
  choropleths[[i-1]] = state_choropleth(df, title=title)
}

# set working directory and animate
setwd("~/Desktop")
choroplethr_animate(choropleths)
}

Run the code above in your browser using DataLab