#Set up
fatal <- read.csv('fatal.csv')

#wanted to explore these variables at first
print(table(fatal$State))
## 
##        AK   AL   AR   AZ   CA   CO   CT   DC   DE   FL   GA   HI   IA   ID   IL 
##    1  129  700  391  914 4969  693  142   91   63 1894 1216  116  296  161 1117 
##   IN   KS   KY   LA   MA   MD   ME   MI   MN   MO   MS   MT   NC   ND   NE   NH 
##  609  428  437  655  215  553  109  903  366  945  446  116  673   43  217   66 
##   NJ   NM   NV   NY   OH   OK   OR   PA   RI   SC   SD   TN   TX   UT   VA   VT 
##  549  444  423  725 1022  721  358  992   32  620   61  695 2797  269  663   42 
##   WA   WI   WV   WY 
##  675  482  190   64
print(table(fatal$Highest.level.of.force))
## 
##                                              Asphyxiated/Restrained 
##                                 4                               347 
##             Asphyxiation/Restrain           Asphyxiation/Restrained 
##                                 1                                 2 
## Beaten/Bludgeoned with instrument           Burned/Smoke inhalation 
##                               182                                45 
##       Chemical agent/Pepper spray                           Drowned 
##                                35                               203 
##                     Drug overdose                Fell from a height 
##                               182                                82 
##                           Gunshot            Less-than-lethal force 
##                             22238                                 1 
##                 Medical emergency                             Other 
##                               397                                65 
##             Restrain/Asphyxiation                           Stabbed 
##                                 1                                52 
##                           Tasered                      Undetermined 
##                               936                               101 
##                           Vehicle 
##                              6624
print(table(fatal$Race))
## 
##                                                           
##                                                         1 
##                                    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
fatal <- fatal %>%
  mutate(Age = as.numeric(Age))
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `Age = as.numeric(Age)`.
## Caused by warning:
## ! NAs introduced by coercion
fatal_summary <- fatal %>%
  group_by(State) %>%
  summarise(
    avg_age = mean(Age, na.rm = TRUE),
    total_cases = n(),
    common_race = names(sort(table(Race), decreasing = TRUE))[1],
    common_force = names(sort(table(Highest.level.of.force), decreasing = TRUE))[1])


#explore
states_sf <- tigris::states(cb = TRUE) %>% 
  st_transform(crs = 4326)
