Salt Lake City Crime

 

Introduction

Salt Lake City,is the capital and the most populous municipality of the U.S. state of Utah. With an estimated population of 190,884 in 2014,the city lies at the core of the Salt Lake City metropolitan area, which has a total population of 1,153,340 (2014 estimate). Salt Lake City is further situated within a larger metropolis known as the Salt Lake City-Ogden-Provo Combined Statistical Area. This region is a corridor of contiguous urban and suburban development stretched along an approximately 120-mile (190 km) segment of the Wasatch Front, comprising a total population of 2,423,912 as of 2014.It is one of only two major urban areas in the Great Basin and the largest in the Intermountain West.

According to FBI Crime data Salt Lake city had the highest car theft rate in the US.In this script, we try to briefly analyse the data collected by the SLC Open Data Website. This data can be found at Kaggle.

Description

Top Crimes

slc %>% group_by(description) %>% summarise(n=n()) %>% na.omit() %>% arrange(desc(n)) %>%
hchart("column",x=description,y=log(n))%>% hc_add_theme(hc_theme_google())
## Error in loadNamespace(name): there is no package called 'webshot'
DT::datatable(slc %>% group_by(description) %>% summarise(n=n()) %>% na.omit() %>% arrange(desc(n)))
## Error in loadNamespace(name): there is no package called 'webshot'

From the above plots and tables we see that larceny,or , in other words , theft of private property comes first in terms of frequency of occurrence. The number of crimes that involved the disruption of public property was 8256, which is about 3245 lesser than the occurrences of larceny.

Top 10 Through time(Hours)

crimes<- c("LARCENY","PUBLIC ORDER","DRUGS","ASSAULT","PUBLIC PEACE","ESCAPE","DAMAGED PROP","NONREPTABL TA","REPORTABLE TA","STOLEN VEHICLE")
colors <- c("#487098","#484898","#34348d","#19198b","#208582","#942f59","#dd125b","#000000","#c61051","#000FFF")
slc %>% group_by(hour,description) %>% summarise(n=mean(n())) %>% filter(description %in% crimes) %>% na.omit() %>%
hchart("line",x=hour,y=n,group=description)%>% hc_add_theme(hc_theme_google()) %>% hc_colors(colors)
## Error in loadNamespace(name): there is no package called 'webshot'

The mean numbesr of the top ten crimes increase in the late afternoon. Crimes reduce early in the morning. The mean number of larceny cases are the highest at 3.00PM. The number of drug cases are the highest at 5.00PM.Utah has had a sudden spike in drug offences due to the ever increasing growth of drug cartels across the US-Mexico border.

Top 10 Through time(Days)

colors <- c("#487098","#484898","#34348d","#19198b","#208582","#942f59","#dd125b","#000000","#c61051","#000FFF")
slc %>% group_by(day,description) %>% summarise(n=mean(n())) %>% filter(description %in% crimes) %>% na.omit() %>%
hchart("column",x=day,y=n,group=as.factor(description))%>% hc_add_theme(hc_theme_google()) %>% hc_colors(colors)
## Error in loadNamespace(name): there is no package called 'webshot'

The amount of larceny cases increase as we go through the middle of the week,peaking on Wednesdays.Number of drug related cases follow the same trend. These numbers dip on Sundays. Assault cases peak up during the weekends. The number of cases that disrupt public peace stays constant for most part of the week.The number of cases related to damage of property on the other hand dips in the middle of the week.

Police Zones that cater to the top ten(Number of Cases greater than 200)

slc %>% group_by(police.zone,description) %>% summarise(n=n()) %>% filter(description %in% crimes,police.zone!="",n>200) %>%
ggplot(aes(x=n, y=police.zone)) +
geom_segment(aes(yend=police.zone), xend=0, colour="grey50") +
geom_point(size=3, aes(colour=description)) + scale_colour_brewer(palette="Set1", guide=FALSE) +
theme_bw() +
theme(panel.grid.major.y = element_blank()) +
facet_grid(description ~ ., scales="free_y", space="free_y")
## Warning in RColorBrewer::brewer.pal(n, pal): n too large, allowed maximum for palette Set1 is 9
## Returning the palette you asked for with that many colors
## Warning: Removed 5 rows containing missing values (geom_point).

 

