Below are two tables showing the frequency of two themes within comments on a twitter post relating to Track and field outfits made by Nike. The first table shows the frequency of the theme of women coming up in these comments. The second table shows the frequency of the theme of the outfit design within these same comments.

Mentions of the topic
Topic Count Percent
0 3257 59.4
1 2222 40.6
Mentions of the topic
Topic Count Percent
0 3964 72.3
1 1515 27.7

Code:

  # Load packages
  
  if (!require("tidyverse")) install.packages("tidyverse")
  if (!require("tidytext")) install.packages("tidytext")
  if (!require("plotly")) install.packages("plotly")
  if (!require("gtExtras")) install.packages("gtExtras")
  
  library(tidyverse)
  library(tidytext)
  library(gtExtras) 
  library(plotly)
  library(lubridate)
  
  # Read the data
  
  mydata <- read.csv("https://raw.githubusercontent.com/drkblake/Data/main/NikeUniforms.csv")
  
  
    tidy_text <- mydata %>% 
    unnest_tokens(word,Full.Text) %>% 
    count(word, sort = TRUE)
  
  # Deleting standard stop words
  
  data("stop_words")
  tidy_text <- tidy_text %>%
    anti_join(stop_words)
  
  # Deleting custom stop words
  
  my_stopwords <- tibble(word = c("https",
                                  "t.co",
                                  "rt"))
  tidy_text <- tidy_text %>% 
    anti_join(my_stopwords)
  
  head(tidy_text, 25)
  
  searchterms <- "Women|woman|female"
  
  mydata$Topic <- ifelse(grepl(searchterms,
                               mydata$Full.Text,
                               ignore.case = TRUE),1,0)
  Topic <- mydata %>%
    group_by(Topic) %>%
    summarize(
      Count = n(),
      Percent = round(n() / nrow(mydata) * 100, 1)
    )
  
  TopicTable <- gt(Topic) %>% 
    tab_header("Mentions of the topic") %>%
    cols_align(align = "left") %>%
    gt_theme_538
  
  TopicTable1
  
  # Deleting custom stop words
  
  my_stopwords <- tibble(word = c("https",
                                  "t.co",
                                  "rt"))
  tidy_text <- tidy_text %>% 
    anti_join(my_stopwords)
  
  head(tidy_text, 25)
  
  searchterms <- " cut|wear|outfit|design"
  
  mydata$Topic <- ifelse(grepl(searchterms,
                               mydata$Full.Text,
                               ignore.case = TRUE),1,0)
  Topic <- mydata %>%
    group_by(Topic) %>%
    summarize(
      Count = n(),
      Percent = round(n() / nrow(mydata) * 100, 1)
    )
  
  TopicTable <- gt(Topic) %>% 
    tab_header("Mentions of the topic") %>%
    cols_align(align = "left") %>%
    gt_theme_538
  
  TopicTable2