Overview

The graph compares weekly media coverage of artificial intelligence and climate change from January 1, 2026, to September 1, 2026. The data were collected from a MediaCloud.org API, which tracks and aggregates content from online news sources. Throughout this period, climate change received relatively steady coverage, while artificial intelligence experienced larger fluctuations and more significant spikes in media attention. 

Artificial intelligence peaked in coverage during the week of May 10, 2026, with 2,342 stories, compared to 817 stories about climate change that same week. Climate change reached its highest weekly total on May 3, 2026, with 1,128 stories; however, artificial intelligence still had a greater showing that week with 2,043 stories. In total, artificial intelligence generated 56,690 stories during this study period, while climate change generated 29,640 stories, as shown in the summary table. 

These disparities may reflect growing public and media interest in technological advancements, new AI products, and discussions about the societal impacts of artificial intelligence. The results are significant because they highlight how certain issues receive considerably more media attention than others, potentially influencing the public’s perception of what topics are most important.

Coverage Summary by Topic
topic Total_Stories Weekly_Minimum Weekly_Maximum Weekly_Mean
Artificial Intelligence 56690 339 2342 1574.72
Climate Change 29640 170 1128 823.33

Code:

############################################################
# STEP 1: Install and Load Packages
############################################################

if (!require("tidyverse")) install.packages("tidyverse")
if (!require("httr2")) install.packages("httr2")
if (!require("lubridate")) install.packages("lubridate")
if (!require("kableExtra")) install.packages("kableExtra")
if (!require("plotly")) install.packages("plotly")

library(tidyverse)
library(httr2)
library(lubridate)
library(kableExtra)
library(plotly)

############################################################
# STEP 2: Verify Media Cloud API Key
############################################################

if (!nzchar(Sys.getenv("MEDIACLOUD_KEY"))) {
  stop(
    "No Media Cloud API key was found.\n",
    "Please save your key to .Renviron first."
  )
}

############################################################
# STEP 3: Define Two Topics
############################################################

# Replace the topic labels and search queries below.
#
# Examples:
# "artificial intelligence"
# "climate change"
# "immigration"
# "inflation"

topics <- c(
  "Artificial Intelligence" = "\"artificial intelligence\"",
  "Climate Change" = "\"climate change\""
)

############################################################
# STEP 4: Define the Date Range
############################################################

start_date <- "2026-01-01"
end_date <- "2026-09-01"

############################################################
# STEP 5: Create a Function to Download
# Daily Story Counts.
############################################################

get_counts <- function(query) {
  
  Sys.sleep(35)
  
  response <-
    request(
      "https://search.mediacloud.org/api/search/count-over-time"
    ) |>
    req_headers(
      Authorization = paste(
        "Token",
        Sys.getenv("MEDIACLOUD_KEY")
      )
    ) |>
    req_url_query(
      q = query,
      start = start_date,
      end = end_date,
      platform = "onlinenews-mediacloud",
      cs = 34412234
    ) |>
    req_perform()
  results <-
    response |>
    resp_body_json()
  map_dfr(
    results$count_over_time$counts,
    as_tibble
  ) |>
    mutate(
      date = as.Date(date)
    )
}

############################################################
# STEP 6: Download Data for Both Topics
############################################################

topic_data <-
  imap_dfr(
    topics,
    function(search_query, topic_name) {
      message("Downloading: ", topic_name)
      get_counts(search_query) |>
        mutate(
          topic = topic_name
        )
    }
  )

############################################################
# STEP 7: Examine the Downloaded Data
############################################################

head(topic_data)
glimpse(topic_data)

############################################################
# STEP 8: Calculate Weekly Story Counts
############################################################

weekly_counts <-
  topic_data |>
  mutate(
    week = floor_date(date, unit = "week")
  ) |>
  group_by(topic, week) |>
  summarise(
    stories = sum(count),
    .groups = "drop"
  )

############################################################
# STEP 9: Display Weekly Counts
############################################################

weekly_counts |>
  arrange(topic, week) |>
  kbl(
    caption = "Weekly Media Cloud Story Counts"
  ) |>
  kable_styling(
    full_width = FALSE,
    bootstrap_options = c(
      "striped",
      "hover"
    )
  )

############################################################
# STEP 10: Summarize Total Coverage
############################################################

topic_summary <-
  weekly_counts |>
  group_by(topic) |>
  summarise(
    Total_Stories = sum(stories),
    Weekly_Minimum = min(stories),
    Weekly_Maximum = max(stories),
    Weekly_Mean = round(mean(stories), 2),
    .groups = "drop"
  ) |>
  arrange(desc(Total_Stories))

Summary_Table <- topic_summary |>
  kbl(
    caption = "Coverage Summary by Topic"
  ) |>
  kable_styling(
    full_width = FALSE,
    bootstrap_options = c(
      "striped",
      "hover"
    )
  )

Summary_Table

############################################################
# STEP 11: Create an Interactive Plotly Line Graph
############################################################

# Create custom hover text with comma-formatted counts

weekly_counts <- weekly_counts |>
  mutate(
    Hover_Text = paste0(
      "<b>Topic:</b> ", topic,
      "<br><b>Stories:</b> ", format(stories, big.mark = ","),
      "<br><b>Week:</b> ", week
    )
  )

# Create Plotly graph

Plotly_Line_Graph <-
  plot_ly(
    data = weekly_counts,
    x = ~week,
    y = ~stories,
    color = ~topic,
    colors = "Set1",
    type = "scatter",
    mode = "lines+markers",
    text = ~Hover_Text,
    hovertemplate = "%{text}<extra></extra>"
  ) |>
  layout(
    title = list(
      text = "Weekly Media Coverage Volume<br><sup>Comparison of Two Topics</sup>"
    ),
    xaxis = list(
      title = "Week"
    ),
    yaxis = list(
      title = "Number of Stories",
      separatethousands = TRUE
    ),
    legend = list(
      title = list(
        text = "Topic"
      )
    ),
    hovermode = "x unified"
  ) |>
  config(
    displayModeBar = TRUE
  )

Plotly_Line_Graph

############################################################
# STEP 12: Save Results as a CSV File
############################################################

write_csv(
  weekly_counts,
  "weekly_story_counts.csv"
)