- Purpose
- Data Source
- Property Crime in 2014
- Pre-Processing data
- Choropleth Plot
- Violent Crime from 1960-2014
- Pre-Processing data
- Multiline Plot
- Thank you
September 19, 2017
https://ucrdatatool.gov/Search/Crime/State /StateCrime.cfmState 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
# 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))
# 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"
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)
This is end of the presentation.