Geo-Spatial Analysis of Complaints near Subway exits (in Queen Borough)

NYPD dispatch receives hundreds of call requests reporting various degrees of complaints, some knotting their relation to criminal activities. To monitor and process these rates with better understanding, we are considering a case where we compare such events happening in the proximity of subway exits. Consideration of such a concept exhibits patterns of how far such incidents occur from public places and aids us to get a better idea of its mapping. Moreover, it helps in the identification of patterns that can be relevant for further patrolling schedules.

The data indicates mostly completed complaint requests spanning from late 2020 to the latest of May of 2021. (The possible range of data is described.) The complaint completion is being classified into such categories:

  1. FELONY
  2. MISDEMEANOR
  3. VIOLATION
# Loading Primary data:
options(warn = -1)
suppressPackageStartupMessages({
library(dplyr)
library(leaflet)
library(formattable)})

Sub<-read.csv("subway.csv")
Complaint<-read.csv("NYPD_complaint.csv")

#NOTE: This data has been pre-processed, necessary for further manipulation.Here most significant functions are showcased.
# To avail formatted data refer last section. 
# Manipulating data
Sub1<-Sub %>% filter(Long > -73.960457)
Complaint1 <- Complaint%>% filter(BORO_NM == "QUEENS")
# Displaying data
 formattable(head(Sub1))
OBJECTID URL NAME Long Lat
1734 http://web.mta.info/nyct/service/ Birchall Ave & Sagamore St at NW corner -73.86836 40.84917
1735 http://web.mta.info/nyct/service/ Birchall Ave & Sagamore St at NE corner -73.86821 40.84913
1736 http://web.mta.info/nyct/service/ Morris Park Ave & 180th St at NW corner -73.87350 40.84122
1737 http://web.mta.info/nyct/service/ Morris Park Ave & 180th St at NW corner -73.87289 40.84145
1738 http://web.mta.info/nyct/service/ Boston Rd & 178th St at SW corner -73.87962 40.84081
1739 http://web.mta.info/nyct/service/ Boston Rd & E Tremont Ave at NW corner -73.88000 40.84043
 formattable(head(Complaint1))
CMPLNT_NUM ADDR_PCT_CD BORO_NM CMPLNT_FR_DT CMPLNT_FR_TM CMPLNT_TO_DT CMPLNT_TO_TM CRM_ATPT_CPTD_CD HADEVELOPT HOUSING_PSA JURISDICTION_CODE JURIS_DESC KY_CD LAW_CAT_CD LOC_OF_OCCUR_DESC OFNS_DESC PARKS_NM PATROL_BORO PD_CD PD_DESC PREM_TYP_DESC RPT_DT STATION_NAME SUSP_AGE_GROUP SUSP_RACE SUSP_SEX TRANSIT_DISTRICT VIC_AGE_GROUP VIC_RACE VIC_SEX X_COORD_CD Y_COORD_CD Latitude Longitude Lat_Lon New.Georeferenced.Column
433883572 110 QUEENS 03/26/2021 13:09:00 03/26/2021 14:29:00 COMPLETED NA 0 N.Y. POLICE DEPT 113 FELONY INSIDE FORGERY PATROL BORO QUEENS NORTH 729 FORGERY,ETC.,UNCLASSIFIED-FELO SMALL MERCHANT 03/26/2021 NA UNKNOWN UNKNOWN D 1021552 212402 40.74960 -73.86537 (40.74960053300003, -73.86537333399998) POINT (-73.86537333399998 40.74960053300003)
588148056 115 QUEENS 03/24/2021 18:06:00 03/24/2021 18:10:00 COMPLETED NA 0 N.Y. POLICE DEPT 347 MISDEMEANOR INTOXICATED & IMPAIRED DRIVING PATROL BORO QUEENS NORTH 905 INTOXICATED DRIVING,ALCOHOL STREET 03/24/2021 NA 25-44 BLACK F 1020151 216992 40.76220 -73.87041 (40.762204702000076, -73.870405222) POINT (-73.870405222 40.762204702000076)
962571084 103 QUEENS 02/28/2021 15:00:00 COMPLETED NA 0 N.Y. POLICE DEPT 361 MISDEMEANOR OFF. AGNST PUB ORD SENSBLTY & PATROL BORO QUEENS SOUTH 661 LEWDNESS,PUBLIC STREET 03/07/2021 25-44 ASIAN / PACIFIC ISLANDER M NA 45-64 WHITE F 1051296 200867 40.71776 -73.75814 (40.71776441700007, -73.75813846299998) POINT (-73.75813846299998 40.71776441700007)
220983507 105 QUEENS 02/09/2021 09:00:00 02/09/2021 21:00:00 COMPLETED NA 0 N.Y. POLICE DEPT 341 MISDEMEANOR FRONT OF PETIT LARCENY PATROL BORO QUEENS SOUTH 339 LARCENY,PETIT FROM OPEN AREAS, RESIDENCE-HOUSE 02/15/2021 NA 25-44 WHITE HISPANIC F 1053310 202445 40.72208 -73.75086 (40.72208013800008, -73.75085696999997) POINT (-73.75085696999997 40.72208013800008)
843718333 105 QUEENS 08/12/2020 12:00:00 COMPLETED NA 0 N.Y. POLICE DEPT 341 MISDEMEANOR INSIDE PETIT LARCENY PATROL BORO QUEENS SOUTH 321 LARCENY,PETIT FROM AUTO RESIDENCE-HOUSE 02/10/2021 NA 65+ BLACK M 1055098 196593 40.70600 -73.74447 (40.70600372100006, -73.74446810899997) POINT (-73.74446810899997 40.70600372100006)
385446791 114 QUEENS 02/05/2021 18:50:00 COMPLETED NA 0 N.Y. POLICE DEPT 113 FELONY FORGERY PATROL BORO QUEENS NORTH 723 FORGERY,DRIVERS LICENSE STREET 02/05/2021 NA UNKNOWN UNKNOWN E 1003172 218076 40.76523 -73.93169 (40.76523264200006, -73.931693307) POINT (-73.931693307 40.76523264200006)
# Label information at: https://data.cityofnewyork.us/Public-Safety/NYPD-Complaint-Data-Current-Year-To-Date-/5uac-w243

