Project Purpose

The aim of this project was to investigate if and how media reports about Taylor Swift and Travis Kelce evolved during season 2023–2024 NFL season and how media coverage of each of the two individuals was influenced by their mutual relationship.

I was interested in determining whether the coverage was significantly dominated by the presence of Taylor and Travis as a couple, or if there were stories about them both separately. This gave me an opportunity to analyze the connection between their relationship and the coverage of them as a news story.

Data Sources

MediaCloud is the main source of this project. It is an online research tool that helps researchers track news history.

The project studied news items published between September 1, 2023, to September 1, 2024. There were three search categories:

Having different categories for research helps separate the news items connected to the story from the news items on their own.

Project Output

The final output delivers an audience-oriented report utilizing interactive visuals made with R and Plotly.

These visuals focus on comparing the weekly media coverage of Taylor Swift, Travis Kelce, along with their collective following. Besides, one visualization will review this as a percentage regarding the specific media that has spoken about the other individual. The table provides the week where joint coverage was the greatest.

The presented visuals allow observing how coverage has changed over a chosen period.

My Role in the Project

I chose the topic, created a research question, and established the timeframe and search categories for my analysis.

I also focused on using the Media Cloud API, extracting the data, and fixing errors I experienced in the process. I made use of AI tools in order to create and fix the R codes, arrange the R Markdown file, and elaborate on the way different codes work.

Lastly, I analyzed the output and corrected the issues in order to obtain the required data and visualizations. Overall, the final deliverable is the depiction of the research topic and the choices I have made along the way.

What I Learned

This task allowed me to find out more about how we can utilize data in order to conduct the analysis of the media. I was taught how to work with API data in R, conduct searches with the help of the queries, and sort obtained data.

Besides, I had a chance to use several R packages, including tidyverse, lubridate, httr2, and Plotly. After finishing this task, I learned how to divide dates into weeks, compare different categories of data, and create interactive visual representations of information.

The hardest part was making Media Cloud API function properly. I faced difficulties while initiating API requests, dealing with the rate limitations, and receiving the proper data structure. Nevertheless, I managed to tackle these issues, and I learned how important it is to verify the data structure and look for bugs in the code rather than rely on the assumption that the data would be as expected.

During the completion of this task, I realized that the number of stories produced is not always indicative of how many people read them.

Step-by-Step Process

1. Developing the Research Question

I chose to examine Taylor Swift and Travis Kelce because their relationship connected the entertainment industry with professional sports and generated a significant amount of media attention during the 2023-2024 NFL season.

I developed a research question focused on how their coverage changed over time and how much their individual media coverage was connected to their relationship.

2. Collecting the Data

I used Media Cloud to retrieve online news coverage for the selected date range. I created three separate search queries to distinguish between stories mentioning Taylor Swift, stories mentioning Travis Kelce and stories mentioning both.

3. Cleaning and Organizing the Data

After retrieving the data, I used R to organize the story counts and dates into a consistent format. I grouped the daily story counts into weeks to make the coverage easier to compare over time.

4. Creating the Visualizations

I used Plotly to create interactive line graphs showing weekly story counts and the percentage of individual coverage mentioning the other person.

I also created a table showing the weeks with the highest joint coverage.

5. Interpreting the Results

The final step was examining the graphs and tables to identify patterns in coverage. I compared individual coverage with joint coverage and considered how the relationship connected sports and entertainment reporting.

Limitations

By using the Media Cloud’s results with a specific set of search terms to retrieve stories, the project may have missed some that do not include the specific names searched.

Another aspect of this analysis is that focuses on the number of stories rather than the tone of each story, audience engagement, or readership. Consequently, while changes in volume of coverage can be observed, this study cannot tell how audiences have reacted to the stories or how they impacted them.

Full Code

The following is the complete R script used for my project.

## ----setup, include=FALSE-----------------------------------------------------------------------------------------------
knitr::opts_chunk$set(
  echo = FALSE,
  message = FALSE,
  warning = FALSE
)

library(tidyverse)
library(httr2)
library(jsonlite)
library(lubridate)
library(plotly)
library(knitr)
library(scales)


## ----data-collection, include=FALSE-------------------------------------------------------------------------------------
start_date <- "2023-09-01"
end_date <- "2024-09-01"

collection_id <- 34412234
platform <- "onlinenews-mediacloud"

api_key <- Sys.getenv("MEDIACLOUD_KEY")

cache_folder <- "mediacloud_cache"

if (!dir.exists(cache_folder)) {
  dir.create(cache_folder)
}

queries <- list(
  "Taylor Swift Only" = '"Taylor Swift" AND NOT "Travis Kelce"',
  "Travis Kelce Only" = '"Travis Kelce" AND NOT "Taylor Swift"',
  "Joint Coverage" = '"Taylor Swift" AND "Travis Kelce"'
)

