The data set used to create the visualization on this page was the Philly shooting data set. This data set has 15577 observations of 25 different variables. Missing variables were removed from the data set. The final data set has 15303 observations of 25 different variables.
shootings2 <- read.csv(file="https://isarenn.github.io/irennenberg/Week8/shootings.csv") #reading in the dataset from githbub
## Define objects with geo-coordinate system to plot specific information
race = st_as_sf(data.frame(x = -75.3677, y = 39.9168),
coords = c("x", "y"),
crs = 4326)
gender = st_as_sf(data.frame(x = -75.3477, y = 39.9168),
coords = c("x", "y"),
crs = 4326)
fatal = st_as_sf(data.frame(x = -75.3877, y = 39.9168),
coords = c("x", "y"),
crs = 4326)
shootings <- shootings2[complete.cases(shootings2),]
Below is the interactive map that aggregates/collapses information over the entirety of the city of Philadelphia. Circles are shown as red if the shooting was nonfatal, and blue if the shooting was fatal.
img1<-"https://isarenn.github.io/irennenberg/Week8/Gender.jpeg"
img2<-"https://isarenn.github.io/irennenberg/Week8/Race.jpeg"
img3<-"https://isarenn.github.io/irennenberg/Week8/Fatal.jpeg"
pal <- colorFactor(c("red", "blue"), domain = c("0", "1"))
Map1<-leaflet(shootings) %>%
setView(lng=-75.15092, lat=40.00995, zoom = 11) %>%
addProviderTiles(providers$CartoDB.Positron, group="Positron") %>%
addProviderTiles(providers$CartoDB.PositronNoLabels, group="PositronLabels") %>%
addProviderTiles(providers$Esri.NatGeoWorldMap, group="Esri") %>%
addMiniMap() %>%
## neighborhood boundary
addPolygons(data = phillyNeighbor,
color = 'lightpink',
weight = 2) %>%
## plot information on the map
addCircleMarkers(data = shootings,
radius = ~ifelse(fatal == "1", 5, 3),
color = ~pal(fatal),
stroke = FALSE,
fillOpacity = 0.5,
popup = ~popupTable(shootings),
clusterOptions = markerClusterOptions(maxClusterRadius = 40)) %>%
addLayersControl(baseGroups = c('Positron', 'PositronLabel', 'Esri'),
overlayGroups = c("Shootings Data"),
options = layersControlOptions(collapsed = TRUE)) %>%
addCircleMarkers(data = gender,
color = "blue",
weight = 2,
label = "Gender",
stroke = FALSE,
fillOpacity = 0.95,
group = "gender") %>%
addPopupImages(img1,
width = 300,
height = 300,
tooltip = FALSE,
group = "gender") %>%
addCircleMarkers(data = race,
color = "purple",
weight = 2,
label = "Race",
stroke = FALSE,
fillOpacity = 0.95,
group = "race") %>%
addPopupImages(img2,
width = 300,
height = 300,
tooltip = FALSE,
group = "race") %>%
addCircleMarkers(data = fatal,
color = "lightblue",
weight = 2,
label = "Fatality",
stroke = FALSE,
fillOpacity = 0.95,
group = "fatal") %>%
addPopupImages(img3,
width = 300,
height = 300,
tooltip = FALSE,
group = "fatal")
title<-tags$div(HTML('<font color = "purple" size =4><b>Philadelphia Shootings By Borough</b></font>'))
Map2<-Map1 %>%
addControl(title, position="topleft")
Map2