install.packages(c( “dplyr”, “stringr”, “tidytext”, “ggplot2”, “plotly”, “knitr”, “rmarkdown”, “textdata” ))

textdata::lexicon_bing()

Reflection

I used ChatGPT to help organize this lab and write R code for a BlueSky dataset about Nike. The original file has 283 posts, and this report focuses on the posts that explicitly mention Nike. I used R to clean the data, find common words, classify posts that include an #ad tag, and calculate positive and negative word counts with the Bing dictionary. I also made an interactive Plotly chart. The process showed me how a basic text analysis can help a marketer separate common discussion topics from advertising activity.

The AI-generated code still needs human review. A post may mention Nike without offering an opinion about the brand, and a product advertisement can contain words that the dictionary labels positive. Some posts are written in other languages, and the dictionary does not understand sarcasm, who an opinion is aimed at, or the meaning of an entire sentence. I added checks for row counts and sentiment calculations and created a ten-post worksheet for manual review. Until I review that sample, I cannot claim the sentiment labels are accurate. Human judgment matters when deciding which posts are relevant and what the results mean for marketing.

Research Question

Among BlueSky posts that explicitly mention Nike, how often is an advertising tag used, and how do positive and negative word patterns vary between tagged ads and other posts?

This analysis uses one collected CSV, not a survey of Nike customers. A post with #ad is marked as an advertisement, but the absence of #ad does not mean it represents an ordinary customer opinion.

1. Import and Clean the Data

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

library(dplyr)
library(stringr)
library(tidytext)
library(ggplot2)
library(plotly)
library(knitr)
file_name <- "Scrape1_Nike_2026-10-22.csv"

if (!file.exists(file_name)) {
  stop("Upload Scrape1_Nike_2026-10-22.csv to the project folder.")
}

raw <- read.csv(
  file_name,
  stringsAsFactors = FALSE,
  fileEncoding = "UTF-8"
)

required <- c(
  "post_id",
  "post_text",
  "like_count",
  "repost_count",
  "total_engagement"
)

if (!all(required %in% names(raw))) {
  stop(
    "Missing CSV columns: ",
    paste(setdiff(required, names(raw)), collapse = ", ")
  )
}

posts <- raw %>%
  mutate(
    row_original = row_number(),
    text_original = coalesce(post_text, ""),

    post_key = if_else(
      is.na(post_id) | str_squish(post_id) == "",
      paste0("missing_id_", row_original),
      post_id
    )
  ) %>%
  filter(str_squish(text_original) != "") %>%
  distinct(post_key, .keep_all = TRUE)

nike <- posts %>%
  filter(str_detect(
    text_original,
    regex("\\bnike\\b", ignore_case = TRUE)
  )) %>%
  mutate(
    hashtag_ad = str_detect(
      text_original,
      regex("#ad\\b", ignore_case = TRUE)
    ),

    has_url = str_detect(
      text_original,
      regex("https?://|www\\.", ignore_case = TRUE)
    ),

    group = if_else(
      hashtag_ad,
      "Tagged #ad",
      "Not tagged #ad"
    ),

    text_clean = text_original %>%
      str_remove_all("https?://\\S+|www\\.\\S+") %>%
      str_remove_all("@[[:alnum:]_.-]+") %>%
      str_squish()
  )

cleaning_audit <- data.frame(
  Check = c(
    "Original rows",
    "Posts after blank and ID cleaning",
    "Nike mentions",
    "Excluded from Nike analysis",
    "Nike posts tagged #ad",
    "Nike posts with URLs"
  ),

  Count = c(
    nrow(raw),
    nrow(posts),
    nrow(nike),
    nrow(raw) - nrow(nike),
    sum(nike$hashtag_ad),
    sum(nike$has_url)
  )
)

kable(cleaning_audit)
Check Count
Original rows 283
Posts after blank and ID cleaning 283
Nike mentions 263
Excluded from Nike analysis 20
Nike posts tagged #ad 71
Nike posts with URLs 121

The code keeps one record per post ID and preserves the original text. URLs and mentions are removed only from the text used for word counts.

2. Text Analysis

words <- nike %>%
  select(post_key, text_clean) %>%
  unnest_tokens(word, text_clean) %>%
  filter(str_detect(word, "[[:alpha:]]"))

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

top_words <- head(word_frequency, 12)

kable(
  top_words,
  col.names = c("Word", "Times used")
)
Word Times used
de 77
ad 73
air 65
en 44
tênis 43
la 41
por 39
chez 38
sneakers 37
cupom 35
le 35
max 30

Most Common Words

ggplot(
  top_words,
  aes(x = reorder(word, n), y = n)
) +
  geom_col(fill = "#426A86") +
  coord_flip() +
  labs(
    title = "Words Appearing Most Often in Nike Mentions",
    subtitle = "Excludes English stop words and Nike",
    x = NULL,
    y = "Word occurrences"
  ) +
  theme_minimal()

