```r
newsgroup_sentiments <- words_by_newsgroup %>%
  inner_join(get_sentiments("afinn"), by = "word") %>%
  group_by(newsgroup) %>%
  summarize(score = sum(score * n) / sum(n))

newsgroup_sentiments %>%
  mutate(newsgroup = reorder(newsgroup, score)) %>%
  ggplot(aes(newsgroup, score, fill = score > 0)) +
  geom_col(show.legend = FALSE) +
  coord_flip() +
  ylab("Average sentiment score")
```

<div class="figure">
<img src="09-usenet_files/figure-epub3/newsgroupsentiments-1.png" alt="Average AFINN score for posts within each newsgroup"  />
<p class="caption">(\#fig:newsgroupsentiments)Average AFINN score for posts within each newsgroup</p>
</div>