```r
library(ggplot2)

ap_sentiments %>%
  count(sentiment, term, wt = count) %>%
  ungroup() %>%
  filter(n >= 200) %>%
  mutate(n = ifelse(sentiment == "negative", -n, n)) %>%
  mutate(term = reorder(term, n)) %>%
  ggplot(aes(term, n, fill = sentiment)) +
  geom_bar(stat = "identity") +
  ylab("Contribution to sentiment") +
  coord_flip()
```

<div class="figure">
<img src="05-document-term-matrices_files/figure-epub3/apsentimentplot-1.png" alt="Words from AP articles with the greatest contribution to positive or negative sentiments, using the Bing sentiment lexicon."  />
<p class="caption">(\#fig:apsentimentplot)Words from AP articles with the greatest contribution to positive or negative sentiments, using the Bing sentiment lexicon.</p>
</div>