## Retrieving data for the year 2024
##   |                                                                              |                                                                      |   0%  |                                                                              |                                                                      |   1%  |                                                                              |=                                                                     |   1%  |                                                                              |=                                                                     |   2%  |                                                                              |==                                                                    |   2%  |                                                                              |==                                                                    |   3%  |                                                                              |===                                                                   |   4%  |                                                                              |===                                                                   |   5%  |                                                                              |====                                                                  |   5%  |                                                                              |====                                                                  |   6%  |                                                                              |=====                                                                 |   6%  |                                                                              |=====                                                                 |   7%  |                                                                              |=====                                                                 |   8%  |                                                                              |======                                                                |   8%  |                                                                              |======                                                                |   9%  |                                                                              |=======                                                               |  10%  |                                                                              |=======                                                               |  11%  |                                                                              |========                                                              |  11%  |                                                                              |========                                                              |  12%  |                                                                              |=========                                                             |  13%  |                                                                              |==========                                                            |  14%  |                                                                              |==========                                                            |  15%  |                                                                              |===========                                                           |  15%  |                                                                              |===========                                                           |  16%  |                                                                              |============                                                          |  17%  |                                                                              |============                                                          |  18%  |                                                                              |=============                                                         |  18%  |                                                                              |=============                                                         |  19%  |                                                                              |==============                                                        |  20%  |                                                                              |==============                                                        |  21%  |                                                                              |===============                                                       |  21%  |                                                                              |===============                                                       |  22%  |                                                                              |================                                                      |  22%  |                                                                              |================                                                      |  23%  |                                                                              |=================                                                     |  24%  |                                                                              |=================                                                     |  25%  |                                                                              |==================                                                    |  25%  |                                                                              |==================                                                    |  26%  |                                                                              |===================                                                   |  27%  |                                                                              |===================                                                   |  28%  |                                                                              |====================                                                  |  28%  |                                                                              |====================                                                  |  29%  |                                                                              |=====================                                                 |  30%  |                                                                              |======================                                                |  31%  |                                                                              |======================                                                |  32%  |                                                                              |=======================                                               |  32%  |                                                                              |=======================                                               |  33%  |                                                                              |========================                                              |  34%  |                                                                              |========================                                              |  35%  |                                                                              |=========================                                             |  35%  |                                                                              |=========================                                             |  36%  |                                                                              |==========================                                            |  37%  |                                                                              |==========================                                            |  38%  |                                                                              |===========================                                           |  38%  |                                                                              |===========================                                           |  39%  |                                                                              |============================                                          |  39%  |                                                                              |============================                                          |  40%  |                                                                              |=============================                                         |  41%  |                                                                              |=============================                                         |  42%  |                                                                              |==============================                                        |  42%  |                                                                              |==============================                                        |  43%  |                                                                              |===============================                                       |  44%  |                                                                              |===============================                                       |  45%  |                                                                              |================================                                      |  45%  |                                                                              |================================                                      |  46%  |                                                                              |=================================                                     |  46%  |                                                                              |=================================                                     |  47%  |                                                                              |==================================                                    |  48%  |                                                                              |==================================                                    |  49%  |                                                                              |===================================                                   |  49%  |                                                                              |===================================                                   |  50%  |                                                                              |====================================                                  |  51%  |                                                                              |====================================                                  |  52%  |                                                                              |=====================================                                 |  52%  |                                                                              |=====================================                                 |  53%  |                                                                              |=====================================                                 |  54%  |                                                                              |======================================                                |  54%  |                                                                              |======================================                                |  55%  |                                                                              |=======================================                               |  55%  |                                                                              |=======================================                               |  56%  |                                                                              |========================================                              |  57%  |                                                                              |========================================                              |  58%  |                                                                              |=========================================                             |  58%  |                                                                              |=========================================                             |  59%  |                                                                              |==========================================                            |  60%  |                                                                              |==========================================                            |  61%  |                                                                              |===========================================                           |  61%  |                                                                              |===========================================                           |  62%  |                                                                              |============================================                          |  63%  |                                                                              |=============================================                         |  64%  |                                                                              |=============================================                         |  65%  |                                                                              |==============================================                        |  65%  |                                                                              |==============================================                        |  66%  |                                                                              |===============================================                       |  67%  |                                                                              |===============================================                       |  68%  |                                                                              |================================================                      |  68%  |                                                                              |================================================                      |  69%  |                                                                              |=================================================                     |  70%  |                                                                              |=================================================                     |  71%  |                                                                              |==================================================                    |  71%  |                                                                              |==================================================                    |  72%  |                                                                              |===================================================                   |  72%  |                                                                              |===================================================                   |  73%  |                                                                              |====================================================                  |  74%  |                                                                              |====================================================                  |  75%  |                                                                              |=====================================================                 |  75%  |                                                                              |=====================================================                 |  76%  |                                                                              |======================================================                |  77%  |                                                                              |======================================================                |  78%  |                                                                              |=======================================================               |  78%  |                                                                              |=======================================================               |  79%  |                                                                              |========================================================              |  80%  |                                                                              |=========================================================             |  81%  |                                                                              |=========================================================             |  82%  |                                                                              |==========================================================            |  82%  |                                                                              |==========================================================            |  83%  |                                                                              |===========================================================           |  84%  |                                                                              |===========================================================           |  85%  |                                                                              |============================================================          |  85%  |                                                                              |============================================================          |  86%  |                                                                              |=============================================================         |  87%  |                                                                              |=============================================================         |  88%  |                                                                              |==============================================================        |  88%  |                                                                              |==============================================================        |  89%  |                                                                              |===============================================================       |  89%  |                                                                              |===============================================================       |  90%  |                                                                              |================================================================      |  91%  |                                                                              |================================================================      |  92%  |                                                                              |=================================================================     |  92%  |                                                                              |=================================================================     |  93%  |                                                                              |==================================================================    |  94%  |                                                                              |==================================================================    |  95%  |                                                                              |===================================================================   |  95%  |                                                                              |===================================================================   |  96%  |                                                                              |====================================================================  |  97%  |                                                                              |===================================================================== |  98%  |                                                                              |===================================================================== |  99%  |                                                                              |======================================================================|  99%  |                                                                              |======================================================================| 100%
states_sf <- states_sf %>%
  left_join(fatal_summary, by = c("STUSPS" = "State"))

map1 <- tmap_mode("view")  
## ℹ tmap modes "plot" - "view"
## ℹ toggle with `tmap::ttm()`
## This message is displayed once per session.
tm_shape(states_sf) +
  tm_polygons(
    "total_cases",       
    palette = "Reds",
    style = "jenks",
    title = "Total Cases"
  ) +
  tm_layout(
    title = "Total Cases by State",
    legend.outside = FALSE
  )