A frequently mentioned word does not necessarily represent a positive customer review. Product names, promotional language, and non-English words can influence the results.

3. Sentiment Analysis

bing <- get_sentiments("bing")

matched <- words %>%
  inner_join(bing, by = "word")

post_counts <- matched %>%
  group_by(post_key) %>%
  summarise(
    positive = sum(sentiment == "positive"),
    negative = sum(sentiment == "negative"),
    .groups = "drop"
  )

scored <- nike %>%
  left_join(post_counts, by = "post_key") %>%
  mutate(
    positive = coalesce(positive, 0L),
    negative = coalesce(negative, 0L),

    score = positive - negative,

    category = case_when(
      positive + negative == 0 ~ "No dictionary match",
      score > 0 ~ "More positive words",
      score < 0 ~ "More negative words",
      TRUE ~ "Equal positive/negative"
    )
  )

sentiment_summary <- scored %>%
  count(category, name = "Posts") %>%
  mutate(
    Percent = round(
      100 * Posts / sum(Posts), 1
    )
  )

kable(sentiment_summary)
category Posts Percent
Equal positive/negative 13 4.9
More negative words 24 9.1
More positive words 83 31.6
No dictionary match 143 54.4

A score of zero may mean that no words matched the dictionary or that the positive and negative counts were equal. Neither result automatically represents a neutral opinion.

4. Interactive Plotly Chart

comparison <- scored %>%
  count(group, category, name = "Posts")

plot_ly(
  comparison,
  x = ~category,
  y = ~Posts,
  color = ~group,
  type = "bar",
  text = ~paste0(group, ": ", Posts, " posts"),
  hoverinfo = "text"
) %>%
  layout(
    title = "Nike Sentiment: #ad Posts Compared with Other Posts",
    xaxis = list(
      title = "Dictionary result",
      tickangle = -18,
      automargin = TRUE
    ),
    yaxis = list(
      title = "Number of posts"
    ),
    barmode = "group",
    margin = list(b = 110)
  )

Positive and Negative Words

sentiment_terms <- matched %>%
  count(
    sentiment,
    word,
    sort = TRUE,
    name = "Count"
  ) %>%
  group_by(sentiment) %>%
  slice_head(n = 7) %>%
  ungroup()

kable(sentiment_terms)
sentiment word Count
negative jam 4
negative nightmare 3
negative dark 2
negative shit 2
negative bad 1
negative bitch 1
negative bleeding 1
positive available 27
positive cheaper 13
positive uplift 9
positive like 5
positive gold 3
positive led 3
positive love 3

5. Verify the Results

verification <- data.frame(
  Check = c(
    "Original dataset has 283 rows",
    "263 posts mention Nike",
    "No duplicate post keys remain",
    "One sentiment result per Nike post",
    "Sentiment category counts add up",
    "Sentiment word totals match",
    "Total engagement equals 511",
    "Engagement equals likes plus reposts"
  ),

  Result = c(
    nrow(raw) == 283,

    nrow(nike) == 263,

    anyDuplicated(posts$post_key) == 0,

    nrow(scored) == nrow(nike),

    sum(sentiment_summary$Posts) == nrow(nike),

    sum(scored$positive) ==
      sum(matched$sentiment == "positive") &&
      sum(scored$negative) ==
      sum(matched$sentiment == "negative"),

    sum(raw$total_engagement, na.rm = TRUE) == 511,

    all(
      raw$total_engagement ==
        raw$like_count + raw$repost_count
    )
  )
)

kable(verification)
Check Result
Original dataset has 283 rows TRUE
263 posts mention Nike TRUE
No duplicate post keys remain TRUE
One sentiment result per Nike post TRUE
Sentiment category counts add up TRUE
Sentiment word totals match TRUE
Total engagement equals 511 TRUE
Engagement equals likes plus reposts TRUE
stopifnot(
  anyDuplicated(posts$post_key) == 0L,
  nrow(scored) == nrow(nike),
  sum(sentiment_summary$Posts) == nrow(nike),
  all(scored$score == scored$positive - scored$negative)
)

Hand Calculation

# Example:
# great = +1
# bad = -1
# bad = -1
# Total = -1

example_words <- tibble(
  text = "great bad bad"
) %>%
  unnest_tokens(word, text) %>%
  inner_join(bing, by = "word")

example_pos <- sum(
  example_words$sentiment == "positive"
)

example_neg <- sum(
  example_words$sentiment == "negative"
)

example_score <- example_pos - example_neg

hand_check <- data.frame(
  Positive = example_pos,
  Negative = example_neg,
  Hand_calculated = -1,
  R_result = example_score
)

