Social Media Engagement and Consumer Ad Content Preferences
1. Create the Dataset
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)
library(tidyr)
# Sample social media comments
data <- tibble(
line = 1:12,
ad_type = c(
"Influencer", "Product Demo", "Discount",
"User Generated", "Influencer", "Product Demo",
"Discount", "User Generated", "Influencer",
"Product Demo", "Discount", "User Generated"
),
likes = c(250, 180, 320, 290, 210, 150,
400, 350, 280, 200, 450, 310),
comments = c(35, 20, 45, 40, 30, 18,
60, 50, 38, 25, 65, 42),
shares = c(40, 30, 55, 60, 35, 25,
70, 65, 45, 35, 85, 55),
text = c(
"I love seeing influencers recommend products. Their reviews feel authentic.",
"Product demonstrations help me understand how products work.",
"Discounts and sales make me more interested in buying products.",
"I trust real customer experiences and honest product reviews.",
"Influencer recommendations introduce me to new brands.",
"I like watching videos that demonstrate product features.",
"Special offers and promotions encourage me to shop.",
"Customer reviews make me feel more confident about purchases.",
"I enjoy seeing influencers share their favorite products.",
"Demonstration videos are helpful and informative.",
"I love finding discounts and affordable products online.",
"Real customer photos and videos make products look trustworthy."
)
)
data
## # A tibble: 12 × 6
## line ad_type likes comments shares text
## <int> <chr> <dbl> <dbl> <dbl> <chr>
## 1 1 Influencer 250 35 40 I love seeing influencers recomme…
## 2 2 Product Demo 180 20 30 Product demonstrations help me un…
## 3 3 Discount 320 45 55 Discounts and sales make me more …
## 4 4 User Generated 290 40 60 I trust real customer experiences…
## 5 5 Influencer 210 30 35 Influencer recommendations introd…
## 6 6 Product Demo 150 18 25 I like watching videos that demon…
## 7 7 Discount 400 60 70 Special offers and promotions enc…
## 8 8 User Generated 350 50 65 Customer reviews make me feel mor…
## 9 9 Influencer 280 38 45 I enjoy seeing influencers share …
## 10 10 Product Demo 200 25 35 Demonstration videos are helpful …
## 11 11 Discount 450 65 85 I love finding discounts and affo…
## 12 12 User Generated 310 42 55 Real customer photos and videos m…
3. Visualize Consumer Engagement
ggplot(engagement_summary,
aes(x = reorder(ad_type, average_engagement),
y = average_engagement)) +
geom_col(fill = "steelblue") +
coord_flip() +
labs(
title = "Average Social Media Engagement by Ad Content Type",
x = "Advertising Content Type",
y = "Average Engagement"
) +
theme_minimal()

4. Prepare Text for Analysis
# Convert comments into individual words
text_df <- data %>%
select(line, ad_type, text) %>%
unnest_tokens(word, text)
# Remove common stop words
data(stop_words)
text_df <- text_df %>%
anti_join(stop_words, by = "word")
text_df
## # A tibble: 62 × 3
## line ad_type word
## <int> <chr> <chr>
## 1 1 Influencer love
## 2 1 Influencer influencers
## 3 1 Influencer recommend
## 4 1 Influencer products
## 5 1 Influencer reviews
## 6 1 Influencer feel
## 7 1 Influencer authentic
## 8 2 Product Demo product
## 9 2 Product Demo demonstrations
## 10 2 Product Demo understand
## # ℹ 52 more rows
5. Identify Most Frequently Used Words
word_frequency <- text_df %>%
count(word, sort = TRUE)
word_frequency
## # A tibble: 44 × 2
## word n
## <chr> <int>
## 1 products 6
## 2 customer 3
## 3 product 3
## 4 reviews 3
## 5 videos 3
## 6 discounts 2
## 7 feel 2
## 8 influencers 2
## 9 love 2
## 10 real 2
## # ℹ 34 more rows
# Visualize frequently used words
word_frequency %>%
filter(n > 1) %>%
mutate(word = reorder(word, n)) %>%
ggplot(aes(n, word)) +
geom_col(fill = "steelblue") +
labs(
title = "Most Frequently Used Words in Consumer Comments",
x = "Frequency",
y = "Words"
) +
theme_minimal()

6. Analyze Consumer Preferences by Ad Type
# Identify frequently mentioned words for each ad type
ad_words <- text_df %>%
count(ad_type, word, sort = TRUE)
ad_words
## # A tibble: 52 × 3
## ad_type word n
## <chr> <chr> <int>
## 1 User Generated customer 3
## 2 Discount discounts 2
## 3 Discount products 2
## 4 Influencer influencers 2
## 5 Influencer products 2
## 6 Product Demo product 2
## 7 Product Demo videos 2
## 8 User Generated real 2
## 9 User Generated reviews 2
## 10 Discount affordable 1
## # ℹ 42 more rows
# Visualize the most common words by advertising type
ad_words %>%
group_by(ad_type) %>%
slice_max(n, n = 5, with_ties = FALSE) %>%
ungroup() %>%
ggplot(aes(x = reorder_within(word, n, ad_type),
y = n)) +
geom_col(fill = "steelblue") +
coord_flip() +
scale_x_reordered() +
facet_wrap(~ad_type, scales = "free") +
labs(
title = "Consumer Vocabulary by Advertising Content Type",
x = "Words",
y = "Frequency"
) +
theme_minimal()

7. Sentiment Analysis
# Assign positive and negative sentiment to words
sentiment_words <- text_df %>%
inner_join(get_sentiments("bing"), by = "word")
# Count positive and negative words by advertising type
sentiment_summary <- sentiment_words %>%
count(ad_type, sentiment)
sentiment_summary
## # A tibble: 4 × 3
## ad_type sentiment n
## <chr> <chr> <int>
## 1 Discount positive 3
## 2 Influencer positive 6
## 3 Product Demo positive 1
## 4 User Generated positive 4
# Visualize consumer sentiment
ggplot(sentiment_summary,
aes(x = ad_type, y = n, fill = sentiment)) +
geom_col(position = "dodge") +
coord_flip() +
labs(
title = "Consumer Sentiment by Advertising Content Type",
x = "Advertising Content Type",
y = "Number of Words",
fill = "Sentiment"
) +
theme_minimal()

8. Calculate Overall Sentiment
overall_sentiment <- sentiment_words %>%
group_by(ad_type) %>%
summarise(
positive_words = sum(sentiment == "positive"),
negative_words = sum(sentiment == "negative"),
net_sentiment = positive_words - negative_words,
.groups = "drop"
) %>%
arrange(desc(net_sentiment))
overall_sentiment
## # A tibble: 4 × 4
## ad_type positive_words negative_words net_sentiment
## <chr> <int> <int> <int>
## 1 Influencer 6 0 6
## 2 User Generated 4 0 4
## 3 Discount 3 0 3
## 4 Product Demo 1 0 1
Social Media Engagement and Consumer Ad Content Preferences
1. Create the Dataset
2. Analyze Social Media Engagement
3. Visualize Consumer Engagement
4. Prepare Text for Analysis
5. Identify Most Frequently Used Words
6. Analyze Consumer Preferences by Ad Type
7. Sentiment Analysis
8. Calculate Overall Sentiment