## 
## ── tmap v3 code detected ───────────────────────────────────────────────────────
## [v3->v4] `tm_polygons()`: instead of `style = "jenks"`, use fill.scale =
## `tm_scale_intervals()`.
## ℹ Migrate the argument(s) 'style', 'palette' (rename to 'values') to
##   'tm_scale_intervals(<HERE>)'[v3->v4] `tm_polygons()`: migrate the argument(s) related to the legend of the
## visual variable `fill` namely 'title' to 'fill.legend = tm_legend(<HERE>)'[v3->v4] `tm_layout()`: use `tm_title()` instead of `tm_layout(title = )`[cols4all] color palettes: use palettes from the R package cols4all. Run
## `cols4all::c4a_gui()` to explore them. The old palette name "Reds" is named
## "brewer.reds"Multiple palettes called "reds" found: "brewer.reds", "matplotlib.reds". The first one, "brewer.reds", is returned.
map1.1 <- tmap_mode("view")  
## ℹ tmap modes "plot" - "view"
tm_shape(states_sf) +
  tm_polygons(
    "total_cases",       
    palette = "Reds",
    style = "quantile",
    title = "Total Cases"
  ) +
  tm_layout(
    title = "Total Cases by State",
    legend.outside = FALSE
  )
## 
## ── tmap v3 code detected ───────────────────────────────────────────────────────
## [v3->v4] `tm_polygons()`: instead of `style = "quantile"`, use fill.scale =
## `tm_scale_intervals()`.
## ℹ Migrate the argument(s) 'style', 'palette' (rename to 'values') to
##   'tm_scale_intervals(<HERE>)'[v3->v4] `tm_polygons()`: migrate the argument(s) related to the legend of the
## visual variable `fill` namely 'title' to 'fill.legend = tm_legend(<HERE>)'[v3->v4] `tm_layout()`: use `tm_title()` instead of `tm_layout(title = )`[cols4all] color palettes: use palettes from the R package cols4all. Run
## `cols4all::c4a_gui()` to explore them. The old palette name "Reds" is named
## "brewer.reds"Multiple palettes called "reds" found: "brewer.reds", "matplotlib.reds". The first one, "brewer.reds", is returned.
map2 <- tmap_mode("view")  
## ℹ tmap modes "plot" - "view"
tm_shape(states_sf) +
  tm_polygons(
    "avg_age",       
    palette = "Reds",
    style = "jenks",
    title = "Average Age"
  ) +
  tm_layout(
    title = "Average Age",
    legend.outside = FALSE
  )
## 
## ── tmap v3 code detected ───────────────────────────────────────────────────────
## [v3->v4] `tm_polygons()`: instead of `style = "jenks"`, use fill.scale =
## `tm_scale_intervals()`.
## ℹ Migrate the argument(s) 'style', 'palette' (rename to 'values') to
##   'tm_scale_intervals(<HERE>)'[v3->v4] `tm_polygons()`: migrate the argument(s) related to the legend of the
## visual variable `fill` namely 'title' to 'fill.legend = tm_legend(<HERE>)'[v3->v4] `tm_layout()`: use `tm_title()` instead of `tm_layout(title = )`[cols4all] color palettes: use palettes from the R package cols4all. Run
## `cols4all::c4a_gui()` to explore them. The old palette name "Reds" is named
## "brewer.reds"Multiple palettes called "reds" found: "brewer.reds", "matplotlib.reds". The first one, "brewer.reds", is returned.
print(map2)
## [1] "view"
#by intended use
fatal.2 <- read.csv('fatal.csv')

fatal.2 <- fatal.2 %>%
  select(State, Intended.use.of.force..Developing.) %>%
  group_by(State, Intended.use.of.force..Developing.) %>%
  summarise(total = n(), .groups = 'drop')

fatal.2 <- fatal.2 %>%
  filter(Intended.use.of.force..Developing. %in% c('Suicide', 'Deadly force', 'Pursuit', 'Less-than-lethal force'))

fatal.3 <- fatal.2 %>%
  filter(Intended.use.of.force..Developing. %in% c('Less-than-lethal force'))

states_sf.2 <- tigris::states(cb = TRUE) %>% 
  st_transform(crs = 4326)
## Retrieving data for the year 2024
states_sf.2 <- states_sf.2 %>%
  left_join(fatal.3, by = c("STUSPS" = "State"))


map1.4 <- tmap_mode("view")  
## ℹ tmap modes "plot" - "view"
tm_shape(states_sf.2) +
  tm_polygons(
    "total",       
    palette = "Reds",
    style = "jenks",
    title = "deadly force not intended"
  ) +
  tm_layout(
    title = "Total Cases of fatality by deadly force not intended by State",
    legend.outside = FALSE
  )
