| Total Stories Collected | |
| Topic | Total_Stories |
|---|---|
| NFL | 164,497 |
| College Football | 43,296 |
This graph shows the difference in media coverage between the National Football League (NFL) and NCAA College Football. The data was collected from January 1st, 2026 to October 26th, 2026. The number of stories collected is provided above.
############################################################
# STEP 1: Install and Load Required Packages
############################################################
required_packages <- c(
"tidyverse",
"httr2",
"lubridate",
"plotly"
)
for (pkg in required_packages) {
if (!requireNamespace(pkg, quietly = TRUE)) {
install.packages(pkg)
}
}
library(tidyverse)
library(httr2)
library(lubridate)
library(plotly)
############################################################
# STEP 2: Verify Media Cloud API Key
############################################################
if (!nzchar(Sys.getenv("MEDIACLOUD_KEY"))) {
stop(
"No Media Cloud API key was found.\n",
"Run the Media Cloud setup code first,\n",
"then restart R and try again."
)
}
mc_key <- Sys.getenv("MEDIACLOUD_KEY")
############################################################
# STEP 3: Define Media Cloud Function
############################################################
mc_counts_over_time <- function(
query,
start_date,
end_date,
collection_id = 34412234
) {
resp <-
request(
"https://search.mediacloud.org/api/search/count-over-time"
) |>
req_headers(
Authorization = paste("Token", mc_key)
) |>
req_url_query(
q = query,
start = start_date,
end = end_date,
platform = "onlinenews-mediacloud",
cs = collection_id
) |>
req_perform()
results <- resp |>
resp_body_json()
map_dfr(
results$count_over_time$counts,
as_tibble
) |>
mutate(
date = as.Date(date)
)
}
############################################################
# STEP 4: Define Search Terms
############################################################
nfl_query <- "NFL"
college_query <- "\"college football\""
############################################################
# STEP 5: Define Date Range
############################################################
start_date <- "2026-01-01"
end_date <- "2026-10-30"
############################################################
# STEP 6: Download NFL Data
############################################################
message("Downloading NFL data...")
nfl_data <-
mc_counts_over_time(
query = nfl_query,
start_date = start_date,
end_date = end_date
) |>
mutate(
topic = "NFL"
)
Sys.sleep(35)
############################################################
# STEP 7: Download College Football Data
############################################################
message("Downloading College Football data...")
college_data <-
mc_counts_over_time(
query = college_query,
start_date = start_date,
end_date = end_date
) |>
mutate(
topic = "College Football"
)
############################################################
# STEP 8: Combine Datasets
############################################################
football_data <-
bind_rows(
nfl_data,
college_data
)
############################################################
# STEP 9: Examine Data
############################################################
head(football_data)
glimpse(football_data)
############################################################
# STEP 10: Convert Daily Counts to Weekly Counts
############################################################
weekly_counts <-
football_data |>
mutate(
week = floor_date(
date,
unit = "week"
)
) |>
group_by(
topic,
week
) |>
summarise(
stories = sum(count),
.groups = "drop"
)
############################################################
# STEP 11: Interactive Plotly Graph
############################################################
Graph <- plot_ly(
data = weekly_counts,
x = ~week,
y = ~stories,
color = ~topic,
type = "scatter",
mode = "lines+markers"
) |>
layout(
title = "NFL vs. College Football News Coverage",
xaxis = list(title = "Week"),
yaxis = list(title = "Weekly Story Count"),
hovermode = "x unified"
)
Graph
############################################################
# STEP 11: Story Count Summary
############################################################
if (!require("gt")) install.packages("gt")
library(gt)
story_totals <- tibble(
Topic = c("NFL", "College Football"),
Total_Stories = c(164497, 43296)
)
story_table <- story_totals %>%
gt() %>%
tab_header(
title = "Total Stories Collected"
) %>%
fmt_number(
columns = Total_Stories,
decimals = 0,
sep_mark = ","
)
story_table
############################################################
# STEP 12: Summary Statistics
############################################################
football_summary <-
weekly_counts |>
group_by(topic) |>
summarise(
Total_Stories = sum(stories),
Weekly_Mean = round(mean(stories), 2),
Weekly_SD = round(sd(stories), 2),
Weekly_Min = min(stories),
Weekly_Max = max(stories),
.groups = "drop"
)
football_summary