-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCPD_Gang_Arrests.Rmd
116 lines (74 loc) · 4.43 KB
/
CPD_Gang_Arrests.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
---
title: "Mapping the CPD Gang Database"
author: "Princess Ojiaku"
date: "8/26/2018"
output: html_document
---
I obtained the Chicago Police Department's gang database from [ProPublica](https://www.propublica.org/article/politic-il-insider-chicago-gang-database). It's a dataset of CPD-classified as gang members. However, it was found to be full of errors and inaccuracies, including outdated information like gang members who are still active at the ripe old age of 132.
I made this gang database into a choropleth map of Chicago, which displays shading based on the number of individuals classified as gang members in each of Chicago's police beats.
This map provides an accessible way to display how many people were put into the database and the police beat under which they were classified.
Note: I've used "Number of Arrests" as a shorthand for how individuals were classified as gang members, although it is possible that they have have been classified by other means than arrest. The data used in the map only indicates the date that the person was entered into the gang database and associated with a particular police beat, not whether or not they were arrested.
```{r setup, include=FALSE, warning=FALSE, error=FALSE}
library(readxl)
library(tidyverse)
library(sf)
library(leaflet)
library(viridis)
library(dplyr)
knitr::opts_chunk$set(echo = TRUE)
```
## Read in the CPD Gang Database & police beat shape file
This reads in our data that includes the suspected gang member arrest data, police beat in which the arrest occured, the gang affliation, and the age and race of the suspect. The data goes from March 1999 -- March 2018.
Then we read in the shapefile of the CPD police beats, so we can map them.
```{r read in data, include=T, warning=F, error=F}
df_gang_318 <- read_excel("CPD Gang Data/CPD gang database 3-18.xlsx", sheet=1)
# I downloaded the Chicago Police Beats Shapefile from the Chicago data portal
map_filepath <- "Boundaries_Police Beats/geo_export_CPD_BEATS.shp"
cpd_beats <- st_read(map_filepath)
#cleaning the data -- take out any rows with NA for a police beat since we can't map those
df_gangs <- filter(df_gang_318, !is.na(O_BEAT))
cpd_beats <- filter(cpd_beats, !is.na(beat_num))
```
#Taking a quick look at the Police beats shapefile
This preliminary map includes a popup of the police beat.
```{r quick view of police beats, warning=F, error=F}
#this is just a quick map to map the police beats
cpd_beats %>%
leaflet() %>%
addTiles() %>%
addPolygons(popup=~beat_num)
```
#Joining the dataframes and creating a new summary for the map
After joining the dataframes, I created a new dataframe from it with a summary of the number of arrests per police beat (num_arrests).
```{r join data, warning=FALSE, error=FALSE}
# it looks like df_gangs needs a padded 0 in front of some of the numbers to make them 4 digits instead of 3. So let's clean that up before we join it with cpd_beats (which is all 4 digits)
df_gangs$O_BEAT <- str_pad(df_gangs$O_BEAT, 4, pad = "0")
#inner join the two data frames. Used an inner join to drop any rows where the two police beat numbers didn't match up
cpd_beats_gangs<- inner_join(cpd_beats, df_gangs, by=c('beat_num'='O_BEAT'))
#get the number of arrests per police beat and create a new data frame (CPD_gang_map2) with just that info
CPD_gang_map2 <- cpd_beats_gangs %>%
group_by(beat_num) %>%
summarize(num_arrests=n())
```
## Ploting the CPD data
Darker blue areas indicate more gang classifications. Select the community area to view a popup of the police beat and the number of arrests.
```{r cpd beats, warning=FALSE, error=FALSE}
#set the color pallette as Blues.
col_pal <- colorNumeric("Blues", domain=CPD_gang_map2$num_arrests)
#Add the pop-up text with Police Beat and Number of Arrests in that area
popup_sb <- paste0("Police Beat: ", as.character(CPD_gang_map2$beat_num), "<br>Number of arrests: ", as.character(CPD_gang_map2$num_arrests))
# yaassss the following leaflet worked!
leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
setView(-87.628598, 41.855372, zoom = 10) %>%
addPolygons(data = CPD_gang_map2,
fillColor = ~col_pal(CPD_gang_map2$num_arrests),
fillOpacity = 0.7,
weight = 0.2,
smoothFactor = 0.2,
popup = ~popup_sb) %>%
addLegend(pal = col_pal,
values = CPD_gang_map2$num_arrests,
position = "bottomright",
title = "Number of Arrests")
```