The data used for this assignment details mass shootings for the past five years. Each entry includes the date, state, number of people who died, number of people that were injured and a small description describing what happened. The data is available on Kaggle at https://www.kaggle.com/datasets/hemil26/mass-shootings-in-united-states-20182022?select=shootings_2018.csv.

states <- map_data("state")
states = states %>%
  mutate(State = str_to_title(region))

shootings2018 = read.csv("shootings_2018.csv")
shootings2019 = read.csv("shootings_2019.csv")
shootings2020 = read.csv("shootings_2020.csv")
shootings2021 = read.csv("shootings_2021.csv")
shootings2022 = read.csv("shootings_2022.csv")

shootingsTotal = bind_rows(shootings2018, shootings2019, shootings2020,
                           shootings2021, shootings2022)

shootingsTotal = shootingsTotal %>%
  group_by(State) %>%
  summarise(DeathTotal = sum(Dead))

shootings2018 = shootings2018 %>% 
  group_by(State) %>%
  summarise(DeathTotal = sum(Dead))
  
stateShootings2018 = states %>%
  left_join(shootings2018, by = "State") %>%
  select(-c(region, subregion))

head(stateShootings2018)
##        long      lat group order   State DeathTotal
## 1 -87.46201 30.38968     1     1 Alabama         11
## 2 -87.48493 30.37249     1     2 Alabama         11
## 3 -87.52503 30.37249     1     3 Alabama         11
## 4 -87.53076 30.33239     1     4 Alabama         11
## 5 -87.57087 30.32665     1     5 Alabama         11
## 6 -87.58806 30.32665     1     6 Alabama         11
p_death2018 = ggplot(data = stateShootings2018, 
       mapping = aes(x = long, y = lat, group = group, fill = DeathTotal,
                     text = paste("Shooting Deaths in 2018: ", DeathTotal))) +
  geom_polygon(color = "white") +
  ggdendro::theme_dendro() +
  scale_fill_viridis(option = "magma", direction = -1) + 
  coord_map() +
  guides(fill = guide_legend(title = "Deaths")) +
  ggtitle("Mass Shooting Deaths in 2018")

ggplotly(p_death2018, tooltip = "text")

In this first plot, I wanted to simply display the mass shooting deaths per state for the year 2018. Using a simple choropleth map with the states defined by spatial polygons, this plot clearly shows number of deaths per state and how each state compares to each other. The tooltip function allows for the hover over effect and an actual death count. However, multiple states either had missing data or no deaths leading to an incomplete look. I like the simplicity and effectiveness of this plot.

t_states <- tigris::states(cb = TRUE, resolution = '20m')
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |========                                                              |  11%
  |                                                                            
  |===============                                                       |  21%
  |                                                                            
  |================                                                      |  22%
  |                                                                            
  |================                                                      |  23%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |====================                                                  |  29%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |======================                                                |  32%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |========================                                              |  34%
  |                                                                            
  |=========================                                             |  36%
  |                                                                            
  |==========================                                            |  37%
  |                                                                            
  |===========================                                           |  38%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |=============================                                         |  42%
  |                                                                            
  |==============================                                        |  42%
  |                                                                            
  |===============================                                       |  45%
  |                                                                            
  |=================================                                     |  47%
  |                                                                            
  |==================================                                    |  49%
  |                                                                            
  |====================================                                  |  51%
  |                                                                            
  |=====================================                                 |  53%
  |                                                                            
  |=======================================                               |  55%
  |                                                                            
  |=========================================                             |  58%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |===========================================                           |  62%
  |                                                                            
  |=============================================                         |  65%
  |                                                                            
  |===============================================                       |  68%
  |                                                                            
  |================================================                      |  68%
  |                                                                            
  |==================================================                    |  72%
  |                                                                            
  |======================================================                |  77%
  |                                                                            
  |=========================================================             |  81%
  |                                                                            
  |============================================================          |  86%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |==================================================================    |  95%
  |                                                                            
  |======================================================================| 100%
stateShootingsTotal = t_states %>%
  left_join(shootingsTotal, by =  c("NAME" = "State"))
mapview::mapview(stateShootingsTotal, zcol = "DeathTotal")

This second plot displays the deaths total from mass shootings for the years 2018-2022. This plot includes each year and shows the death totals over that time period. It also incorporates spatial files using the tigris package and the mapview package to display in a more interactive, full world type view. The ability to start zoomed in on just the United States would have been nice but the zoom +- can be very useful. This plot has less incomplete or missing data and gives a broader view of the past five years.