Purpose of the Project

The purpose of this project was to compare media coverage of the NFL and 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 there really is.

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:

-A data set containing daily news story counts for both topics. -Weekly summaries of news coverage.

-An interactive Plotly line chart comparing NFL and college football coverage over time.

-Summary statistics showing total stories

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 troubleshooting, I made the project design decisions, selected the variables, evaluated the results, and determined how the findings would be presented.

Things I learned

Through this project, I gained a better understanding how to access data using an API and how to use R to automate data collection from an external source. I gained experience working with time-series data and converting daily observations into weekly summaries.

I also learned more on how to create interactive visualizations using Plotly and how to use data manipulation tools from the tidyverse package. 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.

How the code works

Step 1: Load Packages

The script checks whether the required packages are installed and installs any missing packages. It then loads the libraries needed for data collection, data manipulation, date handling, and visualization.

Step 2: Verify the API Key

The script checks whether a valid Media Cloud API key is available. If the key is missing, the script stops and displays an error message.

Step 3: Create a Function

A custom function called mc_counts_over_time() is created. This function sends a request to the Media Cloud API, retrieves story count data for a specified query, and stores the results in a data frame.

Step 4: Define Search Terms

Two search terms are created:

“NFL” and “college football”

These search terms tell Media Cloud what topics to search for.

Step 5: Set the Date Range

The beginning and ending dates for data collection are defined. The API only retrieves stories published during this period.

Step 6: Download NFL Data

The custom function is used to request story count data for the NFL search term. The results are stored in a dataset called nfl_data.

Step 7: Download College Football Data

The same function is used to download story count data for the college football search term. The results are stored in college_data.

Step 8: Combine Datasets

The NFL and college football datasets are merged into a single dataset called football_data, making comparison easier.

Step 9: Examine the Data

Functions such as head() and glimpse() are used to inspect the structure of the data and verify that the download was successful.

Step 10: Calculate Weekly Counts

The script converts daily dates into weekly periods and then sums the daily counts within each week. This produces weekly story counts for each topic.

Step 11: Create an Interactive Visualization

A Plotly line chart is generated to display weekly coverage for both NFL and college football. Users can hover over the graph to view exact values for any week.

Step 12: Generate Story Count Summaries

The script calculates summary statistics for each topic, including total story counts, average weekly coverage, variability, and minimum and maximum weekly counts.

Step 13: Interpret the Results

The resulting tables and visualizations are used to compare media coverage between the NFL and college football. By examining the trends and summary statistics, it is possible to identify differences in the amount of attention each topic received during the study period.

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