Chapter 81 Sentiment analysis by word for Each Result Type
We visualize the most important contributors within each Result Type here.
FoodInspectionWords %>%
inner_join(get_sentiments("afinn"), by = "word") %>%
mutate(contribution = score * n / sum(n)) %>%
top_n(20, abs(contribution)) %>%
mutate(word = reorder(word, contribution)) %>%
ggplot(aes(word, contribution, fill = contribution > 0)) +
geom_col(show.legend = FALSE) +
facet_wrap(~Results, ncol = 2, scales = "free_y") +
coord_flip() + theme_bw()