Reflection

This project helped me understand how R can be used to organize and analyze social media data. I used the Nike-related Bluesky posts collected by my group to examine engagement, clean the post text, look at frequently used words, review sentiment, and create an interactive chart. AI helped me get started with the R code and understand which packages and functions could be used for each part of the analysis.

However, I learned that AI-generated code and results still need to be checked. I had to make sure the code matched the columns in my actual Excel file, check whether the calculations made sense, and compare the automated sentiment results with the manually coded sample. Human judgment is important because a word-based sentiment tool may misunderstand a post, especially when posts contain advertisements, product listings, sarcasm, or languages other than English. AI can help with the process, but people still need to interpret the results and explain what they mean.

1. Load packages

The packages below are used to import the Excel workbook, clean and organize the data, analyze text, and create the interactive chart.

# Install any packages you do not already have:
# install.packages(c("readxl", "dplyr", "tidyr", "stringr",
#                    "tidytext", "ggplot2", "plotly", "lubridate",
#                    "knitr", "scales"))

library(readxl)
library(dplyr)
library(tidyr)
library(stringr)
library(tidytext)
library(ggplot2)
library(plotly)
library(lubridate)
library(knitr)
library(scales)

knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)

2. Import the Nike Bluesky data

Save this R Markdown file and the Excel workbook in the same folder before knitting. The workbook name and sheet name below match the file used for this analysis.

file_name <- "Nike_Social media Analysis complete (1).xlsx"

# Import the main collection of 100 Bluesky posts.
nike_posts <- read_excel("Nike_Social media Analysis complete.xlsx", sheet = "Raw Data")

# Check the data and its column names.
dim(nike_posts)
## [1] 100  25
names(nike_posts)
##  [1] "uri"              "cid"              "author_handle"    "author_name"     
##  [5] "text"             "author_data"      "post_data"        "embed_data"      
##  [9] "reply_count"      "repost_count"     "like_count"       "quote_count"     
## [13] "bookmark_count"   "indexed_at"       "created_at"       "in_reply_to"     
## [17] "in_reply_root"    "quotes"           "tags"             "mentions"        
## [21] "links"            "langs"            "labels"           "Engagement"      
## [25] "Sentiment Sample"
head(nike_posts, 3)
## # A tibble: 3 × 25
##   uri     cid   author_handle author_name text  author_data post_data embed_data
##   <chr>   <chr> <chr>         <chr>       <chr> <chr>       <chr>     <chr>     
## 1 at://d… bafy… realmadrid-f… Real Madri… "⚽ O… "did:plc:z… "app.bsk… "list(uri…
## 2 at://d… bafy… fcbarcelona-… FC Barcelo… "⚽ O… "did:plc:t… "app.bsk… "list(uri…
## 3 at://d… bafy… swooshsupply… swoosh sup… "Nik… "did:plc:n… "app.bsk… "list(ima…
## # ℹ 17 more variables: reply_count <dbl>, repost_count <dbl>, like_count <dbl>,
## #   quote_count <dbl>, bookmark_count <dbl>, indexed_at <chr>,
## #   created_at <chr>, in_reply_to <chr>, in_reply_root <chr>, quotes <chr>,
## #   tags <chr>, mentions <lgl>, links <chr>, langs <chr>, labels <lgl>,
## #   Engagement <dbl>, `Sentiment Sample` <chr>

3. Clean and prepare the data

The original workbook contains 100 posts. Some posts do not have text or a created date, so the code checks for missing values. Engagement is recalculated as likes plus reposts so the measure is consistent.

nike_clean <- nike_posts %>%
  mutate(
    text = as.character(text),
    author_handle = as.character(author_handle),
    created_at = ymd_hms(as.character(created_at), quiet = TRUE),
    like_count = replace_na(as.numeric(like_count), 0),
    repost_count = replace_na(as.numeric(repost_count), 0),
    reply_count = replace_na(as.numeric(reply_count), 0),
    quote_count = replace_na(as.numeric(quote_count), 0),
    bookmark_count = replace_na(as.numeric(bookmark_count), 0),

    # Engagement is defined here as likes plus reposts.
    engagement = like_count + repost_count,

    # Remove links, mentions, hashtags, punctuation, and extra spaces.
    post_text_clean = text %>%
      str_to_lower() %>%
      str_replace_all("https?://\\S+", " ") %>%
      str_replace_all("@[\\w.-]+", " ") %>%
      str_replace_all("#[\\p{L}\\w_]+", " ") %>%
      str_replace_all("[^\\p{L}\\s]", " ") %>%
      str_squish()
  )

# Keep rows with usable post text for text analysis.
text_posts <- nike_clean %>%
  filter(!is.na(text), text != "", post_text_clean != "")

