Chapter 79 Sentiment Analysis for Results

We investigate how often positive and negative words occurred in these Violation text. Which Results (e.g. Pass , Fail , Out of Business ) were the most positive or negative overall?

We will use the AFINN sentiment lexicon, which provides numeric positivity scores for each word, and visualize it with a bar plot.

FoodInspectionWords_sentiments <- FoodInspectionWords %>%
  inner_join(get_sentiments("afinn"), by = "word") %>%
  group_by(Results) %>%
  dplyr::summarize(score = sum(score * n) / sum(n)) %>%
  arrange(desc(score))

FoodInspectionWords_sentiments %>%
  mutate(Results = reorder(Results, score)) %>%
  ggplot(aes(Results, score, fill = Results)) +
  geom_col(show.legend = TRUE) +
  coord_flip() +
  ylab("Average sentiment score") + theme_bw()

As expected, the sentiments are ordered in the following order

  1. Pass has the MOST postive sentiment
  2. Out of Business , Pass w/ Conditions, No Entry follows Next
  3. Fail
  4. Not Ready