## 
## ── tmap v3 code detected ───────────────────────────────────────────────────────
## [v3->v4] `tm_polygons()`: instead of `style = "jenks"`, use fill.scale =
## `tm_scale_intervals()`.
## ℹ Migrate the argument(s) 'style', 'palette' (rename to 'values') to
##   'tm_scale_intervals(<HERE>)'[v3->v4] `tm_polygons()`: migrate the argument(s) related to the legend of the
## visual variable `fill` namely 'title' to 'fill.legend = tm_legend(<HERE>)'[v3->v4] `tm_layout()`: use `tm_title()` instead of `tm_layout(title = )`[cols4all] color palettes: use palettes from the R package cols4all. Run
## `cols4all::c4a_gui()` to explore them. The old palette name "Reds" is named
## "brewer.reds"Multiple palettes called "reds" found: "brewer.reds", "matplotlib.reds". The first one, "brewer.reds", is returned.
# I wanted to examine the others but when I facet wrapped them by state It was too big I think if I were going to do this it would be by the 4 types and then dots would be states and counts on the y axis

# the map is interesting because it shows that california nad texas are outliers again bc of tobbler's law. So exlcluding them, it would be interesting to further examine the states that have 25 - 115 values and explore this aspect. 

I wanted to look first at just what the state of the US was before deciding to anything further. What we see is that the average age is between 31 - 40 for fatalities. In terms of total cases, i first visualized it by quantile but didn’t like the range that I was given in my highest value (4969 - 725) which would be 4244 range – too big. So to get a better sense I changed them both to jenks which gives breaks by natural clusters. Now this map is much better in my opinion, we get a sense of where states are higher in fatalities. I think moving forward jenks is going to be preferred because I don’t think this data is evenly distributed.

To examine this more so I think a boxplot by state would be great to examine how these averages compare to the states overall. Beyond that, these visualizations suffer from tobbler’s law where big things are closely related. We see that states like california, texas, new york, philadelphia all have high levels likely due to their populations and size.


In this part I am going to divide the US into the Census regions to examine how the regions are in regards to fatalities.

fatal_region <- fatal_summary %>%
  mutate(region = case_when(
    State %in% c('FL','GA','NC','SC','VA','MD','WV','KY',
                 'AL','MS','TN','LA','OK','TX','AR', 'DC', 'DE') ~ 'South',
    State %in% c('CT','ME','MA','NH','RI','VT','NJ','NY','PA') ~ 'Northeast',
    State %in% c('IL','IN','MI','OH','WI','IA','KS','MO','NE','ND','SD','MN') ~ 'Midwest',
    State %in% c('AZ','CO','ID','MT','NV','NM','UT','WY','CA','OR','WA',"HI") ~ 'West'))

states_sf <- tigris::states(cb = TRUE) %>% 
  st_transform(crs = 4326)
## Retrieving data for the year 2024
states_sf <- states_sf %>%
  left_join(fatal_region, by = c("STUSPS" = "State"))

region_totals <- fatal_region %>%
  group_by(region) %>%
  summarise(total_cases_region = sum(total_cases, na.rm = TRUE))

states_sf <- states_sf %>%
  left_join(region_totals, by = "region")

# Plot
tmap_mode("view")  
## ℹ tmap modes "plot" - "view"
tm_shape(states_sf) +
  tm_polygons(
    "total_cases_region",
    palette = "Reds",
    style = "jenks",
    title = "Total Cases by Region") +
  tm_layout(
    title = "Total Cases by Region",
    legend.outside = TRUE)
## 
## ── tmap v3 code detected ───────────────────────────────────────────────────────
## [v3->v4] `tm_polygons()`: instead of `style = "jenks"`, use fill.scale =
## `tm_scale_intervals()`.
## ℹ Migrate the argument(s) 'style', 'palette' (rename to 'values') to
##   'tm_scale_intervals(<HERE>)'
## [v3->v4] `tm_polygons()`: migrate the argument(s) related to the legend of the
## visual variable `fill` namely 'title' to 'fill.legend = tm_legend(<HERE>)'
## [v3->v4] `tm_layout()`: use `tm_title()` instead of `tm_layout(title = )`
## [cols4all] color palettes: use palettes from the R package cols4all. Run
## `cols4all::c4a_gui()` to explore them. The old palette name "Reds" is named
## "brewer.reds"
## Multiple palettes called "reds" found: "brewer.reds", "matplotlib.reds". The first one, "brewer.reds", is returned.

From this map we see that the south east has a lot of cases with the west following and then finally the midwest. I thought it was interesting. the regions were determined by the Census.