City Zones

Total number of crimes

slc %>% group_by(city) %>% summarise(n=n()) %>% filter(city!="") %>%
ggplot(aes(x=reorder(city, log(n)), y=log(n*100))) +
geom_bar(stat="identity", colour="black") +
xlab("city")+coord_flip()+ggtitle("Number of Crime Occurrences by City Zones")

plot of chunk unnamed-chunk-6

By totalling the number of crimes, Salt Lake city had the highest, followed by South Salt Lake county. Salt Lake City is the most populous county in Utah, which is probably why the number of crimes are so high.

Top Ten Cities

cities <- c("SALT LAKE CITY","SOUTH SALT LAKE","WEST VALLEY CITY","WEST MILLCREEK","MIDVALE","SANDY","MURRAY","KEARNS","TAYLORSVILLE","DRAPER")

slc %>% group_by(city,description) %>% summarise(n=n()) %>% filter(city %in% cities) %>% top_n(2) %>% ggplot(aes(x=city, y=log(n*100), fill=description)) +
geom_bar(position="dodge",stat="identity")+ theme(plot.title=element_text(size=18),axis.text.x = element_text(angle=90, vjust=1))+ggtitle("Top Two Crimes in the Top Ten City Zones")
## Selecting by n

plot of chunk unnamed-chunk-7


The common crime in all the top ten city is the disruption of public order.The second highest crime in terms of occurrence is drug related in counties such as Midvale,Sandy and South Salt Lake.

Salt Lake City

salt <- filter(slc,city=="SALT LAKE CITY")

salt <- salt %>% group_by(description) %>% summarise(n=n())
salt <- salt %>%
dplyr::mutate(Percentage = (n/sum(n))*100)
for(i in 1:dim(salt)[1]){
if(salt[i,]$Percentage<5){
salt[i,]$description<-"Other"
}
}
pie_chart <- plot_ly() %>%
add_pie(data = salt,
labels=salt$description,
values = salt$Percentage,
name = "By Crime") %>% layout(title = 'Percentage Crimes in Salt Lake City',
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))

pie_chart
## Error in loadNamespace(name): there is no package called 'webshot'

SOUTH SALT LAKE

south <- filter(slc,city=="SOUTH SALT LAKE")

south <- south %>% group_by(description) %>% summarise(n=n())
south <- south %>%
dplyr::mutate(Percentage = (n/sum(n))*100)
for(i in 1:dim(salt)[1]){
if(salt[i,]$Percentage<5){
salt[i,]$description<-"Other"
}
}
pie_chart <- plot_ly() %>%
add_pie(data = salt,
labels=salt$description,
values = salt$Percentage,
name = "By Crime") %>% layout(title = 'Percentage Crimes in South Salt Lake County',
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))

pie_chart
## Error in loadNamespace(name): there is no package called 'webshot'

WEST VALLEY CITY

west <- filter(slc,city=="WEST VALLEY CITY")

west <- west %>% group_by(description) %>% summarise(n=n())
west <- west %>%
dplyr::mutate(Percentage = (n/sum(n))*100)
for(i in 1:dim(salt)[1]){
if(salt[i,]$Percentage<5){
salt[i,]$description<-"Other"
}
}
pie_chart <- plot_ly() %>%
add_pie(data = salt,
labels=salt$description,
values = salt$Percentage,
name = "By Crime") %>% layout(title = 'Percentage Crimes in West Valley City County',
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))

pie_chart
## Error in loadNamespace(name): there is no package called 'webshot'

Location Wise

Frequency of top ten Crimes

library(ggmap)
slc <- na.omit(slc)
temp <- filter(slc,description %in% crimes)
testmap <- get_googlemap(c(lon=mean(slc$x_gps_coords),lat=mean(slc$y_gps_coords)) ,zoom=10, xlim=c(min(slc$x_gps_coords),max(slc$x_gps_coords)), ylim=c(min(slc$y_gps_coords),max(slc$y_gps_coords)))

Source

https://www.neighborhoodscout.com/ut/salt-lake-city/crime/
http://www.sltrib.com/news/2054450-155/war-on-drugs-cartels-target-salt

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s