Warning: package 'tidyverse' was built under R version 4.2.3
Warning: package 'ggplot2' was built under R version 4.2.3
Warning: package 'tibble' was built under R version 4.2.3
Warning: package 'tidyr' was built under R version 4.2.3
Warning: package 'readr' was built under R version 4.2.3
Warning: package 'purrr' was built under R version 4.2.3
Warning: package 'dplyr' was built under R version 4.2.3
Warning: package 'stringr' was built under R version 4.2.3
Warning: package 'forcats' was built under R version 4.2.3
Warning: package 'lubridate' was built under R version 4.2.3
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.4.4 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(pageviews) # This package gets data on Wikipedia viewinglibrary(DT) # DT stands for datatable, and creates interactive tables
Warning: package 'DT' was built under R version 4.2.3
library(infer) # for some stats like t_test
Warning: package 'infer' was built under R version 4.2.3
library(devtools)
Warning: package 'devtools' was built under R version 4.2.3
Loading required package: usethis
Warning: package 'usethis' was built under R version 4.2.3
Mass Shootings & Gun Control
Below will be a graph of the number of views on the Wikipedia article, “Mass shootings in the United States” from 2017 to 2023:
shootings <-article_pageviews(article ="Mass shootings in the United States", start =as.Date("2017-1-1"), end =as.Date("2023-12-31"))shootings |>ggplot(aes(x = date, y = views)) +geom_line() +labs(x ="Views", y ="Year", title ="Views of Mass Shootings in the United States article on Wikipedia")
It seems like there are a few spikes in searches, the largest one being in mid-2022. Here is a similar chart but for the Wikipedia article, “Gun control”:
control <-article_pageviews(article ="Gun control", start =as.Date("2017-1-1"), end =as.Date("2023-12-31"))control |>ggplot(aes(x = date, y = views)) +geom_line() +labs(x ="Views", y ="Year", title ="Views of Gun control article on Wikipedia")
The spike is similarly positioned in mid-2022. Here are the two graphs combined:
guns <-bind_rows(shootings, control) guns |>ggplot(aes(x = date, y = views, color = article)) +geom_line() +labs(x ="Views", y ="Year", title ="Views of Gun Control & Mass Shootings articles on Wikipedia")
Here are the scatterplot of the views of each article:
guns |>pivot_wider(names_from = article, values_from = views) |>ggplot(aes(x = Mass_shootings_in_the_United_States, y = Gun_control)) +# create scatterplotgeom_point() +geom_smooth(method = lm) +# create regression linelabs(x ="Views of the Wikipedia Mass shootings in the US article", y ="Views of the Wikipedia Gun control article", title ="Relationship between Wikipedia article views")
I wanted to find out data on two shootings within the past year that had a high number of deaths, and see whether those shootings made a difference in Wikipedia views. The first shooting I chose was the Lewiston Shooting in Maine, on October 25th, 2023:
top_maine |>select(article, views) |>filter(!article =="Main_Page", !article =="Special:Search") |>top_n(10, views) |>ggplot(aes(x =fct_rev(as_factor(article)), y = views)) +geom_col(fill ="springgreen") +coord_flip() +scale_y_continuous(labels = scales::comma) +labs(y ="Number of Views", x ="Article", title ="Top Wikipedia articles, Oct. 26, 2023")
The Lewiston Shooting seemed to be quite significant, as it was the top 3 most visited site on Wikipedia that day. Here is the data for another mass shooting in 2023, this time in Monterey Park, California on January 21st:
top_cali |>select(article, views) |>filter(!article =="Main_Page", !article =="Special:Search") |>top_n(10, views) |>ggplot(aes(x =fct_rev(as_factor(article)), y = views)) +geom_col(fill ="springgreen") +coord_flip() +scale_y_continuous(labels = scales::comma) +labs(y ="Number of Views", x ="Article", title ="Top Wikipedia articles, Jan. 22, 2023")
It seemed like this shooting was not significant. Further digging showed that the event was only in the top 40s two days after it took place.
Views on Gun Control
Perhaps these two shootings would raise more awareness about gun control in the general public. Here is a graph of views on the Gun control Wikipedia article 7 days before and after the Lewiston shooting:
mass_shootings <-bind_rows(gun_maine, gun_cali)mass_shootings |>ggplot(aes(x = day, y = views, color = event)) +geom_line() +theme_minimal() +labs(x ="Days before/after Shooting", y ="Wikipedia Views", color ="Event", title ="Views of the Wikipedia Gun Control Article before and after Two Mass Shootings")
There seems to be a spike in views of the Gun control article the days after each shooting. To see whether this result is significant, let’s perform a t-test:
Warning: The statistic is based on a difference or ratio; by default, for
difference-based statistics, the explanatory variable is subtracted in the
order "TRUE" - "FALSE", or divided in the order "TRUE" / "FALSE" for
ratio-based statistics. To specify this order yourself, supply `order =
c("TRUE", "FALSE")`.
# A tibble: 2 × 4
after_event Mean StdDev N
<lgl> <dbl> <dbl> <int>
1 FALSE 466. 116. 16
2 TRUE 621. 110. 14
The average number of views on the Gun control Wikipedia article 7 days after both shootings (M = 621.07, SD = 110.46) is significantly higher than the 7 days before the shootings (M = 466.31 , SD = 115.63), t(27.8) = 3.75, p < .001.