# Import .csv downloaded from https://docs.google.com/spreadsheets/d/1dKmaV_JiWcG8XBoRgP8b4e9Eopkpgt7FL7nyspvzAsE/edit#gid=0
library(readr)
fatal_raw <- read_csv("FATAL ENCOUNTERS DOT ORG SPREADSHEET (See Read me tab) - Form Responses.csv")
## New names:
## • `` -> `...33`
## • `` -> `...34`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
## Rows: 31498 Columns: 36
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (28): Name, Gender, Race, Race with imputations, Imputation probability,...
## dbl  (6): Unique ID, Age, Longitude, UID Temporary, Unique ID formula, Uniqu...
## lgl  (2): ...33, ...34
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# head(fatal_raw)
# Load libraries
library(sf)
library(tmap)
library(jsonlite)
library(tidyverse)
library(httr)
library(jsonlite)
library(reshape2)
library(here)
library(knitr)
library(tigris)
# Since I come from China (race-Asian), I want to know about cases where Asians were subjectives
# Have a glimpse about column "Race" -- 
table(fatal_raw$Race)
## 
##                                    African-American/Black 
##                                                      7008 
## African-American/Black African-American/Black Not imputed 
##                                                         4 
##                                    Asian/Pacific Islander 
##                                                       485 
##                             Christopher Anthony Alexander 
##                                                         1 
##                 European-American/European-American/White 
##                                                        37 
##                                   european-American/White 
##                                                         1 
##                                   European-American/White 
##                                                     10614 
##                                           Hispanic/Latino 
##                                                      4192 
##                                            Middle Eastern 
##                                                        53 
##                                   Native American/Alaskan 
##                                                       323 
##                                          Race unspecified 
##                                                      8779
# There are 485 cases identified as "Asian/Pacific Islander" related.
# Create an "Asian/Pacific Islander" subset and convert some undesirable column-datatypes 

fatal_asian <- fatal_raw %>% filter(Race=='Asian/Pacific Islander') %>%
  select(c(1:19)) %>% 
  mutate_at('Latitude', as.numeric) %>% 
  mutate_at('Date of injury resulting in death (month/day/year)', 
            ~ as.Date(., format="%m/%d/%Y")) %>% 
  rename_with(make.names)
# Check datatypes
glimpse(fatal_asian)
## Rows: 485
## Columns: 19
## $ Unique.ID                                          <dbl> 31325, 31128, 31139…
## $ Name                                               <chr> "John \"Amoo\" Za M…
## $ Age                                                <dbl> 28, 28, 33, 24, 43,…
## $ Gender                                             <chr> "Male", "Male", "Fe…
## $ Race                                               <chr> "Asian/Pacific Isla…
## $ Race.with.imputations                              <chr> "Asian/Pacific Isla…
## $ Imputation.probability                             <chr> "Not imputed", "Not…
## $ URL.of.image..PLS.NO.HOTLINKS.                     <chr> "https://fatalencou…
## $ Date.of.injury.resulting.in.death..month.day.year. <date> 2021-12-10, 2021-1…
## $ Location.of.injury..address.                       <chr> "Shady Lane Avenue"…
## $ Location.of.death..city.                           <chr> "Pine River", "Vanc…
## $ State                                              <chr> "WI", "WA", "UT", "…
## $ Location.of.death..zip.code.                       <chr> "54452", "98682", "…
## $ Location.of.death..county.                         <chr> "Lincoln", "Clark",…
## $ Full.Address                                       <chr> "Shady Lane Avenue …
## $ Latitude                                           <dbl> 45.13805, 45.65727,…
## $ Longitude                                          <dbl> -89.59039, -122.547…
## $ Agency.or.agencies.involved                        <chr> "Lincoln County She…
## $ Highest.level.of.force                             <chr> "Gunshot", "Gunshot…
# Convert fatal_asian into a sf object for location mapping
fatal_asian_sf <- fatal_asian %>% 
  st_as_sf(coords=c("Longitude", "Latitude"), crs = 4326)
library(leaflet)
library(htmlwidgets)
library(htmltools)

