Skip to content

Instantly share code, notes, and snippets.

@ckholmes5
Created July 22, 2016 18:15
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 ckholmes5/a90f4c487ffbf66d2f2bfca6df6e1535 to your computer and use it in GitHub Desktop.
Save ckholmes5/a90f4c487ffbf66d2f2bfca6df6e1535 to your computer and use it in GitHub Desktop.
map_df = map_df[order(map_df$order),]
years = sort(unique(statecrime$Year))
maps = list()
for (i in 1:length(years)) {
df = subset(map_df, Year == years[i])
g = ggplot(df, aes(x=long,y=lat,group=group))+
geom_polygon(aes(fill=VC_rate))+
geom_path()+
coord_map()+
scale_fill_gradient(limits = c(0,12), low='deepskyblue', high = 'red', breaks = c(0, 4,8, 12)) +
theme(axis.title = element_blank(), axis.text = element_blank(),panel.background = element_blank(), axis.ticks = element_blank(), legend.key.size = unit(.3, 'cm'), legend.title = element_text(size = 8))+
labs(title = paste(years[i]), fill = 'Violent Crimes \n(per 1000 residents)')
ggsave(paste('~/', i, '.png'), device = 'png')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment