# 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

# Loading our dataset

data <-read.csv('C:/Users/Hp/Desktop/Dataset for R submission/player_data.csv')

Extracting Artifical Intelligence’:

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")     

Creating a tsibble of our extracted data:

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)

Plotting our tsibble:

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.

Plotting for different windows of time:

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'

Observation :

There is a large spike which occurs in the months of vaccation.