get_media_counts <- function(query, label) {

  cache_file <- file.path(
    cache_folder,
    paste0(label, ".rds")
  )

  # Use previously downloaded results if available
  if (file.exists(cache_file)) {
    return(readRDS(cache_file))
  }

  if (api_key == "") {
    return(NULL)
  }

  request <- request(
    "https://search.mediacloud.org/api/search/count-over-time"
  ) |>
    req_headers(
      Authorization = paste("Token", api_key)
    ) |>
    req_url_query(
      q = query,
      start = start_date,
      end = end_date,
      cs = collection_id,
      platform = platform
    ) |>
    req_timeout(120) |>
    req_error(is_error = function(resp) FALSE)

  response <- tryCatch(
    req_perform(request),
    error = function(e) NULL
  )

  if (is.null(response)) {
    return(NULL)
  }

  status <- resp_status(response)

  if (status != 200) {
    message(
      label,
      " request failed. HTTP status: ",
      status
    )
    return(NULL)
  }

  raw_data <- tryCatch(
    resp_body_json(response, simplifyVector = FALSE),
    error = function(e) NULL
  )

  if (is.null(raw_data)) {
    return(NULL)
  }

  saveRDS(raw_data, cache_file)

  raw_data
}

swift_raw <- get_media_counts(
  queries[["Taylor Swift Only"]],
  "swift_only"
)

kelce_raw <- get_media_counts(
  queries[["Travis Kelce Only"]],
  "kelce_only"
)

joint_raw <- get_media_counts(
  queries[["Joint Coverage"]],
  "joint_coverage"
)


## ----data-preparation, include=FALSE------------------------------------------------------------------------------------

clean_media_data <- function(raw_data, category) {

  counts <- raw_data$count_over_time$counts

  df <- bind_rows(counts)

  df <- df |>
    mutate(
      date = as.Date(date),
      count = as.numeric(count)
    ) |>
    select(date, count) |>
    mutate(category = category)

  return(df)
}

swift_data <- clean_media_data(
  swift_raw,
  "Taylor Swift Only"
)

kelce_data <- clean_media_data(
  kelce_raw,
  "Travis Kelce Only"
)

joint_data <- clean_media_data(
  joint_raw,
  "Joint Coverage"
)

data_available <- TRUE

daily_data <- bind_rows(
  swift_data,
  kelce_data,
  joint_data
)

weekly_data <- daily_data |>
  mutate(
    week = floor_date(date, unit = "week")
  ) |>
  group_by(week, category) |>
  summarise(
    stories = sum(count, na.rm = TRUE),
    .groups = "drop"
  )

totals <- daily_data |>
  group_by(category) |>
  summarise(
    total_stories = sum(count, na.rm = TRUE),
    .groups = "drop"
  )

joint_weekly <- weekly_data |>
  filter(category == "Joint Coverage") |>
  arrange(desc(stories))

peak_weeks <- joint_weekly |>
  slice_head(n = 10) |>
  arrange(desc(stories))

swift_weekly <- weekly_data |>
  filter(category == "Taylor Swift Only") |>
  select(week, swift_only = stories)

kelce_weekly <- weekly_data |>
  filter(category == "Travis Kelce Only") |>
  select(week, kelce_only = stories)

joint_weekly_clean <- weekly_data |>
  filter(category == "Joint Coverage") |>
  select(week, joint = stories)

overlap_data <- swift_weekly |>
  full_join(kelce_weekly, by = "week") |>
  full_join(joint_weekly_clean, by = "week") |>
  mutate(
    across(
      c(swift_only, kelce_only, joint),
      ~replace_na(.x, 0)
    ),
    swift_overlap = ifelse(
      swift_only + joint > 0,
      joint / (swift_only + joint) * 100,
      NA_real_
    ),
    kelce_overlap = ifelse(
      kelce_only + joint > 0,
      joint / (kelce_only + joint) * 100,
      NA_real_
    )
  )

total_swift_coverage <- sum(
  swift_data$count,
  na.rm = TRUE
) + sum(
  joint_data$count,
  na.rm = TRUE
)

total_kelce_coverage <- sum(
  kelce_data$count,
  na.rm = TRUE
) + sum(
  joint_data$count,
  na.rm = TRUE
)

total_joint_coverage <- sum(
  joint_data$count,
  na.rm = TRUE
)

swift_overlap_total <- total_joint_coverage /
  total_swift_coverage * 100

kelce_overlap_total <- total_joint_coverage /
  total_kelce_coverage * 100


## ----data-status--------------------------------------------------------------------------------------------------------

if (data_available) {

  cat("Data collection was successful. The analysis below uses the retrieved Media Cloud results.")

} else {

  cat("The Media Cloud data could not currently be retrieved. This may be due to API rate limits or a connection issue. The visualizations and statistical findings will appear once the data is available. Previously cached results will be used automatically if available.")

}


