Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.