Skip to content

Instantly share code, notes, and snippets.

@ramnathv
Created March 6, 2011 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramnathv/856871 to your computer and use it in GitHub Desktop.
Save ramnathv/856871 to your computer and use it in GitHub Desktop.
# Animated Choropleth of Population Density Change
# read data with population
df = read.csv('http://goo.gl/yJQs8');
names(df) = sub('Persons.', '', names(df));
# read data with areas
df_area = read.xls('http://goo.gl/UJbKE',
sheet = 2, pattern = 'Code')[,c('Code', 'Total')];
df_area$Total = with(df_area, sapply(as.character(Total), sub, pa = ",", r = ''))
df_area$Total = with(df_area, sapply(Total, as.numeric))
# merge the two and compute population density
df = merge(df_area, df, by.x = 'Code', by.y = 'Area.Code');
df[,4:ncol(df)] = df[,4:ncol(df)]/df$Total*10;
.breaks = seq(0, 4000, by = 500);
library(animation);
saveMovie(for (i in 4:ncol(df))
print(plotChoropleth(.poly = london, .df = df,
id1 = 'ons_label', id2 = 'Code',
field = as.character(names(df)[i]),
colpal = 'Oranges', .breaks = .breaks)),
clean = T)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment