R Markdown

The following bar graphs highlight the count of police murders across race and gender, where male murders seem to in the highest amount, across all race types.

The point maps highlight the distribution of police murders across the country, in terms of gender and age. It seems the results across the country are consistent, where male murders in the age bracket of 30-35 are the most frequent across almost all of the US states.

library (tidyverse)
## Warning: package 'tidyverse' was built under R version 4.3.3
## Warning: package 'ggplot2' was built under R version 4.3.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(plotly)
## Warning: package 'plotly' was built under R version 4.3.3
## 
## Attaching package: 'plotly'
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout
fatal<- read.csv("C:/Users/Hina/Desktop/FATAL_ENCOUNTERS.csv")
library(stringr)

fatal %>%
  group_by(Gender, Race) %>%                # Group by Gender and Race
  tally(name = "n") %>%                     # Count rows and name the column 'n'
  mutate(p = n / sum(n)) %>%                # Calculate percentage for each group
  arrange(desc(Race)) %>%                   # Arrange data by Race
  ggplot(aes(x = Gender, y = p, fill = Race)) + # Create the ggplot
  geom_bar(stat = "identity", position = "stack") + # Create stacked bar chart
  geom_text(aes(label = str_c(round(p * 100, 1), "%")),  # Add text labels
            color = "white",
            position = position_stack(vjust = 0.3) ) +  # Position labels inside the bars
  labs(y = "Percentage", x = "Gender") +    # Labels for axes
  theme_minimal()       

ggplot(data = fatal) +
        geom_bar(mapping = aes(x=Gender, fill=Race), position = "stack")

