Chapter 50 Homer Simpson

We examine Homer with the help of the Word Cloud, The Postive and Not so Postive words , and how the postivity differs from one Location to the other.

50.1 Word Cloud

SC = ScriptsCharacters %>%
   select(id,name,normalized_text)

SC %>%
  unnest_tokens(word, normalized_text) %>%
  filter(name == "Homer Simpson") %>%
  dplyr::count(name, word, sort = TRUE) %>%
  group_by(word) %>%
  summarize(occurences = n()) %>%
  
  with(wordcloud(word, occurences, max.words = 50,colors=brewer.pal(8, "Dark2")))

50.2 Postive and Not So Postive Words of Homer Simpson

The following graph shows the Twenty high positive and the negative words by Homer Simpson.

contributions <- SC %>%
  unnest_tokens(word, normalized_text) %>%
  filter(name == "Homer Simpson") %>%
  dplyr::count(name, word, sort = TRUE) %>%
  ungroup() %>%
  
  inner_join(get_sentiments("afinn"), by = "word") %>%
  group_by(word) %>%
  summarize(occurences = n(),
            contribution = sum(score))

contributions %>%
  top_n(20, abs(contribution)) %>%
  mutate(word = reorder(word, contribution)) %>%
  head(20) %>%
  ggplot(aes(word, contribution, fill = contribution > 0)) +
  geom_col(show.legend = FALSE) +
  coord_flip() + theme_bw()

50.3 Sentiment Analysis based on location

We wish to analyse the sentiments of Homer based on the location.We want to find out whether Homer’s positivity or negativity changes based on where he is located

visualize_sentiments_location <- function(SCWords) {
  SCWords_sentiments <- SCWords %>%
    inner_join(get_sentiments("afinn"), by = "word") %>%
    group_by(raw_location_text) %>%
    summarize(score = sum(score * n) / sum(n)) %>%
    arrange(desc(score)) 
  
  SCWords_sentiments %>%
    mutate(raw_location_text = reorder(raw_location_text, score)) %>%
    ggplot(aes(raw_location_text, score)) +
    geom_col(fill = fillColor2) +
    coord_flip() +
    ylab("Average sentiment score") + theme_bw()
}

nameOfCharacter = "Homer Simpson"

HomerLocation = LocationCharacters %>%
  filter(name == "Homer Simpson") %>%
  arrange(desc(n)) %>%
  head(10)

SCWordsHomerSimpson <- ScriptsCharacters %>%
  unnest_tokens(word, normalized_text) %>%
  filter(name == nameOfCharacter) %>%
  filter(raw_location_text %in% HomerLocation$raw_location_text) %>%
  dplyr::count(raw_location_text, word, sort = TRUE) %>%
  ungroup()

visualize_sentiments_location(SCWordsHomerSimpson)

Homer seems to be positive in the Kitchen, which is expected since the food is there. He has to postive in work and the positivity is shown in his work place Springfield Nuclear Power Plant.