kable(hand_check)
Positive Negative Hand_calculated R_result
1 2 -1 -1
stopifnot(
  example_pos == 1L,
  example_neg == 2L,
  example_score == -1L
)

6. Human Review

set.seed(2026)

private_review <- scored %>%
  slice_sample(
    n = min(10L, nrow(scored))
  ) %>%
  transmute(
    original_post = text_original,
    dictionary_score = score,
    dictionary_category = category,
    human_label = "",
    reason = ""
  )

write.csv(
  private_review,
  "Nike_Human_Review_PRIVATE.csv",
  row.names = FALSE
)

cat("A ten-post review worksheet was saved.")
## A ten-post review worksheet was saved.

Open Nike_Human_Review_PRIVATE.csv and independently label each post as positive, negative, or neutral/unclear toward Nike. Explain any differences between your interpretation and the dictionary results. Do not publish the raw posts or usernames in your RPubs report.

7. Findings and Limitations

There are 283 original records and 263 posts explicitly mentioning Nike.

Of those Nike posts, 71 contain the #ad tag, and 121 contain a URL. A URL alone does not prove that a post is an advertisement.

The Bing sentiment dictionary identifies at least one positive or negative word in 120 posts.

These results describe dictionary matches, not confirmed customer opinions. Promotional language, sarcasm, unrelated mentions, and posts written in other languages can make sentiment interpretation difficult.

What Could Be Improved?

After manually reviewing ten posts, I would exclude posts unrelated to the Nike brand, identify likely promotional content more carefully, and compare human sentiment labels with the dictionary results.

This would help determine whether the automated analysis accurately reflects what users are saying.

8. AI Prompts and Improvements

Original Prompt

“Can you help me examine social media conversations about Nike using RStudio? I want to identify frequently used words, understand the overall tone of the posts, and create a simple visualization of the findings.

Follow-Up Prompts

“I am working with a BlueSky dataset containing 283 posts related to Nike. Create a beginner-friendly R Markdown analysis using dplyr, tidytext, ggplot2, and plotly. Remove duplicate and empty posts, identify common words, and use the Bing sentiment dictionary to compare positive and negative language. Include an interactive chart comparing posts tagged #ad with other posts. Add verification checks to make sure the calculations are correct, and explain where human interpretation is needed.”

Improved Prompt to Test

“The original prompt gave AI a general idea of what I wanted to analyze. The revised prompt provided the dataset details, specific R packages, cleaning requirements, and visualization instructions. This helped make the analysis more organized and easier to verify. I also wanted to understand the limitations of sentiment analysis instead of relying entirely on AI-generated results.”

9. References

Silge, J., and Robinson, D. Text Mining with R.

https://www.tidytextmining.com/sentiment.html

Plotly R documentation:

https://plotly.com/r/bar-charts/

RPubs:

https://rpubs.com/

10. Reproducibility

sessionInfo()
## R version 4.6.2 (2026-10-29)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.5 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0
## 
## locale:
##  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
##  [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
##  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
## [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
## 
## time zone: UTC
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] knitr_1.52     plotly_4.12.1  ggplot2_4.0.4  tidytext_0.4.3 stringr_1.6.0 
## [6] dplyr_1.2.1   
## 
## loaded via a namespace (and not attached):
##  [1] Matrix_1.7-6        gtable_0.3.6        jsonlite_2.0.0     
##  [4] janeaustenr_1.0.0   compiler_4.6.2      tidyselect_1.2.1   
##  [7] Rcpp_1.1.2          tidyr_1.3.2         jquerylib_0.1.4    
## [10] scales_1.4.0        yaml_2.3.12         fastmap_1.2.0      
## [13] lattice_0.23-1      R6_2.6.1            labeling_0.4.3     
## [16] SnowballC_0.7.1     generics_0.1.4      htmlwidgets_1.6.4  
## [19] tibble_3.3.1        RColorBrewer_1.1-3  bslib_0.12.0       
## [22] pillar_1.11.1       tokenizers_0.3.0    rlang_1.3.0        
## [25] cachem_1.1.0        stringi_1.8.9       xfun_0.62          
## [28] S7_0.2.2            sass_0.4.10         otel_0.3.0         
## [31] viridisLite_0.4.3   cli_3.6.6           withr_3.0.3        
## [34] magrittr_2.0.5      crosstalk_1.2.2     digest_0.6.39      
## [37] grid_4.6.2          lifecycle_1.0.5     vctrs_0.7.3        
## [40] data.table_1.18.6.1 evaluate_1.0.5      glue_1.8.1         
## [43] farver_2.1.2        purrr_1.2.2         httr_1.4.9         
## [46] rmarkdown_2.32      tools_4.6.2         pkgconfig_2.0.3    
## [49] htmltools_0.5.9