police-violence

A look at the data from Mapping Police Violence.
git clone https://git.eamoncaddigan.net/police-violence.git
Log | Files | Refs | README | LICENSE

police-violence.Rmd (2819B)


      1 ---
      2 title: "Mapping Police Violence"
      3 author: "Eamon Caddigan"
      4 date: "December 21, 2015"
      5 output: html_document
      6 ---
      7 
      8 [Mapping Police Violence](http://mappingpoliceviolence.org/) just released [their 2015 Police Violence Report](http://mappingpoliceviolence.org/2015/), along with the data supporting it. 
      9 
     10 One of the most stunning conclusions of the original report is the finding that community violence does not predict police violence. This disproves a common narrative that police are simply responding to violence in kind, and suggests that department policy plays a role in police behavior. 
     11 
     12 Here I take a stab at recreating the graph that accompanies the report. It plots community and police violence in the figure, with separate Y-axes for the factors.
     13 
     14 ```{r}
     15 library(readxl)
     16 library(dplyr)
     17 library(tidyr)
     18 library(ggplot2)
     19 library(gtable)
     20 library(grid)
     21 
     22 mpvReport <- read_excel("MPVDatasetDownload-83zj.xlsx", sheet = 2) 
     23 
     24 mpvReport <- mpvReport %>%
     25   mutate(`Police Department` = sub("^[^[:alpha:]]*", "", `Police Department`),
     26          row_number = 1:nrow(.)) %>% 
     27   filter(row_number <= 60)
     28 
     29 # From https://rpubs.com/kohske/dual_axis_in_ggplot2
     30 p1 <- ggplot(mpvReport, aes(x = row_number, 
     31                             y = `Rate of Police Killings per Million Population`)) + 
     32   geom_bar(color = "black", fill = "white", stat = "identity") +
     33   geom_point(size = 3) +
     34   theme_classic() %+replace%
     35   theme(axis.text.x=element_text(angle = 90, hjust = 1)) +
     36   scale_x_continuous(name = "",
     37                      limits = c(0.5, 60.5),
     38                      breaks = 1:60,
     39                      labels = mpvReport$`Police Department`)
     40 p2 <- ggplot(mpvReport, aes(x = row_number,
     41                             y = `Violent Crime per 1,000 residents`)) +
     42   geom_point(color = "blue", shape = 8) +
     43   theme_classic() %+replace%
     44   theme(panel.background = element_rect(fill = NA),
     45         axis.text.x=element_text(angle = 90, hjust = 1)) +
     46   scale_x_continuous(name = "",
     47                      limits = c(0.5, 60.5),
     48                      breaks = 1:60,
     49                      labels = mpvReport$`Police Department`)
     50 
     51 # extract gtable
     52 g1 <- ggplot_gtable(ggplot_build(p1))
     53 g2 <- ggplot_gtable(ggplot_build(p2))
     54 
     55 # overlap the panel of 2nd plot on that of 1st plot
     56 pp <- c(subset(g1$layout, name == "panel", se = t:r))
     57 g <- gtable_add_grob(g1, g2$grobs[[which(g2$layout$name == "panel")]], pp$t, 
     58                      pp$l, pp$b, pp$l)
     59 
     60 # axis tweaks
     61 ia <- which(g2$layout$name == "axis-l")
     62 ga <- g2$grobs[[ia]]
     63 ax <- ga$children[[2]]
     64 ax$widths <- rev(ax$widths)
     65 ax$grobs <- rev(ax$grobs)
     66 ax$grobs[[1]]$x <- ax$grobs[[1]]$x - unit(1, "npc") + unit(0.15, "cm")
     67 g <- gtable_add_cols(g, g2$widths[g2$layout[ia, ]$l], length(g$widths) - 1)
     68 g <- gtable_add_grob(g, ax, pp$t, length(g$widths) - 1, pp$b)
     69 
     70 # draw it
     71 grid.draw(g)
     72 ```
     73