View source: R/choroplethr_animate.R
choroplethr_animate | R Documentation |
Given a list of choropleths, represented as ggplot2 objects
Save the individual images to the working directory with the naming convention "choropleth_1.png", "choropleth_2.png", etc.
Write a file called "animated_choropleth.html" which contains a viewer which animates them.
choroplethr_animate(choropleths)
choropleths |
A list of choropleths represented as ggplot2 objects. |
Nothing. However, a variable number of files are written to the current working directory.
Ari Lamstein (R code) and Brian Johnson (JavaScript, HTML and CSS code)
## Not run:
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)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.