In order to visualize the spatial distribution of shootings in Philadelphia, PA, the City of Philadelphia Shooting Victim data as obtained from the Philadelphia Open Data project. This report includes a listing of city-wide shooting victims, including Police Officer-involved shootings, from 2015 - current day. In order to aggregate this data by neighborhood and or block, two GeoJSON files were read in for use respectively.
This data is available for public use at OpenPhillyData
str(philly_block)
Classes 'sf' and 'data.frame': 17555 obs. of 8 variables:
$ geoid : chr "421010041013000" "421010041013001" "421010041013002" "421010041013003" ...
$ cr_geoid : int 1254 1254 1254 1254 1254 1254 1254 1254 1254 1254 ...
$ name : chr "Greenwich" "Greenwich" "Greenwich" "Greenwich" ...
$ original_id : chr NA NA NA NA ...
$ pop100 : chr "120" "139" "145" "0" ...
$ hu100 : chr "53" "50" "53" "0" ...
$ state_place_fips: chr "4260000" "4260000" "4260000" "4260000" ...
$ geometry :sfc_MULTIPOLYGON of length 17555; first list element: List of 1
..$ :List of 1
.. ..$ : num [1:5, 1:2] -75.2 -75.2 -75.2 -75.2 -75.2 ...
..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg"
- attr(*, "sf_column")= chr "geometry"
- attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA
..- attr(*, "names")= chr [1:7] "geoid" "cr_geoid" "name" "original_id" ...
str(philly_neighbor)
Classes 'sf' and 'data.frame': 158 obs. of 9 variables:
$ name : chr "PENNYPACK_PARK" "OVERBROOK" "GERMANTOWN_SOUTHWEST" "EAST_PARKSIDE" ...
$ listname : chr "Pennypack Park" "Overbrook" "Germantown, Southwest" "East Parkside" ...
$ mapname : chr "Pennypack Park" "Overbrook" "Southwest Germantown" "East Parkside" ...
$ shape_leng: num 87084 57005 14881 10886 13042 ...
$ shape_area: num 60140756 76924995 14418666 4231000 6949968 ...
$ cartodb_id: int 9 138 59 129 49 6 17 47 50 44 ...
$ created_at: POSIXct, format: "2013-03-19 13:41:50" "2013-03-19 13:41:50" ...
$ updated_at: POSIXct, format: "2013-03-19 13:41:50" "2013-03-19 13:41:50" ...
$ geometry :sfc_MULTIPOLYGON of length 158; first list element: List of 1
..$ :List of 1
.. ..$ : num [1:1607, 1:2] -75.1 -75.1 -75.1 -75.1 -75.1 ...
..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg"
- attr(*, "sf_column")= chr "geometry"
- attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA
..- attr(*, "names")= chr [1:8] "name" "listname" "mapname" "shape_leng" ...
str(philly_shooting_raw)
Classes 'sf' and 'data.frame': 15277 obs. of 22 variables:
$ objectid : int 12728033 12728034 12728035 12728036 12728037 12728038 12728039 12728040 12728041 12728042 ...
$ year : int 2016 2016 2018 2020 2018 2019 2019 2019 2022 2016 ...
$ dc_key : chr "201615054780.0" "201615117555.0" "201815093657.0" "202015094989.0" ...
$ code : chr "400" "300" "400" "400" ...
$ date_ : POSIXct, format: "2016-06-06 20:00:00" "2016-12-03 19:00:00" ...
$ time : chr "12:15:00" "05:43:00" "21:02:00" "17:12:00" ...
$ race : chr "B" "B" "B" "B" ...
$ sex : chr "M" "M" "M" "M" ...
$ age : chr "19" "38" "31" "23" ...
$ wound : chr "Hand" "Chest" "Multiple" "Hand" ...
$ officer_involved : chr "N" "N" "N" "N" ...
$ offender_injured : chr "N" "N" "N" "N" ...
$ offender_deceased: chr "N" "N" "N" "N" ...
$ location : chr "4600 BLOCK Frankford Ave" "4600 BLOCK Frankford Ave" "4600 BLOCK Frankford Ave" "4600 BLOCK FRANKFORD AVE" ...
$ latino : int 0 0 0 0 0 1 1 0 0 0 ...
$ point_x : num -75.1 -75.1 -75.1 -75.1 -75.1 ...
$ point_y : num 40 40 40 40 40 ...
$ dist : chr "15" "15" "15" "15" ...
$ inside : int 0 0 0 0 0 0 0 0 0 0 ...
$ outside : int 1 1 1 1 1 1 1 1 1 1 ...
$ fatal : int 0 0 1 0 0 0 0 0 1 0 ...
$ geometry :sfc_POINT of length 15277; first list element: 'XY' num -75.1 40
- attr(*, "sf_column")= chr "geometry"
- attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
..- attr(*, "names")= chr [1:21] "objectid" "year" "dc_key" "code" ...
- attr(*, "na.action")= 'omit' Named int [1:278] 197 287 622 716 770 783 789 883 961 992 ...
..- attr(*, "names")= chr [1:278] "197" "287" "622" "716" ...
## Define a color palette
pal <- colorFactor(c("red", "gold"), domain = c(TRUE, FALSE))
The data was read in, and classifications updated to either logical or numeric as needed for improved analysis. Uneccessary columns (objectID, DC_Key, and Geometry) removed.
str(philly_shooting)
Classes 'sf' and 'data.frame': 15277 obs. of 20 variables:
$ year : int 2016 2016 2018 2020 2018 2019 2019 2019 2022 2016 ...
$ code : num 400 300 400 400 400 400 400 400 100 400 ...
$ date_ : POSIXct, format: "2016-06-06 20:00:00" "2016-12-03 19:00:00" ...
$ time : chr "12:15:00" "05:43:00" "21:02:00" "17:12:00" ...
$ race : chr "B" "B" "B" "B" ...
$ sex : chr "M" "M" "M" "M" ...
$ age : chr "19" "38" "31" "23" ...
$ wound : chr "Hand" "Chest" "Multiple" "Hand" ...
$ officer_involved : chr "N" "N" "N" "N" ...
$ offender_injured : chr "N" "N" "N" "N" ...
$ offender_deceased: chr "N" "N" "N" "N" ...
$ location : chr "4600 BLOCK Frankford Ave" "4600 BLOCK Frankford Ave" "4600 BLOCK Frankford Ave" "4600 BLOCK FRANKFORD AVE" ...
$ latino : logi FALSE FALSE FALSE FALSE FALSE TRUE ...
$ point_x : num -75.1 -75.1 -75.1 -75.1 -75.1 ...
$ point_y : num 40 40 40 40 40 ...
$ dist : chr "15" "15" "15" "15" ...
$ inside : logi FALSE FALSE FALSE FALSE FALSE FALSE ...
$ outside : logi TRUE TRUE TRUE TRUE TRUE TRUE ...
$ fatal : logi FALSE FALSE TRUE FALSE FALSE FALSE ...
$ geometry :sfc_POINT of length 15277; first list element: 'XY' num -75.1 40
- attr(*, "sf_column")= chr "geometry"
- attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
..- attr(*, "names")= chr [1:19] "year" "code" "date_" "time" ...
leaflet() %>%
setView(lng=-75.15092, lat=40.00995, zoom = 11) %>%
addProviderTiles(providers$CartoDB.DarkMatter, group = "Dark w/ Labels") %>%
addProviderTiles(providers$CartoDB.DarkMatterNoLabels, group = "Dark w/o Labels") %>%
addProviderTiles(providers$Esri.WorldGrayCanvas, group = "Gray") %>%
addLayersControl(baseGroups = c("Dark w/ Labels", "Dark w/o Labels", "Gray"),
options = layersControlOptions(collapsed = TRUE)) %>%
addControl(html = "<h5> Philadelphia Shooting Data<br>2015 - Current</h5>", position = "topleft", className = "map-title") %>%
addPolygons(data = philly_neighbor,
color = 'magenta',
fill= FALSE,
weight = 1) %>%
addMiniMap() %>%
addCircleMarkers(data = philly_shooting,
radius = ~ifelse(fatal == TRUE, 5, 3),
color = ~pal(fatal),
fillOpacity = 0.5,
popup = ~popupTable(philly_shooting),
clusterOptions = markerClusterOptions(maxClusterRadius = 50)) %>%
addCircleMarkers(data = Crime_totals,
color = "white",
weight = 2,
label = "Crime Totals by Classificaiton Code",
stroke = FALSE,
fillOpacity = 0.95,
group = "code") %>%
addPopupImages(code_graph_img,
width = 500,
height = 400,
tooltip = FALSE,
group = "code")