# CSS for title
tag.map.title <- tags$style(HTML("
  .leaflet-control.map_title { 
    position: absolute;
    left: 50px;
    width: 320px;
    text-align: left;
    color: orange;
    padding-left: 10px; 
    background: rgba(20,20,20,0.2);
    font-weight: bold;
    font-size: 20px;
    font-family: Helvetica;
    border-color: white;
    border-radius: 10px;
  }"))

# Format title
title <- tags$div(
  class="map_title", tag.map.title, HTML("<p>Fatal Encounters - Asian/Pacific Islander</p>")
)  

# Label for mouseover & popup
labels <- paste(
  "<strong>Date: </strong>", fatal_asian$Date.of.injury.resulting.in.death..month.day.year.,"<br>",
  "<strong>Age: </strong>", fatal_asian$Age,"<br>",
  "<strong>Agency Involved: </strong>", fatal_asian$Agency.or.agencies.involved,"<br>",
  "<strong>Highest Force: </strong>", fatal_asian$Highest.level.of.force) %>%
  lapply(htmltools::HTML)

factpal <- colorFactor(topo.colors(2), fatal_asian$Gender)

states <- states(cb = T) 
## Retrieving data for the year 2021
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |=                                                                     |   1%
  |                                                                            
  |=                                                                     |   2%
  |                                                                            
  |==                                                                    |   3%
  |                                                                            
  |===                                                                   |   4%
  |                                                                            
  |===                                                                   |   5%
  |                                                                            
  |====                                                                  |   5%
  |                                                                            
  |====                                                                  |   6%
  |                                                                            
  |=======                                                               |   9%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |========                                                              |  11%
  |                                                                            
  |========                                                              |  12%
  |                                                                            
  |=========                                                             |  12%
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |==========                                                            |  14%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |============                                                          |  18%
  |                                                                            
  |=============                                                         |  18%
  |                                                                            
  |=============                                                         |  19%
  |                                                                            
  |===============                                                       |  22%
  |                                                                            
  |================                                                      |  23%
  |                                                                            
  |================                                                      |  24%
  |                                                                            
  |=================                                                     |  24%
  |                                                                            
  |=================                                                     |  25%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |=========================                                             |  36%
  |                                                                            
  |==========================                                            |  37%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |=============================                                         |  42%
  |                                                                            
  |==============================                                        |  43%
  |                                                                            
  |================================                                      |  46%
  |                                                                            
  |=================================                                     |  47%
  |                                                                            
  |=================================                                     |  48%
  |                                                                            
  |==================================                                    |  48%
  |                                                                            
  |==================================                                    |  49%
  |                                                                            
  |===================================                                   |  51%
  |                                                                            
  |=========================================                             |  59%
  |                                                                            
  |==============================================                        |  66%
  |                                                                            
  |===============================================                       |  68%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |==================================================                    |  72%
  |                                                                            
  |===================================================                   |  72%
  |                                                                            
  |======================================================                |  78%
  |                                                                            
  |=======================================================               |  78%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |===========================================================           |  85%
  |                                                                            
  |=============================================================         |  87%
  |                                                                            
  |==============================================================        |  88%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |================================================================      |  91%
  |                                                                            
  |================================================================      |  92%
  |                                                                            
  |=================================================================     |  92%
  |                                                                            
  |=================================================================     |  93%
  |                                                                            
  |==================================================================    |  94%
  |                                                                            
  |==================================================================    |  95%
  |                                                                            
  |===================================================================   |  95%
  |                                                                            
  |======================================================================| 100%
st_crs(states) <- 4326
## Warning: st_crs<- : replacing crs does not reproject data; use st_transform for
## that
leaflet(states) %>%
  addProviderTiles("CartoDB.Positron") %>%
  addPolygons(fillColor = "white",
              color = "black",
              weight = 1) %>%
  
  # Yelp point
  addCircleMarkers(data = fatal_asian_sf,
                   fillColor= ~factpal(Gender),
                   weight=1,
                   color= ~factpal(Gender),
                   popup= ~labels,
                   label= ~labels) %>% 
  
  # Legend
  addLegend("bottomright", pal = factpal, values = fatal_asian$Gender, title = "Gender", opacity = 1) %>% 
  
  # Title
  addControl(title, position="topleft",className="map_title") %>% 
  setView(-98.5795, 39.8282, zoom=3)

Cases are more densed on north-eastern and south-western coast of the US. Also, the number of cases in mid-east inland are more than the number recorded in mid-west inland. A possibile explanation can be Asian people are mostly living in these areas.

# Conduct a temporal analysis
# Extract year from date
fatal_asian <- fatal_asian %>%
  mutate(Year = year(Date.of.injury.resulting.in.death..month.day.year.))
# Count cases in each year
ggplot(data = fatal_asian) + 
  geom_bar(mapping = aes(x=Year, fill=Gender), position = "stack") +
  labs(x = "Year", 
       y = "No. Fatal Records", 
       title = "Annual Number of Fatal Encounters(Asian/Pacific Islander)")

The recorded cases showing an increasing trend over the past 2 decades. This can because the data are more and more transparent available, or because the cases are actually increasing. And more males were killed than females.