0

I'm trying to create a sentiment analysis using the tidytext code here but my graph comes out vertical, without the output making sense compared to the original which is horizontal. How can I fix this?

#Unnest tokens
edAItext = edAI %>% select(Group, Participant_ID, Brainscape_Pattern) %>% 
  unnest_tokens(word, Brainscape_Pattern)

# Inner join
bing_word_counts <- edAItextTest %>%
   inner_join(get_sentiments("bing")) %>%
   count(word, sentiment, sort = TRUE) %>%
   ungroup()

#Check
 bing_word_counts

#Plot
 bing_word_counts %>%
   group_by(sentiment) %>%
   slice_max(n, n = 5) %>%
   ungroup() %>%
   mutate(word = reorder(word, n)) %>%
   ggplot(aes(n, word, fill = sentiment)) +
   geom_col(show.legend = FALSE) +
   facet_wrap(~sentiment, scales = "free_y") +
  labs(x = "Contribution to sentiment",
        y = NULL)

This is how it looks:

My sentiment analysis

This is how it's supposed to look:

Proper graph

Delly
  • 123
  • 1
  • 10

0 Answers0