2023-04-16

1. Mass Shootings- Year and Number of Fatalities

\(\text{Fatalities}=\beta_0+\beta_1\cdot\text{Year}+\varepsilon; \hspace{1cm}\varepsilon\sim\mathcal{N}(0;\sigma^2)\)

# Load ggplot2 package
library(ggplot2)

shootings <- 
  read.csv("~/Desktop/US gun violence/shooting_1982-2023_cleaned.csv")


g <- ggplot(data = shootings, aes(x = year, y = fatalities, 
                                  color = gender)) + 
  geom_point() +
  geom_smooth(aes(group=1), method = "lm", se = FALSE) +
 
  labs(x = "Year", y = "Fatalities") +
  ggtitle("Fatalities in Shootings by Year and Gender")

2. Graph showing year of shooting and number of fatalities

This graph shows almost all mass shooters have been men. It also shows there was an increase in the number of fatalities from ~2007-2022

3. Mass Shootings by race, age, and number of fatalities

4. Mass shootings and mental health

There is a lot of debate on whether we have a gun problem or a mental health problem

$x
[1] "Mental Health Issues"

$y
[1] "Count"

$fill
[1] "Gender"

attr(,"class")
[1] "labels"

5. Mass Shootings - was the weapon obtained legally?

library(plotly)

plot1 <- plot_ly(data = shootings, x = ~year, y = ~location, 
                 color = ~weapons_obtained_legally,
        type = "scatter", mode = "markers") %>%
  layout(title = "Weapons Obtained Legally by Year and Type",
         xaxis = list(title = "Year", dtick = 10), 
         yaxis = list(title = "Location"))

6. Graph: location, year, and if the weapon was obtained legally.

\(\text{Percentage Obtained Legally} =\frac{95}{141}\times{100} =\text{67.4%}\)
\(\text{Percentage Obtained Illegally} =\frac{16}{141}\times{100} =\text{11.3%}\)
\(\text{Percentage TBD/Unknown} =\frac{30}{141}\times{100} =\text{21.3%}\)

7. Frequency and Age Range

library(ggplot2)

shootings <- 
  read.csv("~/Desktop/US gun violence/shooting_1982-2023_cleaned.csv")

shootings_clean <- na.omit(shootings)

g3 <- ggplot(shootings_clean, aes(x = age_group, fill = age_group)) +
  geom_bar(stat = "count", color = "black") +
  labs(title = 
         "Frequency of Shootings by Age Group",
       x = "Age Group", y = "Count")

8. Histogram Showing Frequency of Shootings Based on Age Range