library(readr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidytext)
library(ggplot2)

posts <- read_csv(
  "Bluesky_cleaned_text_analysis.csv",
  show_col_types = FALSE
)

top_words <- posts %>%
  filter(!is.na(text_clean), text_clean != "") %>%
  unnest_tokens(word, text_clean) %>%
  anti_join(stop_words, by = "word") %>%
  filter(!word %in% c("amazon", "delivery")) %>%
  count(word, sort = TRUE) %>%
  slice_max(order_by = n, n = 10, with_ties = FALSE)

ggplot(top_words, aes(x = reorder(word, n), y = n)) +
  geom_col(fill = "#4B84B8") +
  coord_flip() +
  labs(
    title = "Most frequent words in Bluesky posts",
    subtitle = "Common words and the search terms were removed",
    x = NULL,
    y = "Word occurrences"
  ) +
  theme_minimal()