setwd("C:\\Users\\srini\\OneDrive\\Documents\\Urban Analytics")
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

Loading the Fatal Encounters Crime Dataset

fatal_encounters=read.csv(file="FatalEncountersData.csv")

View(fatal_encounters)

When analyzing fatal police encounters, I believe there are several key factors to consider, and over time, these recurring factors can reveal distinct patterns. The factors I find most critical for identifying and understanding these patterns across a dataset include gender, race, state, involved agency or agencies, and the highest level of force used. To begin, I will examine the most frequent values in each of these columns to determine if any clear patterns emerge.

most_common_gender=names(which.max(table(fatal_encounters$Gender)))
most_common_race=names(which.max(table(fatal_encounters$Race)))
most_common_state=names(which.max(table(fatal_encounters$State)))
most_common_agency=names(which.max(table(fatal_encounters$Agency.or.agencies.involved)))
most_common_level_of_force=names(which.max(table(fatal_encounters$Highest.level.of.force)))
print(most_common_gender)
## [1] "Male"
print(most_common_race)
## [1] "European-American/White"
print(most_common_state)
## [1] "CA"
print(most_common_agency)
## [1] "Los Angeles Police Department"
print(most_common_level_of_force)
## [1] "Gunshot"

The following graphs illustrate important trends observed in fatal police encounters. These visualizations highlight the distribution of gender, race, and geographic location of incidents, as well as the agencies involved and the most frequent levels of force used. These patterns provide insight into the demographics and circumstances surrounding these tragic events.

Plot 1: Most Common Gender in Fatal Encounters

library(ggplot2)
ggplot(fatal_encounters, aes(x = Gender)) +
  geom_bar() +
  ggtitle("Most Common Gender in Fatal Encounters") +
  xlab("Gender") + ylab("Count")

Plot 2: Race Distribution of Fatal Encounters

fatal_encounters_filtered = fatal_encounters %>%
  filter(Race != "Christopher Anthony Alexander")

ggplot(fatal_encounters_filtered, aes(x = Race)) +
  geom_bar() +
  ggtitle("Race Distribution in Fatal Encounters") +
  xlab("Race") + 
  ylab("Count") + 
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

Plot 3: Distribution of Fatal Encounters by State

library(ggplot2)
library(maps)

fatal_encounters$Longitude=as.numeric(fatal_encounters$Longitude)
fatal_encounters$Latitude=as.numeric(fatal_encounters$Latitude)
## Warning: NAs introduced by coercion
states_map=map_data("state")

ggplot(states_map, aes(x = long, y = lat)) +
  geom_polygon(fill = "white", color = "black") +
  

  geom_point(data = fatal_encounters, aes(x = Longitude, y = Latitude, color = State), size = 1) +
  
  
  ggtitle("Geographic Distribution of Fatal Encounters by State") +
  
  
  theme_minimal()
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).

Plot 4: Highest Level of Force Used

ggplot(fatal_encounters, aes(x = "", fill = Highest.level.of.force)) +
  geom_bar(width = 1) +
  coord_polar(theta = "y") +
  ggtitle("Distribution of Highest Level of Force Used") +
  theme_void()

In this dataset, the most frequently used level of force in fatal police encounters involves firearms. Therefore, I will be plotting the relation between the race and the number of gunshot related fatalities.