I used AI tools to assist in creating and recreating the original R Markdown (RMD) file for this project. AI was also used to help organize the code, improve documentation, and troubleshoot potential errors. The analysis, interpretation of results, and final review were conducted to ensure the accuracy and relevance of the project.
```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)
library(tidyverse) library(lubridate) library(tidytext) library(plotly) library(DT)
# Reflection
*(Draft notes based on how this analysis went. Rewrite in your own words.)*
Using an AI assistant made it fast to get a complete, organized starting point
for the analysis: combining five files, cleaning them, and drafting the text
analysis, sentiment analysis and plotly charts. Detailed, specific prompts
(naming the keywords, the five files, and the week-by-week goal) produced much
more relevant code than a general request would have.
**Challenges**
* The first draft of any AI code has to be checked against the real data. Here
that meant noticing mixed timestamp formats, blank `created_at` values,
duplicate posts, and keyword matches that need whole-word boundaries.
* The Bing sentiment lexicon treats "trump" as a positive word, which is wrong
for political posts. The code would never have flagged this by itself.
* The data itself limits the question: each file is one day of about 100
posts, and the keyword searched changes by week (see Data Overview).
**Opportunities**
* AI gave a clear structure (introduction, data preparation, analysis,
verification) and suggested methods such as TF-IDF that I might not have
chosen myself.
* It made the work more manageable, while I still had to verify the output and
decide what the results can and cannot support.
# Introduction
This report combines five Bluesky exports into one tidy dataset and compares
**what changed from week to week** for three search keywords: `meta`,
`commercials` and `algorithm`. For each week it looks at:
1. Volume of posts and how often each keyword appears
2. Most frequent and most *distinctive* words (text analysis)
3. Sentiment (Bing lexicon)
4. Engagement (likes, reposts, replies, quotes)
It then verifies the AI-written code with spot checks and hand calculations
and critiques what the results can support.
# Data Overview
| File | Week | Collected by | Notes |
|------|------|--------------|-------|
| `my_post__3_.csv` | 9 | my_post | Same date as Week 9 (2026-10-22); the only file with `algorithm` posts |
| `Joelyne_Week9.csv` | 9 | Joelyne | Mostly `meta` posts |
| `Joelyne_Week10.csv` | 10 | Joelyne | Mostly `meta` posts |
| `Joelyne_Week11.csv` | 11 | Joelyne | Mostly `meta` posts |
| `Tais_week12.csv` | 12 | Tais | Mostly `commercials` posts |
All files share the same 23 columns (post text, author, engagement counts,
timestamps, language, and so on).
> **Read this before interpreting any trend.** Each weekly file is a single
> day's collection capped at roughly 100 posts, and different keywords were
> searched in different weeks. Differences between weeks therefore mix real
> change with *how the data was collected*. See the Critique section.
# Data Preparation
## Combine the five files
Edit the `file` column if your file names differ. `week` and `collector` are
assigned from the file name. `my_post` was collected on the same date as
Week 9 (2026-10-22), so it is labelled Week 9 and kept identifiable through
`source_file`.
```{r load}
file_key <- tribble(
~file, ~week, ~collector,
"my_post__3_.csv", 9, "my_post (algorithm search)",
"Joelyne_Week9.csv", 9, "Joelyne",
"Joelyne_Week10.csv", 10, "Joelyne",
"Joelyne_Week11.csv", 11, "Joelyne",
"Tais_week12.csv", 12, "Tais"
) %>%
mutate(path = file.path(params$data_dir, file))
stopifnot(all(file.exists(file_key$path)))
# Read everything as character first so columns with mixed types
# (e.g. `mentions`, `labels`) cannot break the row-binding.
read_one <- function(path, file, week, collector) {
read_csv(path, col_types = cols(.default = col_character())) %>%
mutate(source_file = file, week = week, collector = collector)
}
raw <- pmap_dfr(
list(file_key$path, file_key$file, file_key$week, file_key$collector),
read_one
)
glimpse(raw)
Decisions made here (change them if you disagree):
created_at values are blank.
parse_date_time() handles both formats, and blank values
fall back to indexed_at.uri and
then by identical text (repeated copy-paste posts would otherwise
inflate keyword counts).text is kept.meta does not match “metadata” or
“metaverse”. commercials? and algorithms? also
match the plural forms.```{r clean} keyword_patterns <- c( meta = “\bmeta\b”, commercials = “\bcommercials?\b”, algorithm = “\balgorithms?\b” )
num_cols <- c(“reply_count”, “repost_count”, “like_count”, “quote_count”, “bookmark_count”)
attrition <- tibble(step = “Raw rows (all files)”, n = nrow(raw))
step1 <- raw %>% filter(!is.na(text) & str_squish(text) != ““) attrition <- add_row(attrition, step =”After dropping empty text”, n = nrow(step1))
step2 <- step1 %>% distinct(uri, .keep_all = TRUE) attrition <- add_row(attrition, step = “After removing duplicate uri”, n = nrow(step2))
step3 <- step2 %>% mutate(text_key = str_squish(str_to_lower(text))) %>% distinct(text_key, .keep_all = TRUE) %>% select(-text_key) attrition <- add_row(attrition, step = “After removing identical text”, n = nrow(step3))
posts <- step3 %>% mutate( across(all_of(num_cols), ~ replace_na(as.integer(.x), 0L)), created_ts = parse_date_time(created_at, orders = c(“Ymd HMOS”, “Ymd HMS”), tz = “UTC”, quiet = TRUE), indexed_ts = parse_date_time(indexed_at, orders = c(“Ymd HMOS”, “Ymd HMS”), tz = “UTC”, quiet = TRUE), post_ts = coalesce(created_ts, indexed_ts), post_date = as_date(post_ts), week_label = factor(paste(“Week”, week), levels = paste(“Week”, sort(unique(week)))), engagement = like_count + repost_count + reply_count + quote_count, is_english = str_detect(replace_na(langs, ““),”\ben\b”), clean_text = text %>% str_replace_all(“&”, “&”) %>% str_remove_all(“https?://\S+|www\.\S+”) %>% str_remove_all(“@[\w.]+”) %>% str_remove_all(“#”) %>% str_squish(), has_meta = str_detect(text, regex(keyword_patterns[“meta”], ignore_case = TRUE)), has_commercials = str_detect(text, regex(keyword_patterns[“commercials”], ignore_case = TRUE)), has_algorithm = str_detect(text, regex(keyword_patterns[“algorithm”], ignore_case = TRUE)) ) %>% select(uri, author_handle, week, week_label, collector, source_file, post_ts, post_date, text, clean_text, langs, is_english, all_of(num_cols), engagement, has_meta, has_commercials, has_algorithm)
attrition
```{r save-combined}
write_csv(posts, file.path(params$data_dir, "bluesky_combined_clean.csv"))
bluesky_combined_clean.csv now holds one row per post,
with a consistent week, a parsed timestamp, keyword flags,
and engagement totals.
{r preview} posts %>% select(week, author_handle, post_date, text, like_count, has_meta, has_commercials, has_algorithm) %>% datatable(options = list(pageLength = 5, scrollX = TRUE))
```{r keyword-long} keyword_long <- posts %>% pivot_longer(starts_with(“has_”), names_to = “keyword”, values_to = “hit”, names_prefix = “has_”) %>% filter(hit)
week_totals <- posts %>% count(week_label, name = “total_posts”)
keyword_week <- keyword_long %>% count(week_label, keyword, name = “posts_with_keyword”) %>% complete(week_label, keyword, fill = list(posts_with_keyword = 0L)) %>% left_join(week_totals, by = “week_label”) %>% mutate(share = posts_with_keyword / total_posts)
keyword_week %>% mutate(share = scales::percent(share, accuracy = 0.1)) %>% arrange(week_label, keyword)
A single post can mention more than one keyword, so rows are not mutually
exclusive.
```{r plot-keywords}
plot_ly(keyword_week, x = ~week_label, y = ~share, color = ~keyword,
type = "bar",
text = ~paste0(posts_with_keyword, " of ", total_posts, " posts"),
hovertemplate = "%{x}<br>%{fullData.name}: %{y:.1%}<br>%{text}<extra></extra>") %>%
layout(barmode = "group",
title = "Share of collected posts that mention each keyword",
xaxis = list(title = ""),
yaxis = list(title = "Share of posts", tickformat = ".0%"))
Stop words, numbers, and the three search keywords themselves are removed (the keywords would otherwise dominate every table). Only English posts are used.
```{r tokens} custom_stop <- tibble(word = c(“meta”, “commercial”, “commercials”, “algorithm”, “algorithms”, “amp”, “bsky”, “app”, “https”, “http”, “www”, “com”, “rt”))
tokens <- posts %>% filter(is_english) %>% select(uri, week_label, clean_text) %>% unnest_tokens(word, clean_text) %>% filter(!str_detect(word, “^\d+$”), nchar(word) > 2) %>% anti_join(stop_words, by = “word”) %>% anti_join(custom_stop, by = “word”)
top_words <- tokens %>% count(week_label, word, sort = TRUE) %>% group_by(week_label) %>% slice_max(n, n = 10, with_ties = FALSE) %>% ungroup()
top_words %>% group_by(week_label) %>% summarise(top_10 = paste0(word, ” (“, n,”)“, collapse =”, “))
```{r plot-top-words, fig.height=7}
ggplot(top_words, aes(reorder_within(word, n, week_label), n)) +
geom_col(fill = "steelblue") +
coord_flip() +
scale_x_discrete(labels = function(x) str_remove(x, "___.*$")) +
facet_wrap(~week_label, scales = "free_y") +
labs(x = NULL, y = "Count", title = "Top 10 words per week (English posts)")
Raw counts mostly show words common in every week. TF-IDF treats each week as a “document” and surfaces words that are unusually frequent in one week compared with the others.
```{r tfidf, fig.height=7} tfidf <- tokens %>% count(week_label, word) %>% bind_tf_idf(word, week_label, n) %>% filter(n >= 2) %>% # ignore words that appear only once group_by(week_label) %>% slice_max(tf_idf, n = 8, with_ties = FALSE) %>% ungroup()
ggplot(tfidf, aes(reorder_within(word, tf_idf, week_label), tf_idf)) + geom_col(fill = “darkorange”) + coord_flip() + scale_x_discrete(labels = function(x) str_remove(x, “___.*$“)) + facet_wrap(~week_label, scales =”free_y”) + labs(x = NULL, y = “TF-IDF”, title = “Most distinctive words per week”)
## Sentiment analysis
Method: the **Bing** lexicon labels words as positive or negative. For each
English post, `net_sentiment = positive words - negative words`. Posts with no
lexicon words score 0 ("neutral"), and non-English posts are excluded because
the lexicon is English-only.
```{r sentiment}
bing <- get_sentiments("bing") %>%
filter(word != "trump") # Bing lists "trump" as positive (the verb); in this
# political data it is almost always a name.
post_sent <- tokens %>%
inner_join(bing, by = "word", relationship = "many-to-many") %>%
count(uri, sentiment) %>%
pivot_wider(names_from = sentiment, values_from = n, values_fill = 0)
posts_sent <- posts %>%
filter(is_english) %>%
left_join(post_sent, by = "uri") %>%
mutate(
positive = replace_na(positive, 0L),
negative = replace_na(negative, 0L),
net_sentiment = positive - negative,
label = case_when(net_sentiment > 0 ~ "positive",
net_sentiment < 0 ~ "negative",
TRUE ~ "neutral")
)
sent_week <- posts_sent %>%
group_by(week_label) %>%
summarise(
n_english = n(),
mean_net = mean(net_sentiment),
se = sd(net_sentiment) / sqrt(n()),
pct_positive = mean(label == "positive"),
pct_negative = mean(label == "negative"),
pct_neutral = mean(label == "neutral"),
.groups = "drop"
)
sent_week %>%
mutate(across(starts_with("pct_"), ~ scales::percent(.x, accuracy = 0.1)),
across(c(mean_net, se), ~ round(.x, 2)))
{r plot-sentiment-week} plot_ly(sent_week, x = ~week_label, y = ~mean_net, type = "scatter", mode = "lines+markers", error_y = ~list(array = 1.96 * se, color = "grey"), text = ~paste0("n = ", n_english), hovertemplate = "%{x}<br>Mean net sentiment: %{y:.2f}<br>%{text}<extra></extra>") %>% layout(title = "Average net sentiment per post, by week (95% interval)", xaxis = list(title = ""), yaxis = list(title = "Mean net sentiment (positive - negative words)", zeroline = TRUE))
```{r plot-sentiment-mix} sent_mix <- posts_sent %>% count(week_label, label) %>% group_by(week_label) %>% mutate(share = n / sum(n)) %>% ungroup()
plot_ly(sent_mix, x = ~week_label, y = ~share, color = ~label, colors
= c(negative = “#d9534f”, neutral = “#bbbbbb”, positive = “#5cb85c”),
type = “bar”, text = ~paste0(n, ” posts”), hovertemplate =
“%{x}
%{fullData.name}: %{y:.1%}
%{text}
### Sentiment by keyword within each week
Because keyword and week overlap heavily in this dataset, many cells are tiny.
Cells below `min_n` are marked and should not be interpreted.
```{r sentiment-keyword}
sent_kw <- posts_sent %>%
pivot_longer(starts_with("has_"), names_to = "keyword", values_to = "hit",
names_prefix = "has_") %>%
filter(hit) %>%
group_by(week_label, keyword) %>%
summarise(n_posts = n(), mean_net = mean(net_sentiment), .groups = "drop") %>%
mutate(low_n = n_posts < params$min_n)
sent_kw
{r plot-sentiment-keyword} plot_ly(filter(sent_kw, !low_n), x = ~week_label, y = ~mean_net, color = ~keyword, type = "scatter", mode = "lines+markers", text = ~paste0("n = ", n_posts), hovertemplate = "%{x}<br>%{fullData.name}: %{y:.2f}<br>%{text}<extra></extra>") %>% layout(title = paste0("Mean net sentiment by keyword (cells with n >= ", params$min_n, " only)"), xaxis = list(title = ""), yaxis = list(title = "Mean net sentiment"))
{r sentiment-drivers} tokens %>% inner_join(bing, by = "word", relationship = "many-to-many") %>% count(week_label, sentiment, word, sort = TRUE) %>% group_by(week_label, sentiment) %>% slice_max(n, n = 5, with_ties = FALSE) %>% summarise(top_words = paste0(word, " (", n, ")", collapse = ", "), .groups = "drop")
```{r engagement} eng_week <- posts %>% group_by(week_label) %>% summarise( n_posts = n(), mean_likes = mean(like_count), mean_reposts = mean(repost_count), mean_replies = mean(reply_count), median_engage = median(engagement), max_engage = max(engagement), .groups = “drop” )
eng_week %>% mutate(across(where(is.numeric), ~ round(.x, 2)))
```{r plot-engagement}
eng_week %>%
pivot_longer(c(mean_likes, mean_reposts, mean_replies),
names_to = "metric", values_to = "mean_count") %>%
plot_ly(x = ~week_label, y = ~mean_count, color = ~metric, type = "bar") %>%
layout(barmode = "group",
title = "Average engagement per post, by week",
xaxis = list(title = ""), yaxis = list(title = "Mean count per post"))
Engagement is heavily skewed (most posts get 0 likes), so the mean can be driven by one or two viral posts. Compare it with the median and max above before reading anything into a jump.
AI-written code is a draft, not a result. These checks are the minimum before trusting any number above.
```{r verify-rows} raw %>% count(source_file, name = “raw_rows”) %>% left_join(count(posts, source_file, name = “rows_kept”), by = “source_file”) %>% mutate(dropped = raw_rows - rows_kept)
stopifnot(sum(attrition\(n[1]) == nrow(raw), !any(duplicated(posts\)uri)))
**Check by hand:** do the raw row counts match what you see when you open each
CSV (minus the header)? Why were rows dropped, and is that reasonable?
## Do the weeks line up with the dates?
```{r verify-dates}
posts %>%
group_by(week_label, source_file) %>%
summarise(first = min(post_date, na.rm = TRUE),
last = max(post_date, na.rm = TRUE),
missing_ts = sum(is.na(post_ts)), .groups = "drop")
Each weekly file should fall on a different date, and
missing_ts should be 0 after the indexed_at
fallback.
```{r verify-keywords} # Recount with base R instead of stringr to confirm the same totals. check <- tibble( keyword = names(keyword_patterns), base_r = map_int(keyword_patterns, ~ sum(grepl(.x, posts\(text, ignore.case = TRUE, perl = TRUE))), pipeline = c(sum(posts\)has_meta), sum(posts\(has_commercials), sum(posts\)has_algorithm)) ) check stopifnot(all(check\(base_r == check\)pipeline))
set.seed(42) posts %>% pivot_longer(starts_with(“has_”), names_to = “keyword”, values_to = “hit”, names_prefix = “has_”) %>% filter(hit) %>% group_by(keyword) %>% slice_sample(n = 5) %>% ungroup() %>% select(keyword, week, text) %>% datatable(options = list(pageLength = 5, scrollX = TRUE))
**Check by hand:** is "meta" always Meta the company, or does it sometimes mean
something else? Are "commercials" TV ads, political ads, or something else?
## Sentiment: hand calculation
```{r verify-sentiment}
set.seed(7)
sample_ids <- posts_sent %>% slice_sample(n = 3) %>% pull(uri)
for (id in sample_ids) {
p <- posts_sent %>% filter(uri == id)
cat("\nPOST:", p$clean_text, "\n")
tokens %>% filter(uri == id) %>%
inner_join(bing, by = "word", relationship = "many-to-many") %>%
select(word, sentiment) %>% print()
cat("Pipeline says: positive =", p$positive, " negative =", p$negative,
" net =", p$net_sentiment, "\n")
}
Check by hand: read each post. Does the score match your own judgement of the tone? Where does it disagree (sarcasm, negation, quoted headlines)?
(About 200 words, in your own words. Suggested points: which weekly differences are large enough to mention; which are artifacts of the collection method; what the sentiment and TF-IDF results suggest about how people talk about Meta versus commercials versus the algorithm; and what you would collect next.)
Complete this section in your own words. Some limitations already visible in this dataset are listed to get you started.
Data collection
meta posts, Week 12 is almost entirely
commercials posts, and algorithm only appears
in the my_post file. A “trend” between weeks may just be a
change in topic or search term.Method
Your turn
Paste the prompt(s) you gave the AI and note what you had to refine:
| Prompt | What was missing or vague | Revised prompt |
|---|---|---|
{r session} sessionInfo()