# Check missing values and the cleaned data.
data.frame(
  Measure = c("Total posts", "Posts with text", "Missing post text",
              "Missing created date"),
  Count = c(
    nrow(nike_clean),
    nrow(text_posts),
    sum(is.na(nike_clean$text) | nike_clean$text == ""),
    sum(is.na(nike_clean$created_at))
  )
) %>%
  kable(caption = "Data quality check")
Data quality check
Measure Count
Total posts 100
Posts with text 96
Missing post text 3
Missing created date 20

4. Descriptive statistics and engagement

This section summarizes likes, reposts, replies, quotes, bookmarks, and total engagement. Engagement for this project means likes plus reposts.

engagement_summary <- nike_clean %>%
  summarise(
    total_posts = n(),
    total_likes = sum(like_count, na.rm = TRUE),
    total_reposts = sum(repost_count, na.rm = TRUE),
    total_replies = sum(reply_count, na.rm = TRUE),
    total_quotes = sum(quote_count, na.rm = TRUE),
    total_bookmarks = sum(bookmark_count, na.rm = TRUE),
    average_likes = round(mean(like_count, na.rm = TRUE), 2),
    average_reposts = round(mean(repost_count, na.rm = TRUE), 2),
    average_engagement = round(mean(engagement, na.rm = TRUE), 2),
    highest_engagement = max(engagement, na.rm = TRUE)
  )

engagement_summary %>%
  kable(caption = "Nike Bluesky engagement summary")
Nike Bluesky engagement summary
total_posts total_likes total_reposts total_replies total_quotes total_bookmarks average_likes average_reposts average_engagement highest_engagement
100 76 3 9 2 0 0.76 0.03 0.79 26

Top 10 posts by engagement

top_posts <- nike_clean %>%
  arrange(desc(engagement), desc(like_count), desc(repost_count)) %>%
  slice_head(n = 10) %>%
  mutate(
    post_number = paste0("Post ", row_number()),
    short_text = if_else(
      is.na(text), "[No post text]",
      str_trunc(text, width = 180)
    )
  ) %>%
  select(post_number, author_handle, short_text,
         like_count, repost_count, engagement)

top_posts %>%
  kable(
    col.names = c("Post", "Author", "Post text", "Likes",
                  "Reposts", "Likes + reposts"),
    caption = "Top 10 posts by engagement"
  )
Top 10 posts by engagement
Post Author Post text Likes Reposts Likes + reposts
Post 1 roryblank.bsky.social I mean I don’t know that Travis Knight, Nike scion, is hurting for money, but Laika movies are extremely time and labor intensive endeavors and they spent $100 million dollars m… 25 1 26
Post 2 ricardooliveria2.bsky.social 🔥 Tênis Nike Mc Trainer 3

🚨 De R$ 599 por R$ 289 🎟️ Use o Cupom: MODA2310

🔗 https://meli.la/2qL9VCU

#amazon #Afazenda #Jonatas #desconto #promo | 4| 0| 4| |Post 3 |promoatomicas.bsky.social |🔥 Tênis Nike Mc Trainer 3

🚨 De R$ 599 por R$ 289 🎟️ Use o Cupom: MODA2310

🔗 https://meli.la/2qL9VCU

#mercadolivre #amazon #Afazenda #oferta #blackfriday | 4| 0| 4| |Post 4 |ricardooliveria2.bsky.social |🔥 Tênis Nike Uplift Sc Masculino

🚨 R$ 266 🎟️ Cupom: MODA2310

🔗 https://meli.la/1PZ54Me

#Revelando #amazon #SDV #desconto #oferta | 4| 0| 4| |Post 5 |promoatomicas.bsky.social |🔥 Tênis Nike Uplift Sc Masculino

🚨 R$ 266 🎟️ Cupom: MODA2310

🔗 https://meli.la/1PZ54Me

#Afazenda #SDV #Entregou #promoção #oferta | 4| 0| 4| |Post 6 |jakeythesnakey.bsky.social |If you are as grossed out by having Nike/Blazers advertising on the Portland White Stag sign as I am, I really recommend writing your councilors about it. I did, and I’m 3 for 3… | 4| 0| 4| |Post 7 |eldritchmoon.love |- At the first president conference scene, the camera is angled in a way that ONLY shows digger’s white Nike sneakers but no one else’s shoes - also at that conference when the… | 3| 0| 3| |Post 8 |caiaoobrabo.bsky.social |🔥 Tênis Nike Mc Trainer 3

🚨 De R$ 599 por R$ 289 🎟️ Use o Cupom: MODA2310

🔗 https://meli.la/2qL9VCU

#amazon #mercadolivre #Deltan #achadinhos #promo | 3| 0| 3| |Post 9 |pedrohenriquee353.bsky.social |🔥 Tênis Nike Mc Trainer 3

🚨 De R$ 599 por R$ 289 🎟️ Use o Cupom: MODA2310

🔗 https://meli.la/2qL9VCU

#SDV #Jonatas #mercadolivre #cupom #oferta | 3| 0| 3| |Post 10 |rangerdonald.bsky.social |youtu.be/85zCwCQPDI8?… | 3| 0| 3|

5. Text analysis: most common words

The post text is separated into individual words. Common English stop words (such as “the” and “and”) are removed. Because the collected posts include more than one language, the word counts should be treated as a basic overview rather than a complete multilingual language analysis.

words <- text_posts %>%
  select(post_text_clean) %>%
  unnest_tokens(word, post_text_clean)

data("stop_words")

word_counts <- words %>%
  anti_join(stop_words, by = "word") %>%
  filter(
    str_length(word) > 2,
    !str_detect(word, "^[0-9]+$")
  ) %>%
  count(word, sort = TRUE)

top_words <- word_counts %>%
  slice_head(n = 20)

top_words %>%
  kable(caption = "20 most frequently used words")
20 most frequently used words
word n
nike 108
air 21
tênis 19
cupom 18
por 18
moda 17
chez 15
masculino 11
mercado 11
livre 10
pour 10
size 9
check 8
white 8
heritage 7
octobre 7
uplift 7
www 7
dans 6
force 6
ggplot(top_words, aes(x = reorder(word, n), y = n)) +
  geom_col() +
  coord_flip() +
  labs(
    title = "Most Common Words in Nike-Related Bluesky Posts",
    x = "Word",
    y = "Number of occurrences"
  ) +
  theme_minimal()

6. Automated sentiment analysis

The Bing sentiment dictionary labels English words as positive or negative. The results below are based on words that match that dictionary. This is not the same as understanding the meaning of an entire post, and it may miss context, sarcasm, advertising language, and non-English words.

bing_words <- get_sentiments("bing")

sentiment_word_matches <- words %>%
  inner_join(bing_words, by = "word")

automated_sentiment <- sentiment_word_matches %>%
  count(sentiment, name = "word_matches") %>%
  mutate(
    percentage = round(word_matches / sum(word_matches) * 100, 2)
  )

automated_sentiment %>%
  kable(caption = "Automated word-based sentiment results")
Automated word-based sentiment results
sentiment word_matches percentage
negative 14 22.95
positive 47 77.05
ggplot(automated_sentiment,
       aes(x = sentiment, y = word_matches)) +
  geom_col() +
  labs(
    title = "Automated Sentiment Word Matches",
    x = "Sentiment category",
    y = "Number of matched words"
  ) +
  theme_minimal()

Most common positive and negative words

sentiment_word_counts <- sentiment_word_matches %>%
  count(sentiment, word, sort = TRUE)

positive_words <- sentiment_word_counts %>%
  filter(sentiment == "positive") %>%
  slice_head(n = 10)

negative_words <- sentiment_word_counts %>%
  filter(sentiment == "negative") %>%
  slice_head(n = 10)

positive_words %>%
  kable(caption = "Most common positive words")
Most common positive words
sentiment word n
positive available 9
positive uplift 7
positive cool 2
positive elite 2
positive nice 2
positive premier 2
positive spotless 2
positive well 2
positive appreciate 1
positive clean 1
negative_words %>%
  kable(caption = "Most common negative words")
Most common negative words
sentiment word n
negative dick 2
negative disagree 2
negative bitch 1
negative boycott 1
negative defy 1
negative evil 1
negative freak 1
negative hurting 1
negative leak 1
negative prejudice 1

7. Compare with the manually coded sentiment sample

The workbook includes a manually coded random sample of 15 posts. The sample contains 8 positive posts, 2 negative posts, and 5 neutral posts. The code imports those labels and calculates the percentages again to verify the totals.

# The first two rows of this worksheet contain the title and blank row.
manual_sample <- read_excel(
  "Nike_Social media Analysis complete.xlsx",
  sheet = "Sentiment Sample",
  skip = 2
)

# Keep the five columns containing the manual coding information.
manual_sample <- manual_sample %>%
  select(1:5)

names(manual_sample) <- c(
  "raw_row", "author", "post_text", "sentiment", "coding_rationale"
)

manual_sample <- manual_sample %>%
  filter(!is.na(sentiment)) %>%
  mutate(sentiment = str_to_title(as.character(sentiment)))

manual_summary <- manual_sample %>%
  count(sentiment, name = "posts") %>%
  mutate(
    percentage = round(posts / sum(posts) * 100, 2)
  )

