Skip to content

Instantly share code, notes, and snippets.

@ckholmes5
Created July 22, 2016 18:02
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/7dc995e7c3ae1b6771dd8f1f585d10cc to your computer and use it in GitHub Desktop.
Save ckholmes5/7dc995e7c3ae1b6771dd8f1f585d10cc to your computer and use it in GitHub Desktop.
grouped_crime = summarise(group_by(statemerge, Year), Violent.Crime.Total = sum(Violent.crime.total), Property.Crime.Total = sum(Property.crime.total)
grouped_crime = mutate(grouped_crime, Total_rate = (Violent.Crime.Total+Property.Crime.Total)*1000/Population, Violent_rate = Violent.Crime.Total*1000/Population, Property_rate = Property.Crime.Total*1000/Population
graph1 = ggplot(grouped_crime, aes(Year, colour = 'red')) +
geom_line(aes(Year, Total_rate), size = 1.5) +
ylab('Crimes per 1000 Residents') +
ggtitle('Total Crime from 1977-2012') +
theme_bw() +
theme(plot.title = element_text(size = rel(2)), legend.position="none")
graph2 = ggplot(grouped_crime, aes(Year)) +
geom_line(aes(Year, Property_rate, color = 'Property_rate'), size = 1.5) +
ylab('Crimes per 1000 Residents') +
geom_line(aes(Year, Violent_rate, color = 'Violent_rate'), size = 1.5) +
ggtitle('Violent and Nonviolent Crime from 1977-2012') +
theme_bw() +
theme(plot.title = element_text(size = rel(2))) +
scale_color_manual(values = c('blue', 'indianred1'),name= "Crime Type", labels=c("Property", "Violent"))
graph3 = ggplot(grouped_crime, aes(Year, colour = 'red')) +
ylab('Crimes per 1000 Residents') +
geom_line(aes(Year, Violent_rate), size = 1.5) +
ggtitle('Violent Crime from 1977-2012') +
theme_bw() +
theme(plot.title = element_text(size = rel(2)), legend.position = 'none')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment