Rationale

The first-level agenda-setting theory explains how the media influences what issues the public perceives as most important. According to this theory, the more frequently and prominently a topic is covered by the media, the more likely people are to consider that issue significant. In other words, the media doesn’t tell audiences what to think, but rather what to think about. By choosing which stories to highlight and how much attention to give them. Therefore, news organizations shape the public agenda guiding collective attention toward certain political, social, or economic problems. This process plays a crucial role in public opinion formation and in setting the priorities of both citizens and policymakers.

Based on the hypothesis of this theory, my project will compare the media coverage of two issues: The death of Charlie Kirk and the death of Minnesota state representative Melissa Hortman. Specifically, the analysis will compare the number of stories per week that APNews.com published about each issue between January 1st and September 30, 2025.   

The results will enhance theoretical understanding of how similar but yet different issues, a death of a political podcaster versus the death of a state representative, compete for attention on the media agenda. v

Hypothesis

Weekly APNews.com coverage volume for the death of Charlie Kirk was higher than the coverage for the death of Melissa Hortman.

Variables & method

Weekly APNews.com coverage volume of the twp deaths served as the analysis’s dependent variable. It was measured continuously as the number of stories published per week. The independent variable was the “story topic” measured categorically as either “Charlie Kirk” or “Melissa Hortman”. Key phrases and words used to identify stories about Charkie Kirk were: “Charlie Kirk,” “Turning Point,” and “Utah Valley University”. Key words for stories about Melissa Hortman were: “Melissa Hortman” and “John Hoffman.”

Results & discussion

The results of the analysis are displayed in an interactive line chart showing weekly counts of AP News articles that mentioned either Charlie Kirk or Melissa Hortman. The visualization revealed variation in the number of stories published about each topic from week to week, reflecting fluctuations in the amount of media attention devoted to each. Periods where one line spiked above the other indicated weeks when that topic received heightened coverage, suggesting an increase in its salience within the media agenda. Weeks with few or no mentions represented times when that issue received little to no media attention, reducing its visibility to the public.

Interpreted through the lens of the first-level agenda-setting theory, these results illustrate how the frequency of media coverage can influence which issues the public perceives as most important. The consistent or increased mention of one topic over another indicates that the media prioritized certain issues or individuals, thereby shaping public awareness and potentially influencing political discourse. Spikes in coverage likely correspond to specific events or developments related to each topic that temporarily raised their news value. Overall, this analysis demonstrates that by tracking and visualizing article frequency over time, it is possible to observe the agenda-setting effects of media coverage and better understand how attention to specific topics fluctuates within the news cycle.

Code:

# ============================================
# --- Load required libraries ---
# ============================================

if (!require("tidyverse")) install.packages("tidyverse")
if (!require("tidytext")) install.packages("tidytext")

library(tidyverse)
library(tidytext)

# ============================================
# --- Load the APNews data ---
# ============================================

# Read the data from the web
FetchedData <- readRDS(url("https://github.com/drkblake/Data/raw/refs/heads/main/APNews.rds"))
# Save the data on your computer
saveRDS(FetchedData, file = "APNews.rds")
# remove the downloaded data from the environment
rm (FetchedData)

APNews <- readRDS("APNews.rds")

# ============================================
# --- Flag Topic1-related stories ---
# ============================================

# --- Define Topic1 phrases ---
phrases <- c(
  "Charlie Kirk",
  "Turning Point",
  "Utah Valley University"
)

# --- Escape regex special characters ---
escaped_phrases <- str_replace_all(
  phrases,
  "([\\^$.|?*+()\\[\\]{}\\\\])",
  "\\\\\\1"
)

# --- Build whole-word/phrase regex pattern ---
pattern <- paste0("\\b", escaped_phrases, "\\b", collapse = "|")

# --- Apply matching to flag Topic1 stories ---
APNews <- APNews %>%
  mutate(
    Full.Text.clean = str_squish(Full.Text),  # normalize whitespace
    Topic1 = if_else(
      str_detect(Full.Text.clean, regex(pattern, ignore_case = TRUE)),
      "Yes",
      "No"
    )
  )

# ============================================
# --- Flag Topic2-related stories ---
# ============================================

# --- Define Topic2 phrases ---
phrases <- c(
  "Melissa Hortman",
  "John Hoffman"
)

# --- Escape regex special characters ---
escaped_phrases <- str_replace_all(
  phrases,
  "([\\^$.|?*+()\\[\\]{}\\\\])",
  "\\\\\\1"
)

# --- Build whole-word/phrase regex pattern ---
pattern <- paste0("\\b", escaped_phrases, "\\b", collapse = "|")

# --- Apply matching to flag Topic2 stories ---
APNews <- APNews %>%
  mutate(
    Full.Text.clean = str_squish(Full.Text),
    Topic2 = if_else(
      str_detect(Full.Text.clean, regex(pattern, ignore_case = TRUE)),
      "Yes",
      "No"
    )
  )

# ============================================
# --- Visualize weekly counts of Topic1- and Topic2-related stories ---
# ============================================

# --- Load plotly if needed ---
if (!require("plotly")) install.packages("plotly")
library(plotly)

# --- Summarize weekly counts for Topic1 = "Yes" ---
Topic1_weekly <- APNews %>%
  filter(Topic1 == "Yes") %>%
  group_by(Week) %>%
  summarize(Count = n(), .groups = "drop") %>%
  mutate(Topic = "Charlie Kirk") # Note custom Topic1 label

# --- Summarize weekly counts for Topic2 = "Yes" ---
Topic2_weekly <- APNews %>%
  filter(Topic2 == "Yes") %>%
  group_by(Week) %>%
  summarize(Count = n(), .groups = "drop") %>%
  mutate(Topic = "Melissa Hortman") # Note custom Topic2 label

# --- Combine both summaries into one data frame ---
Weekly_counts <- bind_rows(Topic2_weekly, Topic1_weekly)

# --- Fill in missing combinations with zero counts ---
Weekly_counts <- Weekly_counts %>%
  tidyr::complete(
    Topic,
    Week = full_seq(range(Week), 1),  # generate all week numbers
    fill = list(Count = 0)
  ) %>%
  arrange(Topic, Week)

# --- Create interactive plotly line chart ---
AS1 <- plot_ly(
  data = Weekly_counts,
  x = ~Week,
  y = ~Count,
  color = ~Topic,
  colors = c("steelblue", "firebrick"),
  type = "scatter",
  mode = "lines+markers",
  line = list(width = 2),
  marker = list(size = 6)
) %>%
  layout(
    title = "Weekly Counts of Topic1- and Topic2-Related AP News Articles",
    xaxis = list(
      title = "Week Number (starting with Week 1 of 2025)",
      dtick = 1
    ),
    yaxis = list(title = "Number of Articles"),
    legend = list(title = list(text = "Topic")),
    hovermode = "x unified"
  )

# ============================================
# --- Show the chart ---
# ============================================

AS1