Scraping and Analyzing YouTube Comments Using Word Frequency Analysis

Data Source Description

For this analysis, I collected comments from Levi Hildebrand’s YouTube video “How Athleisure Wear TOOK OVER America,” which explores the growth and dynamics of the athleisure apparel industry. I selected this video because it discusses the overall athleisure market instead of comparing individual brands, keeping the comment data centered on consumer opinions about the category. Additionally, it connects to my previous lab work, where I analyzed athleisure brands and became interested in consumer perspectives on this product category.


Setup and Authentication

library(tuber)
library(dplyr)
library(readr)
library(tidytext)
library(stringr)
library(wordcloud)
library(RColorBrewer)
library(ggplot2)
library(SnowballC)

Credentials are stored in .Renviron (never hard-coded here) and loaded with Sys.getenv():

app_id     <- Sys.getenv("YOUTUBE_CLIENT_ID")
app_secret <- Sys.getenv("YOUTUBE_CLIENT_SECRET")

yt_oauth(app_id, app_secret)

Scraping the Comments

video_id <- "QZt9yDWFWM8"

comments1 <- get_all_comments(video_id = video_id)

head(comments1)
glimpse(comments1)

Cleaning the Data

comments1 <- comments1 %>%
  as_tibble() %>%
  distinct(id, .keep_all = TRUE) %>%
  select(authorDisplayName, textOriginal, publishedAt, likeCount, id)

write_csv(comments1, "athleisure_comments.csv")
comments_clean <- read_csv("athleisure_comments.csv")

nrow(comments_clean)
## [1] 749
head(comments_clean)
## # A tibble: 6 × 5
##   authorDisplayName  textOriginal            publishedAt         likeCount id   
##   <chr>              <chr>                   <dttm>                  <dbl> <chr>
## 1 @alvarodiamzon5069 "There's two persons i… 2026-01-15 10:29:13         0 Ugzz…
## 2 @joshs3916         "Now everyone looks li… 2025-12-09 03:12:52         0 Ugw_…
## 3 @aeromantics       "I was already feeling… 2025-12-08 17:48:51         0 Ugwk…
## 4 @buckwyld218       "If food doesn't kill … 2025-08-13 21:15:29         1 Ugxm…
## 5 @barryf5479        "200 pound \"whales\" … 2025-06-27 01:22:21         0 Ugy5…
## 6 @joshs3916         "😂"                    2025-12-09 03:22:38         0 Ugy5…

Summary of Collected Data

comments_clean %>%
  summarise(
    total_comments = n(),
    avg_likes = mean(likeCount, na.rm = TRUE),
    max_likes = max(likeCount, na.rm = TRUE)
  )
## # A tibble: 1 × 3
##   total_comments avg_likes max_likes
##            <int>     <dbl>     <dbl>
## 1            749      10.9      1285

Text Analysis: Word Frequency

custom_stopwords <- tibble(word = c("video", "youtube", "athleisure",
                                     "brand", "lol", "http", "https"))

word_freq <- comments_clean %>%
  unnest_tokens(word, textOriginal) %>%
  anti_join(stop_words, by = "word") %>%
  anti_join(custom_stopwords, by = "word") %>%
  filter(str_detect(word, "[a-z]")) %>%
  mutate(word = wordStem(word)) %>%
  count(word, sort = TRUE)

head(word_freq, 15)
## # A tibble: 15 × 2
##    word        n
##    <chr>   <int>
##  1 wear      347
##  2 cloth     289
##  3 gym       215
##  4 peopl     132
##  5 shirt      97
##  6 cotton     94
##  7 short      77
##  8 bui        75
##  9 comfort    70
## 10 athlet     68
## 11 pant       63
## 12 feel       62
## 13 workout    60
## 14 sweat      57
## 15 synthet    57
label_fix <- c(peopl = "people", athlet = "athletic", synthet = "synthetic",
               bui = "buy", cloth = "clothes", comfort = "comfortable",
               shirt = "shirt", short = "shorts", pant = "pants")

word_freq_display <- word_freq %>%
  mutate(word = recode(word, !!!label_fix))

head(word_freq_display, 15)
## # A tibble: 15 × 2
##    word            n
##    <chr>       <int>
##  1 wear          347
##  2 clothes       289
##  3 gym           215
##  4 people        132
##  5 shirt          97
##  6 cotton         94
##  7 shorts         77
##  8 buy            75
##  9 comfortable    70
## 10 athletic       68
## 11 pants          63
## 12 feel           62
## 13 workout        60
## 14 sweat          57
## 15 synthetic      57

Most Common Terms

word_freq_display %>%
  slice_max(n, n = 15) %>%
  ggplot(aes(x = reorder(word, n), y = n)) +
  geom_col(fill = "#2C7FB8") +
  coord_flip() +
  labs(title = "Top 15 Most Common Terms in Athleisure Video Comments",
       x = NULL, y = "Frequency") +
  theme_minimal()

Word Cloud

set.seed(42)
wordcloud(words = word_freq_display$word,
          freq = word_freq_display$n,
          max.words = 100,
          random.order = FALSE,
          colors = brewer.pal(8, "Dark2"))

Interpretation

The word frequency analysis shows that the most common comments on this YouTube video emphasize the product’s physical qualities over brand loyalty or price. Terms like wear, clothes, and gym are most prevalent. This indicates that consumers are now more interested in the product’s functionality rather than the brand itself.

Another noticeable theme involves sentiments about product quality, with words like cotton, synthetic, and sweat appearing alongside comfortable, feel, and workout. This indicates that commenters are actively comparing and assessing performance-wear. The brand Gymshark emerged organically in the word cloud, despite not being mentioned in the video title, suggesting that consumers associate this brand strongly with the perceived quality and performance of the product.