Philly Shooting Data
Reference Map
phillyNeighbor <- st_read("https://pengdsci.github.io/STA553VIZ/w08/Neighborhoods_Philadelphia.geojson")
Reading layer `Neighborhoods_Philadelphia' from data source
`https://pengdsci.github.io/STA553VIZ/w08/Neighborhoods_Philadelphia.geojson'
using driver `GeoJSON'
Simple feature collection with 158 features and 8 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -75.28027 ymin: 39.867 xmax: -74.95576 ymax: 40.13799
Geodetic CRS: WGS 84
phillyNeighborShooting <- na.omit(st_read("https://pengdsci.github.io/STA553VIZ/w08/PhillyShootings.geojson"))
Reading layer `PhillyShootings' from data source
`https://pengdsci.github.io/STA553VIZ/w08/PhillyShootings.geojson'
using driver `GeoJSON'
replacing null geometries with empty geometries
Simple feature collection with 15555 features and 21 fields (with 29 geometries empty)
Geometry type: POINT
Dimension: XY
Bounding box: xmin: -75.27362 ymin: 39.87799 xmax: -74.95936 ymax: 40.13117
Geodetic CRS: WGS 84
##map title
title <- tags$div(
HTML('<img border="0" alt="ImageTitle" src="https://raw.githubusercontent.com/azheneghan/aheneghan/main/images/phillyShootTitle.png" width="200" height="45">')
)
## color palette
pal <- colorFactor(c("#DC267F", "blue"), domain = c("1", "0"))
## Define objects with geo-coordinate system to plot specific information
pnt = st_as_sf(data.frame(x = -75.1256, y = 40.0063),
coords = c("x", "y"),
crs = 4326)
mortal = st_as_sf(data.frame(x = -75.3277, y = 39.9168),
coords = c("x", "y"),
crs = 4326)
## Images to be plot on the map
hospital = "https://raw.githubusercontent.com/azheneghan/aheneghan/main/images/phillyHospital.jpg"
fatalTrend = "https://raw.githubusercontent.com/azheneghan/aheneghan/main/images/TotalPhillyShootingsbyYear.png"
##################################################
leaflet() %>%
setView(lng=-75.15092, lat=40.00995, zoom = 11) %>%
addProviderTiles(providers$CartoDB.DarkMatter, group="Dark") %>%
addProviderTiles(providers$CartoDB.DarkMatterNoLabels, group="DarkLabel") %>%
addProviderTiles(providers$Esri.NatGeoWorldMap, group="Esri") %>%
addControl(title, position = "topleft", className="map-title") %>%
## mini reference map
addMiniMap() %>%
## neighborhood boundary
addPolygons(data = phillyNeighbor,
color = 'skyblue',
weight = 1) %>%
## plot information on the map
addCircleMarkers(data = phillyNeighborShooting,
radius = ~ifelse(fatal == "1", 5, 3),
color = ~pal(fatal),
stroke = FALSE,
fillOpacity = 0.5,
popup = ~popupTable(phillyNeighborShooting),
clusterOptions = markerClusterOptions(maxClusterRadius = 40)) %>%
# Adding the image of city hall
addCircleMarkers(data = pnt,
color = "blue",
weight = 2,
label = "St. Christopher's Hospital for Children",
stroke = FALSE,
fillOpacity = 0.95,
group = "pnt") %>%
addPopupImages(hospital,
width = 100,
height = 120,
tooltip = FALSE,
group = "pnt") %>%
# Trend of crimes over the years
addCircleMarkers(data = mortal,
color = "purple",
weight = 2,
label = "Trend",
stroke = FALSE,
fillOpacity = 0.95,
group = "mortal") %>%
addPopupImages(fatalTrend,
width = 500,
height = 350,
tooltip = FALSE,
group = "mortal") %>%
addLayersControl(baseGroups = c('Dark', 'DarkLabel', 'Esri'),
overlayGroups = c("Crime Data"),
options = layersControlOptions(collapsed = TRUE)) %>%
browsable()