Skip to content

Instantly share code, notes, and snippets.

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