In this post I will extend a previous analysis creating a borough-level heat map of NYC motor vehicle collisions. The data is from NYC Open Data. In particular, I will go from borough-level to street-level collisions. The processing of the code is very similar to the previous analysis, with a few more functions that map streets to colors. Below, I load the ggmap package, and the data, and only keep collisions with longitude and latitude information.
library(ggmap) d=read.csv('.../NYPD_Motor_Vehicle_Collisions.csv') d_clean=d[which(regexpr(',',d$LOCATION)!=-1),] #### 1. Clean Data #### # get long and lat coordinates from concatenated "location" var comm=regexpr(',',d_clean$LOCATION) d_clean$loc=as.character(d_clean$LOCATION) d_clean$lat=as.numeric(substr(d_clean$loc,2,comm-1)) d_clean$long=as.numeric(substr(d_clean$loc,comm+1,nchar(d_clean$loc)-1)) # create year variable d_clean$year=substr(d_clean$DATE,7,10)