This project analyzes recent Bluesky posts mentioning CeraVe, a skincare brand. The purpose of the analysis is to identify common words and themes in the online conversation and evaluate the overall sentiment associated with CeraVe.
Artificial intelligence was used to help develop the R code for cleaning the data, conducting text and sentiment analysis, creating visualizations, and developing verification procedures. The results were then checked using summary statistics and individual posts.
The following prompt was used to guide the analysis:
Write R code for an R Markdown analysis of Bluesky posts mentioning CeraVe. Use the atrrr package to collect recent posts and use dplyr, stringr, tidytext, ggplot2, and plotly for the analysis. Remove missing and duplicate posts, tokenize the text, remove stop words, identify the most frequently used words, and use the Bing sentiment lexicon to identify positive and negative words. Calculate sentiment scores at the post level and classify posts as positive, negative, or neutral. Create summary tables, a common-word visualization, and an interactive Plotly sentiment chart. Include sanity checks and a sample of posts for manual verification. The final document should be suitable for an introductory marketing analytics course and publication on RPubs.
knitr::opts_chunk$set(
echo = TRUE,
message = FALSE,
warning = FALSE,
fig.width = 8,
fig.height = 5
)
# Packages needed for this project
packages <- c(
"atrrr",
"dplyr",
"tidyr",
"stringr",
"tidytext",
"ggplot2",
"plotly",
"readr",
"knitr"
)
# Install missing packages
missing_packages <- packages[
!(packages %in% rownames(installed.packages()))
]
if(length(missing_packages) > 0) {
install.packages(
missing_packages,
repos = "https://cloud.r-project.org"
)
}
# Load packages
library(atrrr)
library(dplyr)
library(tidyr)
library(stringr)
library(tidytext)
library(ggplot2)
library(plotly)
library(readr)
library(knitr)
Before running or knitting this document, I authenticated my Bluesky account in the RStudio Console using:
auth("betterdays06.bsky.social")
My password or app password is not included in this document.
The following code searches Bluesky for recent posts containing the keyword CeraVe.
# File used to save the scrape
data_file <- "CeraVe_Bluesky_Posts.csv"
# Scrape new data only if the CSV does not already exist
if (!file.exists(data_file)) {
cerave_raw <- search_post(
"CeraVe",
limit = 200
)
# Convert list columns before saving
cerave_save <- cerave_raw %>%
mutate(
across(
where(is.list),
~ sapply(
.,
function(x) paste(as.character(x), collapse = "; ")
)
)
)
write.csv(
cerave_save,
data_file,
row.names = FALSE
)
} else {
cerave_save <- read.csv(
data_file,
stringsAsFactors = FALSE
)
}
cat("Rows in original CeraVe dataset:", nrow(cerave_save))
## Rows in original CeraVe dataset: 272
Saving the original scrape is important because it allows the analysis to be reproduced without collecting a different group of posts every time the document is knitted.
Bluesky data can sometimes use slightly different column names
depending on the version of atrrr. The following code
automatically looks for the column containing the post text.
possible_text_columns <- c(
"text",
"Text",
"post",
"Post",
"record_text",
"post_text"
)
text_column <- possible_text_columns[
possible_text_columns %in% names(cerave_save)
][1]
if (is.na(text_column)) {
stop(
paste(
"A post text column could not be found.",
"Available columns are:",
paste(names(cerave_save), collapse = ", ")
)
)
}
cat("Post text column detected:", text_column)
## Post text column detected: text
The dataset is cleaned by keeping the post text, removing missing posts, removing blank posts, and removing duplicate text.
URLs and extra spaces are also removed from the text used for analysis.
cerave <- cerave_save %>%
transmute(
post_id = row_number(),
Post = as.character(.data[[text_column]])
) %>%
filter(
!is.na(Post),
str_trim(Post) != ""
) %>%
distinct(Post, .keep_all = TRUE) %>%
mutate(
clean_text = Post,
clean_text = str_remove_all(
clean_text,
"https?://\\S+"
),
clean_text = str_remove_all(
clean_text,
"@[A-Za-z0-9._-]+"
),
clean_text = str_replace_all(
clean_text,
"[\r\n]+",
" "
),
clean_text = str_squish(clean_text)
)
cat("Original posts:", nrow(cerave_save), "\n")
## Original posts: 272
cat("Clean unique posts:", nrow(cerave))
## Clean unique posts: 250
A basic sanity check was performed to make sure blank and duplicate posts were removed.
cleaning_check <- data.frame(
Check = c(
"Original rows",
"Clean rows",
"Missing post text",
"Duplicate post text"
),
Result = c(
nrow(cerave_save),
nrow(cerave),
sum(is.na(cerave$Post)),
sum(duplicated(cerave$Post))
)
)
kable(
cleaning_check,
caption = "Data Cleaning Verification"
)
| Check | Result |
|---|---|
| Original rows | 272 |
| Clean rows | 250 |
| Missing post text | 0 |
| Duplicate post text | 0 |
The cleaning check should show 0 missing post texts and 0 duplicate post texts in the final dataset.
For the text analysis, each post is separated into individual words
using unnest_tokens().
words <- cerave %>%
select(post_id, clean_text) %>%
unnest_tokens(
word,
clean_text
)
cat("Total word tokens:", nrow(words))
## Total word tokens: 6603
Common English words such as “the,” “and,” and “is” are not usually useful for identifying conversation themes. These stop words are removed.
The word “cerave” is also removed because every post was collected using the CeraVe search term.
data("stop_words")
clean_words <- words %>%
anti_join(
stop_words,
by = "word"
) %>%
filter(
!word %in% c(
"cerave",
"https",
"http",
"amp"
)
) %>%
filter(
!str_detect(word, "^[0-9]+$")
)
cat(
"Words remaining after removing stop words:",
nrow(clean_words)
)
## Words remaining after removing stop words: 4384
The following table shows the most frequently occurring meaningful words in the CeraVe posts.
word_frequency <- clean_words %>%
count(
word,
sort = TRUE
)
top_words <- word_frequency %>%
slice_head(n = 15)
kable(
top_words,
caption = "15 Most Common Words in CeraVe Bluesky Posts"
)
| word | n |
|---|---|
| de | 116 |
| por | 99 |
| hidratante | 89 |
| amazon | 68 |
| loção | 65 |
| corporal | 55 |
| ceramidas | 52 |
| facial | 50 |
| pele | 45 |
| la | 44 |
| skin | 43 |
| cream | 42 |
| 473ml | 38 |
| limpeza | 37 |
| para | 36 |
These words provide a simple overview of the topics and product characteristics people frequently discuss when mentioning CeraVe.
top_words %>%
ggplot(
aes(
x = reorder(word, n),
y = n
)
) +
geom_col() +
coord_flip() +
labs(
title = "Most Common Words in CeraVe Bluesky Posts",
x = "Word",
y = "Frequency"
) +
theme_minimal()
This chart makes it easier to identify the major terms appearing in the CeraVe conversation.
The Bing sentiment lexicon classifies individual words as either positive or negative.
bing <- get_sentiments("bing")
sentiment_words <- words %>%
inner_join(
bing,
by = "word"
)
sentiment_counts <- sentiment_words %>%
count(
sentiment,
sort = TRUE
)
kable(
sentiment_counts,
caption = "Positive and Negative Sentiment Word Counts"
)
| sentiment | n |
|---|---|
| positive | 144 |
| negative | 68 |
Counting sentiment words alone does not tell us how many posts are positive or negative. Therefore, I calculated a sentiment score for each post.
Positive words receive a value of +1 and negative words receive a value of -1.
The values are added together for each post.
sentiment_scores <- sentiment_words %>%
mutate(
value = ifelse(
sentiment == "positive",
1,
-1
)
) %>%
group_by(post_id) %>%
summarise(
positive_words = sum(sentiment == "positive"),
negative_words = sum(sentiment == "negative"),
sentiment_score = sum(value),
.groups = "drop"
)
# Join sentiment scores back to ALL posts
post_sentiment <- cerave %>%
left_join(
sentiment_scores,
by = "post_id"
) %>%
mutate(
positive_words = replace_na(positive_words, 0),
negative_words = replace_na(negative_words, 0),
sentiment_score = replace_na(sentiment_score, 0),
sentiment = case_when(
sentiment_score > 0 ~ "Positive",
sentiment_score < 0 ~ "Negative",
TRUE ~ "Neutral"
)
)
cat(
"Posts classified:",
nrow(post_sentiment)
)
## Posts classified: 250
Posts with more positive than negative words are classified as Positive. Posts with more negative words are classified as Negative. Posts with equal positive and negative scores, including posts containing no Bing sentiment words, are classified as Neutral.
sentiment_summary <- post_sentiment %>%
count(sentiment) %>%
mutate(
percent = round(
n / sum(n) * 100,
1
)
)
kable(
sentiment_summary,
caption = "CeraVe Post Sentiment Results"
)
| sentiment | n | percent |
|---|---|---|
| Negative | 16 | 6.4 |
| Neutral | 174 | 69.6 |
| Positive | 60 | 24.0 |
One requirement of the assignment is to verify the AI-generated analysis rather than automatically accepting the results.
First, I checked whether every cleaned post received exactly one sentiment classification.
verification <- data.frame(
Test = c(
"Clean posts",
"Posts receiving sentiment classification",
"Difference",
"Positive + Negative + Neutral"
),
Result = c(
nrow(cerave),
nrow(post_sentiment),
nrow(cerave) - nrow(post_sentiment),
sum(sentiment_summary$n)
)
)
kable(
verification,
caption = "Sentiment Analysis Sanity Check"
)
| Test | Result |
|---|---|
| Clean posts | 250 |
| Posts receiving sentiment classification | 250 |
| Difference | 0 |
| Positive + Negative + Neutral | 250 |
The number of classified posts should equal the number of cleaned posts. The difference should therefore equal 0.
I also selected posts containing sentiment words so that the automated calculation could be checked manually.
manual_check <- post_sentiment %>%
filter(
positive_words + negative_words > 0
) %>%
select(
post_id,
Post,
positive_words,
negative_words,
sentiment_score,
sentiment
) %>%
slice_head(n = 5)
kable(
manual_check,
caption = "Sample Posts for Manual Sentiment Verification"
)
| post_id | Post | positive_words | negative_words | sentiment_score | sentiment |
|---|---|---|---|---|---|
| 4 | Oh and a butternut squash. Thanks to Moon Valley Farm for the generous CSA box portions; all mistakes are my own inability to judge sizes and portions. See also the 8” broom to clean our hall ceiling and the time I ordered a pound of Cerave. | 2 | 3 | -1 | Negative |
| 10 | From Ralph Lauren embracing Americana in all its complexity to | ||||
| Sesame Workshop’s videos helping families prepare for bad weather to Cerave’s cheeky partnership with the NBA, these honorees represent branding at its best. | 2 | 1 | 1 | Positive | |
| 12 | This year I’m thankful for Cerave (not sponsored) | 1 | 0 | 1 | Positive |
| 14 | Hidratação diária com fórmula sem perfume, ideal pra incluir no cuidado com a pele |
Loção Hidratante Sem Perfume 473ml CeraVe | 1| 0| 1|Positive | | 18|pretty much everything on the BDS consumer boycott list
plus a few that aren’t, for similar reasons ex. cerave supports israel and still does animal testing so i swapped my moisturizer to gold bond (still owned by unilever tho unfort.)
chik-fil-a (i’m a gay trans vegetarian why would i eat there?) | 3| 1| 2|Positive |
For example, a post containing two positive Bing words and one negative Bing word should have:
2 - 1 = +1
Because the score is greater than zero, the post should be classified as Positive.
This provides a simple hand calculation that can be compared with the R output.
The following interactive chart shows the number of positive, negative, and neutral CeraVe posts.
sentiment_plot <- ggplot(
sentiment_summary,
aes(
x = sentiment,
y = n,
text = paste0(
"Sentiment: ", sentiment,
"<br>Posts: ", n,
"<br>Percent: ", percent, "%"
)
)
) +
geom_col() +
labs(
title = "Sentiment of CeraVe Posts on Bluesky",
x = "Sentiment",
y = "Number of Posts"
) +
theme_minimal()
ggplotly(
sentiment_plot,
tooltip = "text"
)
The Plotly chart is interactive. Moving the cursor over a bar displays the sentiment category, number of posts, and percentage of the sample.
positive_words <- sentiment_words %>%
filter(
sentiment == "positive"
) %>%
count(
word,
sort = TRUE
) %>%
slice_head(n = 10)
kable(
positive_words,
caption = "Most Common Positive Words"
)
| word | n |
|---|---|
| free | 27 |
| like | 12 |
| best | 8 |
| gentle | 6 |
| good | 6 |
| top | 5 |
| available | 4 |
| clean | 3 |
| gold | 3 |
| sensitive | 3 |
negative_words <- sentiment_words %>%
filter(
sentiment == "negative"
) %>%
count(
word,
sort = TRUE
) %>%
slice_head(n = 10)
kable(
negative_words,
caption = "Most Common Negative Words"
)
| word | n |
|---|---|
| limit | 4 |
| bad | 2 |
| boring | 2 |
| complex | 2 |
| desert | 2 |
| greasy | 2 |
| hate | 2 |
| issues | 2 |
| itchy | 2 |
| allergies | 1 |
positive_pct <- sentiment_summary %>%
filter(sentiment == "Positive") %>%
pull(percent)
negative_pct <- sentiment_summary %>%
filter(sentiment == "Negative") %>%
pull(percent)
neutral_pct <- sentiment_summary %>%
filter(sentiment == "Neutral") %>%
pull(percent)
if(length(positive_pct) == 0) positive_pct <- 0
if(length(negative_pct) == 0) negative_pct <- 0
if(length(neutral_pct) == 0) neutral_pct <- 0
overall_results <- data.frame(
Sentiment = c(
"Positive",
"Negative",
"Neutral"
),
Percentage = c(
positive_pct,
negative_pct,
neutral_pct
)
)
kable(
overall_results,
caption = "Overall Sentiment Percentages"
)
| Sentiment | Percentage |
|---|---|
| Positive | 24.0 |
| Negative | 6.4 |
| Neutral | 69.6 |
The Bluesky analysis provides a snapshot of how users are discussing CeraVe online. The common-word analysis identifies the topics and product-related terms that occur most frequently in the collected posts. This can help CeraVe understand which products, skincare topics, or customer concerns receive the most attention.
The sentiment analysis separates the posts into positive, negative, and neutral categories based on the Bing sentiment dictionary. The results provide an overall indication of whether the language surrounding CeraVe in this sample is favorable, unfavorable, or neutral. However, the results should be interpreted as a description of this Bluesky sample rather than the opinions of all CeraVe customers.
The AI-generated code was verified in several ways. First, I compared the number of cleaned posts with the number of posts receiving sentiment classifications. These totals should match. Second, I checked for missing and duplicate post text after cleaning. Third, I examined individual posts and compared the positive and negative word counts with the calculated sentiment score.
There are important limitations to automated sentiment analysis. The Bing lexicon evaluates individual words and does not fully understand the context of an entire post. Sarcasm, jokes, negation, slang, emojis, and product-specific language may therefore be interpreted incorrectly. For example, a post could contain the word “good” sarcastically and still receive a positive score.
Another limitation is that a post mentioning CeraVe is not necessarily expressing an opinion about CeraVe. Some posts may contain advertisements, news, comparisons with competing products, or unrelated references. Therefore, manual inspection remains important when interpreting the results.
This project demonstrated how Bluesky data can be combined with R, tidy text analysis, sentiment dictionaries, and Plotly to study consumer conversations about CeraVe. AI was useful for developing the analysis code, but verification was necessary to make sure the code behaved as expected and to identify limitations in automated sentiment classification. The analysis can help marketers identify frequently discussed topics and monitor whether online conversations surrounding CeraVe are generally positive, negative, or neutral. ````