# Importing required libraries
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ 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(ggrepel)
library(ggthemes)
# Loading our dataset
data <-read.csv('C:/Users/Hp/Desktop/Dataset for R submission/player_data.csv')
Using the timeframe from the year 2014 to 2020:
ai_hits <- wp_trend(page=c("Artificial Intelligence"),
from="2010-01-01",
to="2023-01-01",
lang="en",
warn=TRUE)
ai_hits <- mutate(ai_hits, article = "Artificial Intelligence")
ai_hits <- group_by(ai_hits, date) %>%
summarise(views = sum(views)) %>%
ungroup() %>%
mutate(article = "Artificial Intelligence")
ai_hits <- select(ai_hits, article, date, views)
ai_hits$date <- as.Date(ai_hits$date)
ai_hits_ts <- as_tsibble(ai_hits, index = date)
ggplot(ai_hits_ts, aes(x = date, y = views)) +
geom_line(size = 1.5, colour = "steelblue") +
theme_bw()
## 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.
ai_hits_ts %>%
index_by(month = floor_date(date, 'month')) %>%
summarise(avg_views = mean(views)) %>%
ggplot(mapping = aes(x = month, y = avg_views)) +
geom_line() +
geom_smooth(span = 0.3, color = 'blue', se = FALSE) +
labs(title = "Wikipedia Trends: Artificial Intelligence",
subtitle = "(by each month)") +
scale_x_date(breaks = "5 month", labels = \(x) month(x)) +
theme_hc()
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
ai_hits_ts %>%
index_by(week = floor_date(date, 'week')) %>%
summarise(avg_views = mean(views)) %>%
ggplot(mapping = aes(x = week, y = avg_views)) +
geom_line() +
geom_smooth(span = 0.3, color = 'blue', se = FALSE) +
labs(title = "Wikipedia Trends: Artificial Intelligence",
subtitle = "(by weeks)") +
scale_x_date(breaks = "20 week", labels = \(x) week(x)) +
theme_hc()
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
There is a large spike which occurs in the months of vaccation.
ai_hits_ts %>%
filter_index("2010-01" ~ "2010-05") %>%
ggplot(mapping = aes(x = date, y = views)) +
geom_line() +
geom_smooth(method = 'lm', color = 'blue', se = FALSE) +
labs(title = "Wikipedia Trends: Artificial Intelligence") +
theme_hc()
## `geom_smooth()` using formula = 'y ~ x'
ai_hits_ts %>%
filter_index("2015-01" ~ "2015-05") %>%
ggplot(mapping = aes(x = date, y = views)) +
geom_line() +
geom_smooth(method = 'lm', color = 'blue', se = FALSE) +
labs(title = "Wikipedia Trends: Artificial Intelligence") +
theme_hc()
## `geom_smooth()` using formula = 'y ~ x'
ai_hits_ts %>%
filter_index("2018-06" ~ "2018-12") %>%
ggplot(mapping = aes(x = date, y = views)) +
geom_line() +
geom_smooth(method = 'lm', color = 'blue', se = FALSE) +
labs(title = "Wikipedia Trends: Artificial Intelligence") +
theme_hc()
## `geom_smooth()` using formula = 'y ~ x'
ai_hits_ts %>%
filter_index("2022-06" ~ "2022-12") %>%
ggplot(mapping = aes(x = date, y = views)) +
geom_line() +
geom_smooth(method = 'lm', color = 'blue', se = FALSE) +
labs(title = "Wikipedia Trends: Artificial Intelligence") +
theme_hc()
## `geom_smooth()` using formula = 'y ~ x'
Examining Wikipedia trends for “Artificial Intelligence” over different time spans.
ai_hits_xts <- xts(ai_hits_ts$views,
order.by = ai_hits_ts$date,
frequency = 30) # keeping this as 7
ai_hits_xts <- setNames(ai_hits_xts, "views")
pacf(ai_hits_xts, na.action = na.exclude,
xlab = "Lag (Weekly)", main = "PACF for Wikipedia Hits")
ai_hits_xts
## views
## 2010-01-01 3271
## 2010-01-02 3973
## 2010-01-03 3323
## 2010-01-04 0
## 2010-01-05 3944
## 2010-01-06 4581
## 2010-01-07 4576
## 2010-01-08 4673
## 2010-01-09 3881
## 2010-01-10 4195
## ...
## 2022-12-23 77
## 2022-12-24 95
## 2022-12-25 98
## 2022-12-26 65
## 2022-12-27 94
## 2022-12-28 72
## 2022-12-29 132
## 2022-12-30 176
## 2022-12-31 140
## 2023-01-01 146