Online news outlets published more coverage of Republican presidential candidate Donald Trump than of Democratic rival Kamala Harris throughout most of the 2024 election, an analysis of GDELT data shows.
This chart compares daily counts of online articles mentioning “Donald Trump” and “Kamala Harris” between July 1, 2024, shortly before Democratic Harris entered the race, and Nov. 6, 2024, the day Harris conceded the race to Trump. “Volume” values are the number of articles published per day in all U.S.-based online news outlets tracked by GDELT.
The agenda setting theory of mass communication suggests that media coverage volume about topic can influence the amount of attention the public pays to the topic. Other factors may affect the development of public opinions about the topic, though.
Here is the R script that gathered the data and produced the chart:
# Installing and loading the tidyverse package
if (!require("tidyverse"))
install.packages("tidyverse")
if (!require("plotly"))
install.packages("plotly")
if (!require("readr"))
install.packages("readr")
library(tidyverse)
library(plotly)
library(readr)
# Specifying date range
startdate <- "20240701"
enddate <- "20241106"
# Gathering data for Topic A
query <- "'Donald Trump' SourceCountry:US"
#Building the Volume dataframe
vp1 <- "https://api.gdeltproject.org/api/v2/doc/doc?query="
vp2 <- "&mode=timelinevolraw&startdatetime="
vp3 <- "000000&enddatetime="
vp4 <- "000000&format=CSV"
text_v_url <- paste0(vp1, query, vp2, startdate, vp3, enddate, vp4)
v_url <- URLencode(text_v_url)
v_url
Volume <- read_csv(v_url)
Volume$Date <- as.Date(Volume$Date, "%Y-%m-%d")
Volume <- Volume %>%
filter(Series == "Article Count")
VolumeA <- Volume
# Gathering data for Topic B
query <- "'Kamala Harris' SourceCountry:US"
#Building the Volume dataframe
vp1 <- "https://api.gdeltproject.org/api/v2/doc/doc?query="
vp2 <- "&mode=timelinevolraw&startdatetime="
vp3 <- "000000&enddatetime="
vp4 <- "000000&format=CSV"
text_v_url <- paste0(vp1, query, vp2, startdate, vp3, enddate, vp4)
v_url <- URLencode(text_v_url)
v_url
Volume <- read_csv(v_url)
Volume$Date <- as.Date(Volume$Date, "%Y-%m-%d")
Volume <- Volume %>%
filter(Series == "Article Count")
VolumeB <- Volume
# Merging Topic A and Topic B data
VolumeAB <- merge(VolumeA, VolumeB, by = "Date")
VolumeAB$VolumeA <- VolumeAB$Value.x
VolumeAB$VolumeB <- VolumeAB$Value.y
#Creating a plot called "fig" that plots volume by date
fig <- plot_ly(
data = VolumeAB,
x = ~Date,
y = ~VolumeA,
name = 'Trump',
type = 'scatter',
mode = 'lines',
line = list(color = "#AE2012")
) %>%
add_trace(
y = ~VolumeB,
name = 'Harris',
mode = 'lines',
line = list(color = "#005F73")
) %>%
layout(
title = 'U.S. coverage volume',
xaxis = list(title = "Date", showgrid = FALSE),
yaxis = list(title = "Volume", showgrid = TRUE)
)
# Displaying the plot
fig
### Saving the data to a local .csv file
write_csv(VolumeAB, "VolumeAB.csv")