Earlier this week, The New York Times, published an article titled “Who stops a ‘Bad Guy With a Gun’?” https://www.nytimes.com/interactive/2022/06/22/us/shootings-police-response-uvalde-buffalo.html

The article featured a Sankey diagram showing the outcomes of 433 active shooting attacks.

The {vtree} package can display data like this.

library(vtree)

First, let’s build a data frame with the data from the NYT.

gun <- build.data.frame(
  c("ended","who","what","bystander"),
  list("before the police arrived","The attacker","left the scene",NA,113),
  list("before the police arrived","The attacker","died by suicide",NA,72),
  list("before the police arrived","A bystander","subdued the attacker",NA,42),
  list("before the police arrived","A bystander","shot the attacker","citizen",12),
  list("before the police arrived","A bystander","shot the attacker","security guard",7),
  list("before the police arrived","A bystander","shot the attacker","off-duty officer",3),
  list("after the police arrived","The police","shot the attacker",NA,98),
  list("after the police arrived","The police","subdued the attacker",NA,33),
  list("after the police arrived","The attacker","died by suicide",NA,38),
  list("after the police arrived","The attacker","surrendered",NA,15)) 

# Specify the order of values
gun$ended <- factor(gun$ended,
  c("before the police arrived","after the police arrived"))
gun$who <- factor(gun$who,
  c("The police","The attacker","A bystander"))
gun$what <- factor(gun$what,
  c("left the scene","died by suicide","surrendered","subdued the attacker","shot the attacker"))
gun$bystander <- factor(gun$bystander,
  c("citizen","security guard","off-duty officer"))

Next, let’s use vtree to display the data. (Note that the order in one of the branches is slightly different.)

vtree(gun,"ended who what bystander",
  fillcolor="goldenrod1",rootfillcolor="goldenrod1",title="Active shooting attacks",
  follow=list(what="shot the attacker"),
  tprunebelow=list(list(
   ended="after the police arrived",
    who="The police",
    what="shot the attacker")),    
  labelvar=c(ended="When did attacks end?",bystander="The bystander was a"),
  vsplitwidth=Inf)

A convenient feature of vtree is the ability to produce a legend with marginal totals for each variable. (I have omitted the bystander breakdown.)

vtree(gun,"ended who what",fillcolor="goldenrod1",rootfillcolor="goldenrod1",title="Active shooting attacks",
  follow=list(what="shot the attacker"),
  labelvar=c(ended="When did attacks end?"),
  showlegend=TRUE,vsplitwidth=Inf)

It may also be useful to examine the data without taking into account the timing of police arrival:

vtree(gun,"who what",fillcolor="goldenrod1",rootfillcolor="goldenrod1",
  title="Active shooting attacks")

It is also interesting to change the order of “who” and “what”:

vtree(gun,"what who",fillcolor="goldenrod1",rootfillcolor="goldenrod1",title="Active shooting attacks",
  follow=list(what="shot the attacker"))