── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.4
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.4.4 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.0
✔ 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 tableslibrary(infer) # for some stats like t_testlibrary(devtools)
Loading required package: usethis
Below you will find the process and overlay of two graphs titled Gun_control and Mass_shootings_in_the_United_States. There was a notable difference of views between both.
gun_control <-article_pageviews(article ="Gun control", start =as.Date("2017-1-1"), end =as.Date("2023-12-31"))
Mass_Shootings <-article_pageviews(article ="Mass shootings in the United States" , start =as.Date("2017-1-1"), end =as.Date("2023-12-31"))
guns <-bind_rows(gun_control, Mass_Shootings)
guns %>%ggplot(aes(x = date, y = views, color = article)) +geom_line()
Below you will find a scatterplot of the two articles and their relationship regarding the Wikipedia article view.
ggplot(guns_pivot, aes(x =`Gun_control`, y =`Mass_shootings_in_the_United_States`)) +geom_point() +geom_smooth(method = lm) +# add a regression line if neededlabs(x ="Views of the Wikipedia Gun control article",y ="Views of the Wikipedia Mass shootings in the United States article",title ="Relationship between Wikipedia article views")
The Las Vegas shooting in 2017 made headlines. Below is a table and bar graph indicating the amount of views this article received the day after the shooting occurred. Other articles were assessed in comparison.
Vegas:
popular <-top_articles(start =as.Date("2017-10-2"))
popular |>select(article, views) |>filter(!article =="Main_Page", !article =="Special:Search") |>slice_max(views, n =10) |>datatable()
popular |>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 ="blue")+coord_flip()+scale_y_continuous(labels = scales::comma)
The Orlando Night Club shooting occurred on June 6th, 2016. Below is a table and bar graph indicating the number of views this article received the following day. Other articles have been assessed for comparison.
top <-top_articles(start =as.Date("2016-6-13"))
top |>select(article, views) |>filter(!article =="Main_Page", !article =="Special:Search") |>slice_max(views, n =10) |>datatable()
top |>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 ="lightgreen")+coord_flip()+scale_y_continuous(labels = scales::comma)
Below is the process and code used to combine the data from the Orlando and Vegas shooting dates and the “Gun Control” article over a span of 14 days (7 days prior, 7 days after). The amount of views of the Gun Control article increased after the shootings occurred. This can be seen in the graph below.
Vegas |>ggplot(aes(x = day, y = views)) +geom_line()
shootings <-bind_rows(Orlando, Vegas)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")
The t-test below indicates that there was a significant increase in views of the article “Gun Control” the day after the shootings occurred.
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 532. 411. 16
2 TRUE 2426. 1125. 14
The average number of views of the Wikipedia Gun Control article in the 7 days prior to the two shootings (M = 531.8, SD = 410.6) was statistically significantly different from the average number of views in the 7 days after the shooting (M = 2426.1, SD = 1125.4), t(16) = 5.96, p = 1.99e-05.