Created
March 6, 2011 00:27
-
-
Save ramnathv/856871 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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