## ----weekly-coverage----------------------------------------------------------------------------------------------------

if (data_available) {

  plot_data <- weekly_data |>
    mutate(
      category = factor(
        category,
        levels = c(
          "Taylor Swift Only",
          "Travis Kelce Only",
          "Joint Coverage"
        )
      )
    )

  plot_ly(
    data = plot_data,
    x = ~week,
    y = ~stories,
    color = ~category,
    type = "scatter",
    mode = "lines+markers",
    hovertemplate = paste(
      "Week: %{x|%B %d, %Y}",
      "<br>Stories: %{y}",
      "<extra></extra>"
    )
  ) |>
    layout(
      title = "Weekly Coverage of Taylor Swift and Travis Kelce",
      xaxis = list(
        title = "Week"
      ),
      yaxis = list(
        title = "Number of News Stories"
      ),
      legend = list(
        title = list(text = "Coverage Category")
      )
    )

}


## ----relationship-overlap-----------------------------------------------------------------------------------------------

if (data_available) {

  overlap_long <- overlap_data |>
    select(
      week,
      swift_overlap,
      kelce_overlap
    ) |>
    pivot_longer(
      cols = c(swift_overlap, kelce_overlap),
      names_to = "category",
      values_to = "percentage"
    ) |>
    mutate(
      category = recode(
        category,
        swift_overlap = "Taylor Swift Coverage Mentioning Kelce",
        kelce_overlap = "Travis Kelce Coverage Mentioning Swift"
      )
    )

  plot_ly(
    data = overlap_long,
    x = ~week,
    y = ~percentage,
    color = ~category,
    type = "scatter",
    mode = "lines+markers",
    hovertemplate = paste(
      "Week: %{x|%B %d, %Y}",
      "<br>Percentage: %{y:.1f}%",
      "<extra></extra>"
    )
  ) |>
    layout(
      title = "Percentage of Individual Coverage Connected to Their Relationship",
      xaxis = list(
        title = "Week"
      ),
      yaxis = list(
        title = "Percentage of Coverage",
        ticksuffix = "%",
        rangemode = "tozero"
      )
    )

}


## ----overall-percentages------------------------------------------------------------------------------------------------

if (data_available) {

  overall_overlap <- tibble(
    Individual = c(
      "Taylor Swift",
      "Travis Kelce"
    ),
    `Coverage Mentioning the Other Person` = c(
      swift_overlap_total,
      kelce_overlap_total
    )
  )

  kable(
    overall_overlap |>
      mutate(
        `Coverage Mentioning the Other Person` =
          percent(
            `Coverage Mentioning the Other Person` / 100,
            accuracy = 0.1
          )
      ),
    caption = "Percentage of Individual Coverage Mentioning the Other Person"
  )

}


## ----peak-weeks---------------------------------------------------------------------------------------------------------

if (data_available) {

  peak_weeks |>
    transmute(
      Week = format(week, "%B %d, %Y"),
      `Joint Stories` = stories
    ) |>
    kable(
      caption = "Top Ten Weeks for Joint Media Coverage"
    )

}


## ----findings, results='asis'-------------------------------------------------------------------------------------------

if (data_available) {

  swift_total <- sum(
    swift_data$count,
    na.rm = TRUE
  )

  kelce_total <- sum(
    kelce_data$count,
    na.rm = TRUE
  )

  joint_total <- sum(
    joint_data$count,
    na.rm = TRUE
  )

  peak_joint_week <- joint_weekly |>
    slice_max(stories, n = 1, with_ties = FALSE)

  cat(
    "During the study period, Media Cloud recorded ",
    comma(swift_total),
    " stories mentioning Taylor Swift without Travis Kelce, ",
    comma(kelce_total),
    " stories mentioning Travis Kelce without Taylor Swift and ",
    comma(joint_total),
    " stories mentioning both individuals. ",
    sep = ""
  )

  cat(
    "The week with the highest joint coverage began on ",
    format(peak_joint_week$week, "%B %d, %Y"),
    " and included ",
    comma(peak_joint_week$stories),
    " stories mentioning both individuals.",
    sep = ""
  )

  cat(
    "\n\nAcross the entire study period, ",
    round(swift_overlap_total, 1),
    "% of coverage mentioning Taylor Swift also mentioned Travis Kelce, while ",
    round(kelce_overlap_total, 1),
    "% of coverage mentioning Travis Kelce also mentioned Taylor Swift.",
    sep = ""
  )

} else {

  cat(
    "The findings section will be completed after the Media Cloud data is successfully retrieved. The final analysis will compare the total number of stories in each category, examine changes in weekly coverage and identify the weeks with the greatest joint coverage."
  )

}