This plot shows the number of stories per week between January and mid-August 2026 mentioning terms related to the wars in Gaza, Iran, and Ukraine.
The data were extracted from Media Cloud queries and analyzed using R.
Here is the R code that produced the plot.
############################################################
# 1. Install and load required packages
############################################################
if (!require(tidyverse)) install.packages("tidyverse")
if (!require(plotly)) install.packages("plotly")
library(tidyverse)
library(plotly)
############################################################
# 2. Download and read RDS file from GitHub
############################################################
url <- "https://github.com/drkblake/Data/raw/refs/heads/main/MediaCloudData.rds"
temp_file <- tempfile(fileext = ".rds")
download.file(
url,
temp_file,
mode = "wb"
)
MediaCloudData <- readRDS(
temp_file
)
############################################################
# 3. Convert data from wide to long format
############################################################
MediaCloudLong <- MediaCloudData %>%
pivot_longer(
cols = c(Iran, Gaza, Ukraine),
names_to = "Topic",
values_to = "Stories"
)
############################################################
# 4. Create Monday-based week variable
############################################################
MediaCloudLong <- MediaCloudLong %>%
mutate(
Week = as.Date(
cut(
Date,
breaks = "week",
start.on.monday = TRUE
)
)
)
############################################################
# 5. Aggregate daily counts to weekly totals
############################################################
MediaCloudWeekly <- MediaCloudLong %>%
group_by(Week, Topic) %>%
summarize(
Stories = sum(Stories),
.groups = "drop"
)
############################################################
# 6. Remove partial weeks at beginning and end
############################################################
MediaCloudWeekly <- MediaCloudWeekly %>%
filter(
Week > min(Week),
Week < max(Week)
)
############################################################
# 7. Create tooltip text
############################################################
MediaCloudWeekly <- MediaCloudWeekly %>%
mutate(
Tooltip = paste0(
"Topic: ", Topic,
"<br>Week Beginning: ", format(Week, "%Y-%m-%d"),
"<br>Stories: ", Stories
)
)
############################################################
# 8. Create interactive Plotly line chart
############################################################
Plot <- plot_ly(
data = MediaCloudWeekly,
x = ~Week,
y = ~Stories,
color = ~Topic,
type = "scatter",
mode = "lines+markers",
text = ~Tooltip,
hoverinfo = "text"
) %>%
layout(
title = "Weekly Story Counts",
xaxis = list(
title = "Week Beginning"
),
yaxis = list(
title = "Story Count"
),
legend = list(
title = list(
text = "Topic"
)
)
)
############################################################
# 9. Display chart
############################################################
Plot