So moving on, I found it hard to really handle the level of data. 31k observations is a lot. So, two things. I want to examine race and fatalities along with the highest use of force. For highest use of force, I’m thinking of doing a number for each variable, but restrain/asphyxiation has four variables spelled differently in past/present tense. So i’m first going to have to stringr them. Beyond exploring these two variable, I think I will explore solely GA and see what the state of GA is in terms of this data. Then compare it to Illinois and Florida because they had similar number of cases to GA

GA <- fatal %>%
  filter(State %in% "GA")

#finding the asphyixation cases and turning them into one variable
GA <- GA %>%
   mutate (
     type = if_else(str_detect(Highest.level.of.force, regex("^Asph", ignore_case = TRUE)),
                          "Asphyxiation",
                          Highest.level.of.force))

#Plotting first
bargraph <- ggplot(data = GA, aes(x = type)) +
  geom_bar(fill = 'blue', color = 'black') +
  labs(x = 'type of force', y = 'Number of Cases') +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
print(bargraph)

bxplot <- ggplot(data = GA) +
  geom_boxplot(aes(x = Highest.level.of.force, y = Age),
               color = 'black', fill ='white') +
  labs(title = 'Type of fatality compared to age', x = 'Fatality', y = 'Age') +
   theme(axis.text.x = element_text(angle = 45, hjust = 1))
print(bxplot)
## Warning: Removed 70 rows containing non-finite outside the scale range
## (`stat_boxplot()`).

# the boxplot shows us that gun violence is the predominate form of fatality across age. Bludgonening and stabbing are common for young people

#year 
GA <- GA %>%
  mutate(year = str_extract(Date.of.injury.resulting.in.death..month.day.year., "\\d{4}"))

bargraph2 <- ggplot(data = GA, aes(x = year)) +
  geom_bar(fill = 'blue', color = 'black') +
  labs(x = 'year', y = 'Number of Cases') +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
print(bargraph2)

# we see that there is a lot of fatalities reported in the later years compared to the earlier years. there are multiple reasons why this might happen. 


# Mapping
GA_sf <- GA %>%
  st_as_sf(coords = c('Longitude', 'Latitude'), crs = 4326)

ga_counties <- tigris::counties(state = "GA", cb = TRUE) %>%
  st_transform(crs = 4326)
