September 19, 2017

Contents

  1. Purpose
  2. Data Source
  3. Property Crime in 2014
    • Pre-Processing data
    • Choropleth Plot
  4. Violent Crime from 1960-2014
    • Pre-Processing data
    • Multiline Plot
  5. Thank you

1. Purpose

  • This presentation is developed towards the Week-3 assignment of the Data Products course, offered by John Hopkins University on Coursera.org

2. Data Source

  • Website: https://ucrdatatool.gov/Search/Crime/State /StateCrime.cfm
  • Sources: FBI, Uniform Crime Reports, prepared by the National Archive of Criminal Justice Data
  • Date of download: Sep 19 2017

3. Property Crime in 2014

       State Population Property.crime.total Burglary Larceny.theft
1    Alabama    4849377               154094    39715        104238
2     Alaska     736732                20334     3150         15445
3    Arizona    6731484               215240    43562        154091
4   Arkansas    2966369                99018    24790         68627
5 California   38802500               947192   202670        592670
6   Colorado    5355866               135510    23472         99464
  Motor.vehicle.theft
1               10141
2                1739
3               17587
4                5601
5              151852
6               12574

3.1. Pre-Processing

# Turn State names to corresponding state codes
# Read State codes csv
stateCodes<-read.csv("stateCodes.csv")
# Routine to change State names to State codes
getStateCodes<-function(st){
  if(st %in% stateCodes$state){
    return(stateCodes[stateCodes$state==st,]$code);
  }
}

crimeData$code<-sapply(crimeData$State, getStateCodes);
# Create data to show when hovered over the plot
crimeData$hover<-with(crimeData, paste(State,'<br>','Burglary: ',
Burglary,'<br>','Larceny theft: ',Larceny.theft,'<br>','Motor Veh
icle theft: ',Motor.vehicle.theft))

3.2. Choropleth Plot

4. Violent Crime from 1960-2014

# Read the violent crime data
violentCrimeData<-read.csv("violentCrimeDataYearly.csv");
# Let's look at the dimensions of the data
dim(violentCrimeData)
## [1] 55 51
# Look at top 6 column names
head(colnames(violentCrimeData))
## [1] "Year"       "Alabama"    "Alaska"     "Arizona"    "Arkansas"  
## [6] "California"

4.1. Pre-Processing

library(tidyr)
# I selected these states
selectedState<-c("California", "Texas", "Florida", "New.York")
selectedStateIndex<-colnames(violentCrimeData)  %in% selectedState;
timeLine<-violentCrimeData[,1]
selectedStateViolentCrimeData<-violentCrimeData[,selectedStateIndex]

# Create a long dataset suitable for plotly - multiline plot
selectedStateViolentCrimeData<-gather(selectedStateViolentCrimeData,
state, crimeData)
selectedStateViolentCrimeData$Year<-rep(timeLine,4)

4.2. Multiline Plot

5. Thank you

This is end of the presentation.