Geo-plot:

Here the purple dots mark the position of subway exits, while the orange to yellow scale dots indicates the various locations of the complaints. The steady transition to that flow corresponds to the nature of the incident (here Felony to Violence).

The coloured marking features a great inference of how severe a crime has occurred and its distancing from public places (Subway Exits) which are generally crowded. It shows the spectrum of severity from the pivoted location combining with the time of the complaint registration. Narrating better chronology of incidents.

On Hover: Shows the time of the complaint.

On Click: Shows type of the complaint.

pal<- colorFactor(palette = c("#EB490C","#FAF311"),domain =  Complaint$LAW_CAT_CD)

leaflet(Complaint1)%>% 
        addProviderTiles(providers$Stamen.Toner)%>%
        setView(lng = -73.8532, lat = 40.7282, zoom = 10.5) %>% 
addCircles(lng =~Longitude,lat =~Latitude,color = ~pal(LAW_CAT_CD),opacity =0.3,popup = (~LAW_CAT_CD),label = ~CMPLNT_FR_TM,radius = 1)%>% 
addCircles(data = Sub1,lng=~Long,lat = ~Lat,color = "#8211FA",popup= ~NAME,radius = 1)

For further breakdown of code and data manipulation, refer this section:

Complaint<-read.csv("NYPD_Complaint.csv")

# Filtering the Queens section from main data:
Complaint1<-Complaint %>% filter(BORO_NM == "QUEENS")

Limiting the longitudinal scope of the subway stations to the Queens borough (as here data provides us with all stations in NYC).

Sub1<-Sub %>% filter(Long > -73.960457)

Here the Longitude provided acts as a numeric quantity possessing a negative value for the machine. Now as we move towards GMT, scales shift towards 00:00, but as NYC is behind GMT, we indicate it with a negative sign beforehand. Now if we want to discard the values behind the specific longitude (towards the left of the map), hence we employ the ‘greater’ sign to match the logic.

NOTE:

The data used here sources from: https://opendata.cityofnewyork.us/

The data was further refined in attempt to get the better results without hampering the accuracy.

For any queries or for acquiring pre-processed data please contact me at

Have a good day !