## Retrieving data for the year 2024
##   |                                                                              |                                                                      |   0%  |                                                                              |                                                                      |   1%  |                                                                              |=                                                                     |   1%  |                                                                              |=                                                                     |   2%  |                                                                              |==                                                                    |   2%  |                                                                              |==                                                                    |   3%  |                                                                              |==                                                                    |   4%  |                                                                              |===                                                                   |   4%  |                                                                              |===                                                                   |   5%  |                                                                              |====                                                                  |   5%  |                                                                              |====                                                                  |   6%  |                                                                              |=====                                                                 |   6%  |                                                                              |=====                                                                 |   7%  |                                                                              |=====                                                                 |   8%  |                                                                              |======                                                                |   8%  |                                                                              |======                                                                |   9%  |                                                                              |=======                                                               |   9%  |                                                                              |=======                                                               |  10%  |                                                                              |=======                                                               |  11%  |                                                                              |========                                                              |  11%  |                                                                              |========                                                              |  12%  |                                                                              |=========                                                             |  12%  |                                                                              |=========                                                             |  13%  |                                                                              |=========                                                             |  14%  |                                                                              |==========                                                            |  14%  |                                                                              |==========                                                            |  15%  |                                                                              |===========                                                           |  15%  |                                                                              |===========                                                           |  16%  |                                                                              |============                                                          |  16%  |                                                                              |============                                                          |  17%  |                                                                              |============                                                          |  18%  |                                                                              |=============                                                         |  18%  |                                                                              |=============                                                         |  19%  |                                                                              |==============                                                        |  19%  |                                                                              |==============                                                        |  20%  |                                                                              |==============                                                        |  21%  |                                                                              |===============                                                       |  21%  |                                                                              |===============                                                       |  22%  |                                                                              |================                                                      |  22%  |                                                                              |================                                                      |  23%  |                                                                              |================                                                      |  24%  |                                                                              |=================                                                     |  24%  |                                                                              |=================                                                     |  25%  |                                                                              |==================                                                    |  25%  |                                                                              |==================                                                    |  26%  |                                                                              |===================                                                   |  26%  |                                                                              |===================                                                   |  27%  |                                                                              |===================                                                   |  28%  |                                                                              |====================                                                  |  28%  |                                                                              |====================                                                  |  29%  |                                                                              |=====================                                                 |  29%  |                                                                              |=====================                                                 |  30%  |                                                                              |=====================                                                 |  31%  |                                                                              |======================                                                |  31%  |                                                                              |======================                                                |  32%  |                                                                              |=======================                                               |  32%  |                                                                              |=======================                                               |  33%  |                                                                              |=======================                                               |  34%  |                                                                              |========================                                              |  34%  |                                                                              |========================                                              |  35%  |                                                                              |=========================                                             |  35%  |                                                                              |=========================                                             |  36%  |                                                                              |==========================                                            |  36%  |                                                                              |==========================                                            |  37%  |                                                                              |==========================                                            |  38%  |                                                                              |===========================                                           |  38%  |                                                                              |===========================                                           |  39%  |                                                                              |============================                                          |  39%  |                                                                              |============================                                          |  40%  |                                                                              |============================                                          |  41%  |                                                                              |=============================                                         |  41%  |                                                                              |=============================                                         |  42%  |                                                                              |==============================                                        |  42%  |                                                                              |==============================                                        |  43%  |                                                                              |==============================                                        |  44%  |                                                                              |===============================                                       |  44%  |                                                                              |===============================                                       |  45%  |                                                                              |================================                                      |  45%  |                                                                              |================================                                      |  46%  |                                                                              |=================================                                     |  46%  |                                                                              |=================================                                     |  47%  |                                                                              |=================================                                     |  48%  |                                                                              |==================================                                    |  48%  |                                                                              |==================================                                    |  49%  |                                                                              |===================================                                   |  49%  |                                                                              |===================================                                   |  50%  |                                                                              |===================================                                   |  51%  |                                                                              |====================================                                  |  51%  |                                                                              |====================================                                  |  52%  |                                                                              |=====================================                                 |  52%  |                                                                              |=====================================                                 |  53%  |                                                                              |=====================================                                 |  54%  |                                                                              |======================================                                |  54%  |                                                                              |======================================                                |  55%  |                                                                              |=======================================                               |  55%  |                                                                              |=======================================                               |  56%  |                                                                              |========================================                              |  56%  |                                                                              |========================================                              |  57%  |                                                                              |========================================                              |  58%  |                                                                              |=========================================                             |  58%  |                                                                              |=========================================                             |  59%  |                                                                              |==========================================                            |  59%  |                                                                              |==========================================                            |  60%  |                                                                              |==========================================                            |  61%  |                                                                              |===========================================                           |  61%  |                                                                              |===========================================                           |  62%  |                                                                              |============================================                          |  62%  |                                                                              |============================================                          |  63%  |                                                                              |============================================                          |  64%  |                                                                              |=============================================                         |  64%  |                                                                              |=============================================                         |  65%  |                                                                              |==============================================                        |  65%  |                                                                              |==============================================                        |  66%  |                                                                              |===============================================                       |  66%  |                                                                              |===============================================                       |  67%  |                                                                              |===============================================                       |  68%  |                                                                              |================================================                      |  68%  |                                                                              |================================================                      |  69%  |                                                                              |=================================================                     |  69%  |                                                                              |=================================================                     |  70%  |                                                                              |=================================================                     |  71%  |                                                                              |==================================================                    |  71%  |                                                                              |==================================================                    |  72%  |                                                                              |===================================================                   |  72%  |                                                                              |===================================================                   |  73%  |                                                                              |===================================================                   |  74%  |                                                                              |====================================================                  |  74%  |                                                                              |====================================================                  |  75%  |                                                                              |=====================================================                 |  75%  |                                                                              |=====================================================                 |  76%  |                                                                              |======================================================                |  76%  |                                                                              |======================================================                |  77%  |                                                                              |======================================================                |  78%  |                                                                              |=======================================================               |  78%  |                                                                              |=======================================================               |  79%  |                                                                              |========================================================              |  79%  |                                                                              |========================================================              |  80%  |                                                                              |========================================================              |  81%  |                                                                              |=========================================================             |  81%  |                                                                              |=========================================================             |  82%  |                                                                              |==========================================================            |  82%  |                                                                              |==========================================================            |  83%  |                                                                              |==========================================================            |  84%  |                                                                              |===========================================================           |  84%  |                                                                              |===========================================================           |  85%  |                                                                              |============================================================          |  85%  |                                                                              |============================================================          |  86%  |                                                                              |=============================================================         |  86%  |                                                                              |=============================================================         |  87%  |                                                                              |=============================================================         |  88%  |                                                                              |==============================================================        |  88%  |                                                                              |==============================================================        |  89%  |                                                                              |===============================================================       |  89%  |                                                                              |===============================================================       |  90%  |                                                                              |===============================================================       |  91%  |                                                                              |================================================================      |  91%  |                                                                              |================================================================      |  92%  |                                                                              |=================================================================     |  92%  |                                                                              |=================================================================     |  93%  |                                                                              |=================================================================     |  94%  |                                                                              |==================================================================    |  94%  |                                                                              |==================================================================    |  95%  |                                                                              |===================================================================   |  95%  |                                                                              |===================================================================   |  96%  |                                                                              |====================================================================  |  96%  |                                                                              |====================================================================  |  97%  |                                                                              |====================================================================  |  98%  |                                                                              |===================================================================== |  98%  |                                                                              |===================================================================== |  99%  |                                                                              |======================================================================|  99%  |                                                                              |======================================================================| 100%
map_GA <- tmap_mode("plot") 
## ℹ tmap modes "plot" - "view"
tm_shape(ga_counties) +
  tm_polygons(col = "white", border.col = "grey") +
