The 2nd amendment in the United States allows its citizens the right to bear arms. This is a highly controversial topic due to an innumerably amount of incidences of gun violence. Whether it is in schools, or in other public places, the number of incidents seem to have been increasing, to the extent that several lawmakers want to impose restrictions. This is met with a large amount of criticism from the other side, which leads to differing gun laws in different states. Some more strict than others.
But is the introduction of strict gun laws (whatever that may be, stronger background checks, accessibility, etc) really introducing a decrease in the amount of firearm related mortalities? This quick project aims to answer this question.
The CDC publishes firearm related deaths on a quarterly basis, which can be access using an API, as seen below. In this project, the 12 month data from the year 2023 is used, calculated as deaths per 100,000 people.
library(httr)
library(jsonlite)
library(dplyr)
library(reshape2)
library(stringr)
library(ggplot2)
library(maps)
library(mapdata)
library(ggpattern)
library(sf)
# Define the URL for the CDC API
url = 'https://data.cdc.gov/resource/489q-934x.json'
# Send a GET request to the URL
response = GET(url)
data = fromJSON(content(response, "text"))
data = data %>%
filter(year_and_quarter == '2023 Q4') %>%
filter(cause_of_death == 'Firearm-related injury') %>%
filter(rate_type == 'Crude') %>%
filter(time_period == '12 months ending with quarter')
state_columns = c("year_and_quarter", "cause_of_death",
"rate_alaska", "rate_alabama", "rate_arkansas", "rate_arizona",
"rate_california", "rate_colorado", "rate_connecticut", "rate_district_of_columbia",
"rate_delaware", "rate_florida", "rate_georgia", "rate_hawaii",
"rate_iowa", "rate_idaho", "rate_illinois", "rate_indiana",
"rate_kansas", "rate_kentucky", "rate_louisiana", "rate_massachusetts",
"rate_maryland", "rate_maine", "rate_michigan", "rate_minnesota",
"rate_missouri", "rate_mississippi", "rate_montana", "rate_north_carolina",
"rate_north_dakota", "rate_nebraska", "rate_new_hampshire", "rate_new_jersey",
"rate_new_mexico", "rate_nevada", "rate_new_york", "rate_ohio",
"rate_oklahoma", "rate_oregon", "rate_pennsylvania", "rate_rhode_island",
"rate_south_carolina", "rate_south_dakota", "rate_tennessee", "rate_texas",
"rate_utah", "rate_virginia", "rate_vermont", "rate_washington",
"rate_wisconsin", "rate_west_virginia", "rate_wyoming")
data_filtered = data[, state_columns]
data_long = melt(data_filtered, id.vars = c("year_and_quarter", "cause_of_death"),
variable.name = "state", value.name = "death_rate")
data_long$state = gsub("rate_", "", data_long$state)
data_long$state = gsub("_", " ", data_long$state)
data_long = data_long %>%
rename(State = state) %>%
filter(State != 'district of columbia')
To quantify gun law strictness is difficult. The Giffords Law Center from Harvard University issues a ranking annually, based on several factors, ranging from 1 for most strict to 50 for most lenient. For example, this year, Mississippi has the gun law strength 44, which is considered very lenient. The reasoning for this rating is that K-12 teachers are allowed to carry guns,or that state and local agencies are now prohibited from keeping records on privately owned firearms. On the other hand of the spectrum, Connecticut has the the rating of 3, because the state recently prohibited open carry and ghost guns.
The data for Giffords Law Strentghs were access via https://giffords.org/lawcenter/resources/scorecard/ and hardcoded into a csv file, due to the lack of an API. Furthermore, this was converted to a 5-point Likert scale with breaking points at the 10-multiplier. Therefore, Connecticut would be considered very strict, while Mississippi would be considered very lenient.
gifford = read.csv('https://raw.githubusercontent.com/lucasweyrich958/DATA608/refs/heads/main/giffords_gun_law.csv', header = T)
gifford$State = tolower(gifford$State)
gifford$likert_category = cut(
gifford$Ranking,
breaks = c(0, 10, 20, 30, 40, 50),
labels = c('Very Strict', 'Strict', 'Neutral', 'Lenient', 'Very Lenient'),
right = TRUE
)
final_data = data_long %>%
left_join(gifford, by = 'State') %>%
select(State, death_rate, Ranking, likert_category)
final_data$death_rate = as.numeric(final_data$death_rate)
Below, three visualizations are shown to assess whether the strictness of gun laws are in fact related to the amount of deaths. Firstly, a basic USA map is shown with a color gradient that visualizes the death rate per 100,000 people. This gives an easy introduction into the data, not yet considering the law strictness. Therefore, it does require domain knowledge, but allows the viewers to get familiar with the gradient and death rate.
us_states <- map_data("state")
# Ensure final_data state names are lowercase
final_data <- final_data %>%
mutate(State = tolower(State))
# Merge the data keeping the necessary columns
map_data <- us_states %>%
left_join(final_data, by = c("region" = "State")) %>%
filter(!region %in% c('district of columbia', 'alaska', 'hawaii'))
# Plot
ggplot(map_data, aes(x = long, y = lat, group = group, fill = death_rate)) +
geom_polygon(color = "white") +
scale_fill_gradient(low = "#40c9ff", high = "#e81cff", na.value = "grey50") +
labs(title = "Firearm Death Rate by State",
fill = "Death Rate \n(per 100,000)") +
theme_minimal() +
theme(axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
panel.grid = element_blank())
Second,a tile graph is shown that shows death rate gradient separated by each state and also grouped by law strictness. A clear trend is visible where there is more blue (less deaths) on the strict side of the graph versus the pink (more deaths) on the lenient side of the graph. Although it is not fully clear cut and there is some variability visisble. For example, Colorado may be considered very strict, but still has medium amount of deaths, relatively, which is likely due to the only recent enactment of stricter gun laws.
ggplot(final_data, aes(x = likert_category, y = State, fill = death_rate)) +
geom_tile(color = "white") +
scale_fill_gradient(low = "#40c9ff", high = "#e81cff") +
labs(title = "Firearm Death Rate by Gun Law Strictness and State",
x = "Gun Law Strictness",
y = "State",
fill = "Death Rate \n(per 100,000)") +
theme_minimal()
Lastly, a similar plot is shown but also incorporating the geogrpahical location of the states. The color gradient again shows the death rate, while the states are grouped by gun law strictness. Interestingly, a pattern can be seen that the coastal states tend to be more strict than the central/southern states.
state_data = data.frame(
state_name = tolower(state.name),
state_abbr = state.abb,
x = state.center$x,
y = state.center$y
)
state_abbreviations = merge(state_data, final_data, by.x = "state_name", by.y = "State", all.x = TRUE)
state_abbreviations = state_abbreviations %>%
filter(state_name != 'hawaii') %>%
filter(state_name != 'alaska')
us_map_data = map_data("state") %>%
filter(!region %in% c("district of columbia", "hawaii", "alaska"))
ggplot() +
geom_polygon(data = us_map_data, aes(x = long, y = lat, group = group),
color = "#2e2e2e", fill = NA, size = 0.2) +
geom_polygon(data = map_data, aes(x = long, y = lat, group = group, fill = death_rate)) +
scale_fill_gradient(low = "#40c9ff", high = "#e81cff", na.value = "#2e2e2e") +
labs(title = "US States by Death Rate and Gun Law Strictness",
fill = "Death Rate \n(per 100,000)") +
facet_wrap(~ likert_category, ncol = 1, labeller = label_both) +
geom_text(data = state_abbreviations, aes(x = x, y = y, label = state_abbr),
color = "black", size = 3, inherit.aes = FALSE) +
theme_minimal() +
theme(axis.title = element_blank(), axis.text = element_blank(), axis.ticks = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_rect(fill = NA, color = "black"))
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
Overall, it appears that stricter gun laws are in fact related to decreased death rate, however, it is unclear whether there is an actual cause-and-effect relationship, or if this is cultural. Due to the vast size of the US, cultural differences are just as vast, and this could very well be the case that people in New York are not interested in owning that many weapons as someone in Nebraska, therefore, leading to less gun related deaths in NY compared to NE, and that a change in the NE law would not make a large difference.