manual_summary %>%
  kable(caption = "Manual sentiment results (15-post sample)")
Manual sentiment results (15-post sample)
sentiment posts percentage
Negative 2 13.33
Neutral 5 33.33
Positive 8 53.33

Compare the two approaches

The manual sample and the automated dictionary analysis measure sentiment differently. The manual sample labels each selected post as a whole, while the Bing method counts individual English words that appear in its dictionary. Their percentages should not be treated as directly equivalent.

manual_summary %>%
  mutate(method = "Manual post-level sample") %>%
  select(method, sentiment, posts, percentage) %>%
  kable(caption = "Manual sentiment summary")
Manual sentiment summary
method sentiment posts percentage
Manual post-level sample Negative 2 13.33
Manual post-level sample Neutral 5 33.33
Manual post-level sample Positive 8 53.33

8. Interactive Plotly chart

The chart displays the 10 posts with the highest engagement. Hover over a bar to see the author, post text, likes, reposts, and total engagement.

plot_data <- nike_clean %>%
  arrange(desc(engagement), desc(like_count), desc(repost_count)) %>%
  slice_head(n = 10) %>%
  mutate(
    post_number = paste0("Post ", row_number()),
    hover_label = paste0(
      "<b>", post_number, "</b>",
      "<br>Author: ", coalesce(author_handle, "Unknown"),
      "<br>Likes: ", like_count,
      "<br>Reposts: ", repost_count,
      "<br>Engagement: ", engagement,
      "<br><br>", coalesce(text, "No post text")
    )
  )

fig <- plot_ly(
  data = plot_data,
  x = ~post_number,
  y = ~engagement,
  type = "bar",
  text = ~engagement,
  hovertext = ~hover_label,
  hoverinfo = "text"
) %>%
  layout(
    title = "Top 10 Nike-Related Bluesky Posts by Engagement",
    xaxis = list(title = "Post"),
    yaxis = list(title = "Likes + Reposts", rangemode = "tozero")
  )

fig

9. Findings and interpretation

The engagement results in the workbook show that the highest-engagement post received 26 likes and reposts combined, while each of the next four posts received 4. Four of the five highest-engagement posts were promotional Nike footwear posts that included prices, coupons, links, hashtags, and emojis. The highest post was different because it contained a longer opinion or commentary. This suggests that, in this collected group of posts, both useful product promotions and discussion-worthy content can attract engagement.

The manual sentiment sample contains 8 positive posts (53.33%), 2 negative posts (13.33%), and 5 neutral posts (33.33%). However, the positive labels often reflect promotional language or product availability, not necessarily an independent customer endorsement of Nike. The sample is small, so it should not be treated as a complete picture of all Nike customers or all Bluesky users.

10. Critique of AI output and the role of human judgment

AI can help suggest R code, explain functions, and make the analysis process faster. However, the code and results still need to be checked against the actual spreadsheet. For example, the workbook has missing post text and missing created dates, so those rows need to be handled carefully. Engagement should also be calculated consistently using likes plus reposts rather than assuming that every column in the spreadsheet represents the same measure.

Human judgment is especially important when interpreting sentiment. A dictionary may label a word as positive or negative without understanding how it is being used in the post. This matters for the Nike dataset because many posts are advertisements, product listings, or posts written in languages other than English. A promotional post may sound positive because it mentions a deal or product availability, but that does not prove that a customer personally likes Nike. The manual sample and the original post text help provide context that an automated score cannot fully capture.

11. AI prompts used

Keep a record of the prompts you actually used with AI. The examples below can be used as your original and improved prompts, but edit them if your actual prompts were different.

Original prompt:

“Help me analyze my Nike social media Excel data using R. I need to clean the data, analyze engagement and sentiment, and make a chart.”

Improved prompt:

“I am using an Excel workbook named Nike_Social media Analysis complete (1).xlsx. The main dataset is on the Raw Data sheet and has 100 Bluesky posts. The relevant columns include text, author_handle, like_count, repost_count, reply_count, quote_count, bookmark_count, and created_at. Please write clear R code using readxl, dplyr, stringr, tidytext, and plotly. Recalculate engagement as likes plus reposts, handle missing text and dates without deleting valid engagement data, clean the post text, show descriptive engagement statistics, identify the top 10 posts, perform a clearly labeled word-based sentiment analysis, import and summarize the 15-post manual sentiment sample from the Sentiment Sample sheet, and create an interactive Plotly bar chart. Explain limitations, especially that the Bing sentiment dictionary is English-based and does not understand context. Do not invent results; make the code calculate results from the workbook.”

Important: Your assignment also asks you to post screenshots of the prompts and AI responses in the discussion forum. Take screenshots of the prompts and the responses you actually used.