Purpose of the Project

The purpose of this project was to compare media coverage of the National Football League (NFL) and NCAA College Football using data collected from the Media Cloud platform. I have watched both College Football and NFL my entire life so I wanted to examine how often each topic appeared in online news coverage and determine whether there were differences in the amount of attention each sport received over time.

I did an undergrad thesis project on NIL involved with College Football and how it may effect how they present themselves online. Since college football has blown up in the past few years, it really got me thinking about how much coverage and attention goes into the sport.

Data Source

The data came from the Media Cloud API. Media Cloud collects and archives news stories from online news sources around the world. For this project, I used the search terms “NFL” and “college football” and collected story count data from January 1, 2026 through October 30, 2026. The API returned daily story counts, which were then aggregated into weekly totals for analysis.

Project Output

The final project produced:

My role in developing the script

I selected the research topic and developed the project question. I chose NFL and college football because both sports receive extensive media attention and provide an opportunity to compare professional and collegiate sports coverage.

I identified Media Cloud as an appropriate data source, selected the search terms, determined the date range for the study, and tested the queries to ensure the results were relevant. I reviewed the output, interpreted the findings, and decided how the data should be visualized and summarized.

While AI assisted with coding tasks and any complications I ran into, I made the project design decisions, selected the variables, evaluated the results, and determined how the findings would be presented.

Things I learned

Throughout this project, I strengthened my data analysis and programming skills by using an API to retrieve data and leveraging Rstudio to collect data from an external source. I also gained hands on experience working with time series data, grouping together observations into weekly trends, and identifying patterns and trends within large data sets.

I also got a better understanding on how to create a plotly line interactive chart on Rstudio. Copilot helped me learned that AI can adjust the size of the graph so it can fit on your Rmarkdown when you knit it. In addition, I learned how media coverage can vary significantly between topics and how large data sets can be analyzed to identify patterns and trends.

Overall, I was surprised with the results. I would’ve thought the college football would have a closer amount of stories compared to the NFL. College football and NIL is the hot topic in the sports community right now so I would’ve believed this would be the reason there were a lot more stories or articles on college football. It was very interesting to see how the NFL is just much more significant compared to college football.

How the code works

Step 1: Import the Data

The project begins by importing CSV files from Media Cloud containing NFL and college football story counts, as well as separate datasets. These files were loaded into Rstudio so they could be analyzed and visualized.

Step 2: Load Required Packages

Several R packages were loaded to support the project. The tidyverse package was used for data management, lubridate was used to work with dates, httr2 was used to communicate with the Media Cloud API, and plotly was used to create an interactive visualization.

Step 3: Connect to Media Cloud

The script verified that a valid Media Cloud API key was available. This key allowed R to access story count data directly from Media Cloud’s database.

Step 4: Create a Data Collection Function

A custom function was created to send requests to the Media Cloud API and retrieve story counts over time. This function converted the returned data into a format that could be analyzed in R.

Step 5: Define Search Terms and Time Period

The search terms “NFL” and “college football” were selected to gather stories related to each topic. The analysis focused on news coverage published between January 1, 2026, and October 30, 2026.

Step 6: Collect Story Counts

Using the custom Media Cloud function, daily story counts were collected separately for NFL coverage and college football coverage. Each dataset was labeled according to its topic.

Step 7: Combine and Examine the Datasets

The NFL and college football datasets were merged into a single dataset, making it possible to compare the two topics within the same analysis. The combined dataset was reviewed to verify that the data were imported correctly and contained the expected variables and observations.

Step 8: Create an Interactive Graph

An interactive Plotly line chart was created to visualize weekly news coverage over time. The graph displayed weekly story totals for both the NFL and college football, allowing trends and differences in coverage to be easily observed.

Step 9: Calculate Total Story Counts

A summary table was generated to display the total number of stories collected for each topic. This provided a direct comparison of the overall amount of coverage received by the NFL and college football.

Step 10: Generate Summary Statistics

Additional descriptive statistics were calculated, including the mean, standard deviation, minimum, and maximum number of stories per week. These measures helped summarize typical coverage levels and variation across the study period.

Step 11: Analyze News Sources

The source datasets were combined and analyzed to identify the news outlets that published the greatest number of NFL and college football stories. A bar chart was then created to visualize the top sources contributing coverage for each topic.

The Complete Script

The Script requires a Media Cloud API key to access and download data from the Media Cloud database. However, the code itself can be viewed without an API key.

############################################################
# STEP 0: Import CSV Files
############################################################

nfl_data <- read.csv("~/Downloads/nfl_data.csv")

college_data <- read.csv("~/Downloads/college_data.csv")

nfl_sources <- read.csv("~/Downloads/nfl_sources.csv")

college_sources <- read.csv("~/Downloads/college_sources.csv")

############################################################
# STEP 0A: Save Data Frames as CSV Files
############################################################

write.csv(
  nfl_data,
  "nfl_data.csv",
  row.names = FALSE
)

write.csv(
  college_data,
  "college_data.csv",
  row.names = FALSE
)

write.csv(
  nfl_sources,
  "nfl_sources.csv",
  row.names = FALSE
)

write.csv(
  college_sources,
  "college_sources.csv",
  row.names = FALSE
)

############################################################
# 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 1.5: Import Datasets
############################################################

nfl_data <- read.csv("nfl_data.csv")

college_data <- read.csv("college_data.csv")


############################################################
# 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: Collect NFL Data
############################################################

nfl_data <- mc_counts_over_time(
  query = nfl_query,
  start_date = start_date,
  end_date = end_date
) %>%
  mutate(topic = "NFL")


############################################################
# STEP 7: Collect 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 Table
############################################################

library(gt)

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

summary_table <- football_summary |>
  gt() |>
  tab_header(
    title = "Summary Statistics for NFL and College Football Coverage"
  ) |>
  fmt_number(
    columns = c(
      Total_Stories,
      Weekly_Mean,
      Weekly_SD,
      Weekly_Min,
      Weekly_Max
    ),
    decimals = 0,
    sep_mark = ","
  )

summary_table

############################################################
# STEP 14: Top News Sources
############################################################

library(tidyverse)

nfl_sources <- nfl_sources |>
  mutate(topic = "NFL")

college_sources <- college_sources |>
  mutate(topic = "College Football")

all_sources <- bind_rows(
  nfl_sources,
  college_sources
)

top_sources <- all_sources |>
  group_by(topic) |>
  slice_max(count, n = 10) |>
  ungroup()

ggplot(
  top_sources,
  aes(
    x = reorder(source, count),
    y = count,
    fill = topic
  )
) +
  geom_col() +
  coord_flip() +
  facet_wrap(~topic, scales = "free_y") +
  labs(
    title = "Top News Sources Covering NFL and College Football",
    x = "News Source",
    y = "Number of Stories",
    fill = "Topic"
  ) +
  theme_minimal()