Load the necessary packages
library(tidyverse)
## ── Attaching packages ────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.1.0 ✔ purrr 0.3.0
## ✔ tibble 2.0.1 ✔ dplyr 0.7.8
## ✔ tidyr 0.8.2 ✔ stringr 1.3.1
## ✔ readr 1.3.1 ✔ forcats 0.3.0
## ── Conflicts ───────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(pageviews) # This package gets data on Wikipedia viewing
library(DT) # DT stands for datatable, and creates interactive tables
Load Wikipedia’s viewership iformation on Gun control
guns <- article_pageviews(article = "Gun control", start = as.Date("2015-7-1"), end = as.Date("2018-12-31"))
Graph this data over time
guns %>%
ggplot(aes(x = date, y = views))+
geom_line(color = "purple")+ theme_minimal()+
labs(x = "Date",
y = "Views",
title = "Views of Wikipedia Gun Control Over Time")
Create a table depicting the most views on reading Gun control artiicles on Wikipedia
guns %>%
select(date, views) %>%
arrange(-views) %>%
datatable()
Wikipedia Views the day after the Las Vegas shooting
top_articles(start = as.Date("2017-10-2")) %>% select(article, views)%>%
filter(!article == "Main_Page", !article == "Special:Search")%>%
datatable()
Wikipedia Views the day after the Florida school shooting
top_articles(start = as.Date("2018-2-15")) %>% select(article, views)%>%
filter(!article == "Main_Page", !article == "Special:Search")%>%
datatable()
Getting the comparitive data
vegas_shooting <- article_pageviews(article = "Gun_control",
start = as.Date("2017-9-24"),
end = as.Date("2017-10-15"))
vegas_shooting <- vegas_shooting %>%
mutate(day = -7:14) %>%
mutate(event = "Las Vegas")
florida_shooting <- article_pageviews(article = "Gun_control",
start = as.Date("2018-2-7"),
end = as.Date("2018-2-28"))
florida_shooting <- florida_shooting %>%
mutate(day = -7:14) %>%
mutate(event = "Florida")
shootings <- bind_rows(vegas_shooting, florida_shooting)
Comparing the Florida and Las Vegas Shootings
shootings %>%
ggplot(aes(x = day, y = views, color = event))+
geom_line()+
theme_minimal()+
labs(x = "Days before/after shooting",
y = "Views",
title = "Views of Wikipedia Gun control article, before/after mass shootings")
As one can see from the table above, Wikipedia viewership was increased after the Florida and Las Vegas shootings. The viewership even continued on for at least 1 to 2 weeks after the incident. It is also interesting to note the relatiely insignificant amount of viewership on this particular article prior to these incdients.