tm_shape(GA_sf) +
  tm_dots(col = "red", size = 0.1, alpha = 0.7) +   
tm_layout(title = "Fatal Cases in Georgia")
## 
## ── tmap v3 code detected ───────────────────────────────────────────────────────
## [v3->v4] `tm_polygons()`: use 'fill' for the fill color of polygons/symbols
## (instead of 'col'), and 'col' for the outlines (instead of 'border.col').
## [v3->v4] `tm_dots()`: use `fill_alpha` instead of `alpha`.
## [v3->v4] `tm_layout()`: use `tm_title()` instead of `tm_layout(title = )`
## This message is displayed once every 8 hours.

print(map_GA)
## [1] "view"
# that is nice but doesn't tell us much so 

ga_county <- GA %>%
  group_by(Location.of.death..county., Highest.level.of.force) %>%
  summarise(total = n())
## `summarise()` has grouped output by 'Location.of.death..county.'. You can
## override using the `.groups` argument.
ga_county <- ga_county %>%
  rename('County' = Location.of.death..county.) %>%
  mutate(County = paste0(County, " County"))
  

ga_county_sf <- tigris::counties(state = "GA", cb = TRUE) %>%
  st_transform(crs = 4326)
## Retrieving data for the year 2024
ga_county_sf <- ga_county_sf %>%
  left_join(ga_county, by = c('NAMELSAD' = 'County'))

map_ga_2 <- tmap_mode('plot')
## ℹ tmap modes "plot" - "view"
tm_shape(ga_county_sf) +
  tm_polygons(
    col = "total",
    palette = "Reds",
    fill.scale = tm_scale_intervals(style = "jenks"),
    fill.legend = tm_legend(title = "Total Fatalities by County"))
## 
## ── tmap v3 code detected ───────────────────────────────────────────────────────
## [v3->v4] `tm_tm_polygons()`: migrate the argument(s) related to the scale of
## the visual variable `fill` namely 'palette' (rename to 'values') to fill.scale
## = tm_scale(<HERE>).[cols4all] color palettes: use palettes from the R package cols4all. Run
## `cols4all::c4a_gui()` to explore them. The old palette name "Reds" is named
## "brewer.reds"Multiple palettes called "reds" found: "brewer.reds", "matplotlib.reds". The first one, "brewer.reds", is returned.

print(map_ga_2)
## [1] "plot"
#from this we see that most of the counties based on this data don't have a lot of fatalities
#Comparing to Illinois & Florida
states <- fatal %>%
  filter(State %in% c('FL','GA','IL'))
states.1 <- states %>%
   mutate (
     type = if_else(str_detect(Highest.level.of.force, regex("^asph", ignore_case = TRUE)), "Asphyxiation", Highest.level.of.force))

states.1 <- states.1 %>%
  group_by(State, type) %>%
  summarise(total = n(),.groups ='drop')

bxplot2 <- ggplot(data = states.1) +
  geom_boxplot(aes(x = type, y = total),
               color = 'black', fill ='white') +
  facet_wrap(~State) +  # break apart by state
  labs(title = 'Boxplot of type of fatality by state',
       x = 'Type of fatality',
       y = 'Count') +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Convert to interactive plotly
plotly::ggplotly(bxplot2)
# This didn't do exactly how i imgained and I would like to see things a bit better so 

plot4 <- ggplot(states.1, aes(x= type, y = total, fill = State)) +
  geom_col(position = 'dodge') +
  labs(title = 'barplot of type of fatality by state',
       x = 'Type of fatality',
       y = 'Count') +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

print(plot4)

#gunshots distort the data else where so 

