Below, the bar graph illustrates the 25 most common unigrams in headlines mentioning Donald Trump. The unigram analysis suggests that the most common themes associated with Donald Trump in news headlines are government, elections, the judiciary, foreign affairs, and public policy. After tokenizing the headlines and counting word frequencies, the most common terms included Iran, House, War, Court, White, GOP, AI, Senate, Democrats, and Supreme. These words indicate that coverage frequently focused on political institutions, legal proceedings, domestic governance, and international issues. The prominence of terms such as Court, Judge, and Supreme suggests that legal matters were a major component of media coverage, while terms such as Iran, War, and Military point to discussions of foreign policy and national security. Likewise, words such as House, Senate, GOP, Democrats, Election, and Midterms highlight the importance of electoral politics and partisan competition.
Several decisions were made regarding which words to exclude from the analysis. Common stop words were removed because they do not convey meaningful themes or topics. Social media artifacts such as “rt,” “amp,” “https,” “http,” and related web terms were also discarded because they resulted from the collection process rather than the content of the headlines. In addition, frequently occurring words directly related to Donald Trump, including “trump,” “trump’s,” “donald,” and “president,” were removed. Since every story in the dataset mentioned Trump at least once, these words added little analytical value. Terms such as “news,” “today,” “u.s.,” and “people” were also excluded because they were too general to indicate a specific topic. Removing these words allowed broader themes to emerge more clearly and revealed the issues most commonly associated with Trump in news coverage. The results suggest that news organizations frequently linked Trump to topics involving government institutions, legal proceedings, elections, and foreign affairs.
# =====================================================
# Load Packages
# =====================================================
library(tidyverse)
library(tidytext)
# =====================================================
# Step 1: Download and Load the Data
# =====================================================
download.file(
url = "https://github.com/drkblake/Data/raw/refs/heads/main/Trump_story_headlines.rds",
destfile = "Trump_story_headlines.rds",
mode = "wb"
)
headlines <- readRDS("Trump_story_headlines.rds")
# View variable names
names(headlines)
# =====================================================
# Step 2: Tokenize Headlines into Unigrams
# =====================================================
unigrams <- headlines %>%
select(title) %>%
unnest_tokens(word, title)
# =====================================================
# Step 3: Remove Stop Words and Social Media Artifacts
# =====================================================
data("stop_words")
unigrams_clean <- unigrams %>%
anti_join(stop_words, by = "word") %>%
filter(
!word %in% c(
"rt",
"amp",
"https",
"http",
"www",
"co",
"t",
"s"
)
)
# =====================================================
# Step 4: Remove Additional Common Words
# =====================================================
custom_words <- c(
"trump",
"trump's",
"trump’s",
"donald",
"president",
"says",
"said",
"say",
"new",
"news",
"today",
"one",
"would",
"could",
"us",
"u",
"u.s",
"people"
)
unigrams_clean <- unigrams_clean %>%
filter(!word %in% custom_words)
# =====================================================
# Step 5: Count Unigram Frequencies
# =====================================================
word_counts <- unigrams_clean %>%
count(word, sort = TRUE)
# Display the 25 most common words
head(word_counts, 25)
# =====================================================
# Step 6: Graph the Top 25 Most Common Unigrams
# =====================================================
TrumpHeadlines <- word_counts %>%
slice_max(n, n = 25) %>%
mutate(word = reorder(word, n)) %>%
ggplot(aes(x = word, y = n)) +
geom_col(fill = "steelblue") +
coord_flip() +
labs(
title = "Top 25 Most Common Unigrams in Trump Headlines",
x = "Unigram",
y = "Frequency"
) +
theme_minimal()
TrumpHeadlines