Sentiment Analysis of Tesla’s Cybertruck Launch

I used this assignment to analyze and compare the sentiments of tweets between Tesla’s Cybertruck (#cybertruck) & Ford F150 (#F150). I thought this was timely due to the public launch of Tesla’s Cybertruck (). Elon Musk uses Twitter to publicize all of his companies announcements and Ford’s F150 is his new products primary competition.

To start I set up my Twitter account to access data from the platform. This required me to configure and call out the code listed in this week’s lecture notes and videos. I have hidden this code from this markdown.

From here I started to download tweets using ‘search_tweets’ related to #Cybertruck & #F150. On a side note: The tweet’s origninating platform data was new detail for me. I enjoyed the Trump Tweet article too! That said, the results showed that the top three platforms were ‘Twitter from iPhone’, ‘Twitter from Android’ & ‘Twitter from Web App’ for both #s.

#F150 returned under 1000 tweets while #Cybertruck had many. many more than 1000. Next, I used ‘tidytext’ to isolate the individual words in the various tweets.

ct_words <- ctruck %>% select(status_id, text) %>%
  filter(!str_detect(text, '^"')) %>%
  mutate(text = str_replace_all(text, "https://t.co/[A-Za-z\\d]+|&amp;", "")) %>%
  unnest_tokens(word, text, token = "regex") %>%
  filter(!word %in% stop_words$word,
         str_detect(word, "[a-z]"))
kable(head(ct_words, caption = "CyberTruck Tweet Words"))
status_id word
1199293162113552384 @carleenhaylett
1199293162113552384 @elonmusk
1199293162113552384 @tesla
1199293162113552384 haha
1199293162113552384 it!
1199293162113552384 8yo

Here is the same for the Ford F150

ftruck <- search_tweets('#F150', n = num_tweets, include_rts = FALSE)

reg <- "([^A-Za-z\\d#@']|'(?![A-Za-z\\d#@]))"
f150_words <- ftruck %>% select(status_id, text) %>%
  filter(!str_detect(text, '^"')) %>%
  mutate(text = str_replace_all(text, "https://t.co/[A-Za-z\\d]+|&amp;", "")) %>%
  unnest_tokens(word, text, token = "regex", pattern = reg) %>%
  filter(!word %in% stop_words$word,
         str_detect(word, "[a-z]"))

kable(head(f150_words, caption = "F150 Tweet Words"))
status_id word
1196025733963034624 #f150
1196079524225548288 #nfsheat
1196079524225548288 #f150
1196082146286419968 @jdemontreal
1196082146286419968 @mariodumont
1196082146286419968 l’#alberta

Enter NRC Sentitment & Visualizations

nrc <- get_sentiments("nrc") %>%
select(word, sentiment)
ctruck_words_sentiments <- ct_words %>% inner_join(nrc, by = "word")
ctruck_words_sentiments_plot <- ctruck_words_sentiments %>% group_by(sentiment) %>% summarize(n = n()) %>% arrange(desc(n))
names(ctruck_words_sentiments_plot) <- c("NRC_Sentiment", "Cybertruck_Sentiment")

ggplot(ctruck_words_sentiments_plot, aes(x = NRC_Sentiment, y = Cybertruck_Sentiment)) + 
  geom_col() +
  coord_flip() +
  labs(x = "NRC_Sentiment",
       y = "Cybertruck_Sentiment",
       title = "#Cybertruck Tweets Sentiment")

While there were tons of different opions - Tesla’s Cybertruck seemed to be well liked.

f150_words_sentiments <- f150_words %>% inner_join(nrc, by = "word")
f150_words_sentiments %>% group_by(sentiment) %>% summarize(n = n())
## # A tibble: 10 x 2
##    sentiment        n
##    <chr>        <int>
##  1 anger           84
##  2 anticipation   166
##  3 disgust         42
##  4 fear            98
##  5 joy            126
##  6 negative       178
##  7 positive       305
##  8 sadness         51
##  9 surprise        87
## 10 trust          206
f150_words_sentiments_plot <- f150_words_sentiments %>% group_by(sentiment) %>% summarize(n = n()) %>% arrange(desc(n))
names(f150_words_sentiments_plot) <- c("NRC_Sentiment", "F150_Sentiment")
ggplot(f150_words_sentiments_plot, aes(x = NRC_Sentiment, y = F150_Sentiment)) + 
  geom_col() +
  coord_flip() +
  labs(x = "NRC_Sentiment",
       y = "F150_Sentiment",
       title = "#F150 Tweets Sentiment")

new_pickup_words_sentiments_plot <- ctruck_words_sentiments_plot %>% right_join(f150_words_sentiments_plot)
kable(head(new_pickup_words_sentiments_plot, caption = "CyberTruck & F150 Tweet Sentiments"))
NRC_Sentiment Cybertruck_Sentiment F150_Sentiment
positive 466 305
trust 272 206
negative 271 178
anticipation 205 166
joy 169 126
fear 169 98
kable(head(new_pickup_words_sentiments_plot, caption = "CyberTruck & F150 Tweet Sentiments"))
NRC_Sentiment Cybertruck_Sentiment F150_Sentiment
positive 466 305
trust 272 206
negative 271 178
anticipation 205 166
joy 169 126
fear 169 98

It seems that both trucks twitter activity match up and will be interesting how each company uses this platform in future.

##Go Electric!!!