library(viridis)
## Warning: package 'viridis' was built under R version 4.3.3
## Loading required package: viridisLite
library(sf)
## Linking to GEOS 3.11.2, GDAL 3.7.2, PROJ 9.3.0; sf_use_s2() is TRUE
class(fatal)
## [1] "data.frame"
sum(is.na(fatal$Longitude))
## [1] 1
sum(is.na(fatal$Latitude))
## [1] 0
fatal[is.na(fatal$Longitude) | is.na(fatal$Latitude), ]
##       Unique.ID                                       Name Age Gender Race
## 31498        NA This is a spacer for Fatal Encounters use.                
##       Race.with.imputations Imputation.probability
## 31498                                             
##       URL.of.image..PLS.NO.HOTLINKS.
## 31498                               
##       Date.of.injury.resulting.in.death..month.day.year.
## 31498                                         12/31/1999
##                         Location.of.injury..address. Location.of.death..city.
## 31498 This row is a spacer for Fatal Encounters use.                         
##       State Location.of.death..zip.code. Location.of.death..county.
## 31498                                 NA                           
##       Full.Address Latitude Longitude Agency.or.agencies.involved
## 31498                              NA                            
##       Highest.level.of.force UID.Temporary Name.Temporary Armed.Unarmed
## 31498                                   NA                             
##       Alleged.weapon Aggressive.physical.movement Fleeing.Not.fleeing
## 31498                                                                
##       Description.Temp URL.Temp Brief.description
## 31498                                            
##       Dispositions.Exclusions.INTERNAL.USE..NOT.FOR.ANALYSIS
## 31498                                                       
##       Intended.use.of.force..Developing. Supporting.document.link  X X.1
## 31498                                                             NA  NA
##       Unique.ID.formula Unique.identifier..redundant.
## 31498             31497                            NA
fatal <- fatal[!is.na(fatal$Longitude) & !is.na(fatal$Latitude), ]
fatal$Longitude <- as.numeric(as.character(fatal$Longitude))
fatal$Latitude <- as.numeric(as.character(fatal$Latitude))
## Warning: NAs introduced by coercion
fatal[!is.finite(fatal$Longitude), ]
##  [1] Unique.ID                                             
##  [2] Name                                                  
##  [3] Age                                                   
##  [4] Gender                                                
##  [5] Race                                                  
##  [6] Race.with.imputations                                 
##  [7] Imputation.probability                                
##  [8] URL.of.image..PLS.NO.HOTLINKS.                        
##  [9] Date.of.injury.resulting.in.death..month.day.year.    
## [10] Location.of.injury..address.                          
## [11] Location.of.death..city.                              
## [12] State                                                 
## [13] Location.of.death..zip.code.                          
## [14] Location.of.death..county.                            
## [15] Full.Address                                          
## [16] Latitude                                              
## [17] Longitude                                             
## [18] Agency.or.agencies.involved                           
## [19] Highest.level.of.force                                
## [20] UID.Temporary                                         
## [21] Name.Temporary                                        
## [22] Armed.Unarmed                                         
## [23] Alleged.weapon                                        
## [24] Aggressive.physical.movement                          
## [25] Fleeing.Not.fleeing                                   
## [26] Description.Temp                                      
## [27] URL.Temp                                              
## [28] Brief.description                                     
## [29] Dispositions.Exclusions.INTERNAL.USE..NOT.FOR.ANALYSIS
## [30] Intended.use.of.force..Developing.                    
## [31] Supporting.document.link                              
## [32] X                                                     
## [33] X.1                                                   
## [34] Unique.ID.formula                                     
## [35] Unique.identifier..redundant.                         
## <0 rows> (or 0-length row.names)
fatal[!is.finite(fatal$Latitude), ]
##      Unique.ID          Name Age Gender                    Race
## 2514     28891 Wildan Tmusic  22   Male European-American/White
##        Race.with.imputations Imputation.probability
## 2514 European-American/White            Not imputed
##                                                URL.of.image..PLS.NO.HOTLINKS.
## 2514 https://fatalencounters.org/wp-content/uploads/2020/10/Wildan-Tmusic.jpg
##      Date.of.injury.resulting.in.death..month.day.year.
## 2514                                         10/03/2020
##      Location.of.injury..address. Location.of.death..city. State
## 2514                         I-95                  Norwood    MA
##      Location.of.death..zip.code. Location.of.death..county.
## 2514                         2021                    Norfolk
##                       Full.Address Latitude Longitude
## 2514 I-95 Norwood MA 2021 Norfolk        NA -71.17373
##      Agency.or.agencies.involved Highest.level.of.force UID.Temporary
## 2514  Massachusetts State Police                Vehicle         28891
##      Name.Temporary Armed.Unarmed Alleged.weapon Aggressive.physical.movement
## 2514  Wildan Tmusic       Unarmed           None                         None
##      Fleeing.Not.fleeing Description.Temp URL.Temp
## 2514     Fleeing/Vehicle                          
##                                                                                                                                                                                                                                                                                                                Brief.description
## 2514 A trooper was attempting to stop a driver, Wildan Tmusic, for speeding just after 2:30 a.m. when the driver refused to stop and fled. The trooper was given the go-ahead to pursue the vehicle moments before it crashed.Tmusic was killed and passenger Adam J. Rodriguez later succumbed to his injuries in the hospital.
##      Dispositions.Exclusions.INTERNAL.USE..NOT.FOR.ANALYSIS
## 2514                                  Pending investigation
##      Intended.use.of.force..Developing.
## 2514                            Pursuit
##                                                                                                                              Supporting.document.link
## 2514 https://www.wcvb.com/article/second-victim-of-interstate-95-crash-in-norwood-conencted-to-pursuits-dies-massachusetts-state-police-say/34278934#
##       X X.1 Unique.ID.formula Unique.identifier..redundant.
## 2514 NA  NA                NA                         28891
fatal <- fatal[is.finite(fatal$Longitude) & is.finite(fatal$Latitude), ]

fatal_sf <- st_as_sf(fatal, coords = c("Longitude", "Latitude"), crs = 4326) 

ggplot(data = fatal_sf) +
  geom_point(aes(x = st_coordinates(geometry)[, 1], 
                 y = st_coordinates(geometry)[, 2], 
                 color = (Gender))) +
  labs(x = "Longitude", y = "Latitude", color = "Gender") +
  theme_minimal()

ggplot(data = fatal_sf) +
  geom_point(aes(x = st_coordinates(geometry)[, 1], 
                 y = st_coordinates(geometry)[, 2], 
                 color = (Age))) +
  labs(x = "Longitude", y = "Latitude", color = "Age") +
  theme_minimal()

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.