state_n_gun <- states.1 %>%
  filter(type != 'Gunshot')

plot5 <- ggplot(state_n_gun, aes(x = type, y = total, fill = State)) +
  geom_col(position = 'dodge') +
  labs(title = 'barplot by fatality besides gun',
       x = 'type of fatality',
       y = 'count') +
    theme(axis.text.x = element_text(angle = 45, hjust = 1))

print(plot5)

#that's better now we see that besides gunshot, vehicle is the most. What is interesting to see is that taser is a big thing in Florida. Curious about what the other means in Illinois


#Tried a regression incurred some errors to explore
states <- states %>%
  mutate(gun = if_else(Highest.level.of.force == 'Gunshot', 1,0)) #creating a boolean for if someone got shot

model1 <- glm(gun ~ Race, data = states, family = binomial)
summary(model1)
## 
## Call:
## glm(formula = gun ~ Race, family = binomial, data = states)
## 
## Coefficients:
##                                                                Estimate
## (Intercept)                                                     0.85543
## RaceAfrican-American/Black African-American/Black Not imputed  11.71064
## RaceAsian/Pacific Islander                                     -0.42011
## RaceEuropean-American/European-American/White                  -0.16228
## RaceEuropean-American/White                                     0.31440
## RaceHispanic/Latino                                             0.12058
## RaceMiddle Eastern                                              0.24318
## RaceNative American/Alaskan                                    11.71064
## RaceRace unspecified                                           -0.39728
##                                                               Std. Error
## (Intercept)                                                      0.05825
## RaceAfrican-American/Black African-American/Black Not imputed  229.62848
## RaceAsian/Pacific Islander                                       0.39131
## RaceEuropean-American/European-American/White                    1.22613
## RaceEuropean-American/White                                      0.08904
## RaceHispanic/Latino                                              0.12896
## RaceMiddle Eastern                                               0.81857
## RaceNative American/Alaskan                                    324.74370
## RaceRace unspecified                                             0.08350
##                                                               z value Pr(>|z|)
## (Intercept)                                                    14.685  < 2e-16
## RaceAfrican-American/Black African-American/Black Not imputed   0.051 0.959327
## RaceAsian/Pacific Islander                                     -1.074 0.283006
## RaceEuropean-American/European-American/White                  -0.132 0.894706
## RaceEuropean-American/White                                     3.531 0.000414
## RaceHispanic/Latino                                             0.935 0.349785
## RaceMiddle Eastern                                              0.297 0.766403
## RaceNative American/Alaskan                                     0.036 0.971234
## RaceRace unspecified                                           -4.758 1.96e-06
##                                                                  
## (Intercept)                                                   ***
## RaceAfrican-American/Black African-American/Black Not imputed    
## RaceAsian/Pacific Islander                                       
## RaceEuropean-American/European-American/White                    
## RaceEuropean-American/White                                   ***
## RaceHispanic/Latino                                              
## RaceMiddle Eastern                                               
## RaceNative American/Alaskan                                      
## RaceRace unspecified                                          ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 5189.2  on 4226  degrees of freedom
## Residual deviance: 5119.8  on 4218  degrees of freedom
## AIC: 5137.8
## 
## Number of Fisher Scoring iterations: 11
#based on what i read about these results I need to do this

print(table(states$Race, states$gun))
##                                                            
##                                                               0   1
##   African-American/Black                                    420 988
##   African-American/Black African-American/Black Not imputed   0   2
##   Asian/Pacific Islander                                     11  17
##   European-American/European-American/White                   1   2
##   European-American/White                                   289 931
##   Hispanic/Latino                                           104 276
##   Middle Eastern                                              2   6
##   Native American/Alaskan                                     0   1
##   Race unspecified                                          456 721


In attempting this regression what I saw is that I would have to stringr and combine like races together because that is definitely affecting the model since Black/African American have the highest level of gun violence yet were not found significant.

Conclusion:

So from the exploration of this data we can see that it is deeply affected by tobbler’s law meaning that California and Texas are consistently outliers in most visualizations. But, once we hone in on specific violence and states there becomes nuance. For example, in GA we saw how most of the state had low levels of fatalities except for Fulton county. When we look beyond Georgia and compare it to states with similar counts of violence, we see that gun violence is predominate followed by vehicular fatalities. I think it would be interesting to look at the vehicular and examine that compared to first part with deadly force intended or not. Overall, when taking gun violence out of the equation and ignoring vehicles not a lot of people would die except by tasering which I thought was interesting. There were more things that i would have liked to look at, but it required me to really clean the data to do regressions and incoprorate tidycensus elements.