IniziaInizia gratis

Word impact, frequency analysis

One of the easiest ways to explore data is with a frequency analysis. Although not difficult, in sentiment analysis this simple method can be surprisingly illuminating. Specifically, you will build a barplot. In this exercise you are once again working with moby and bing to construct your visual.

To get the bars ordered from lowest to highest, you will use a trick with factors. reorder() lets you change the order of factor levels based upon another scoring variable. In this case, you will reorder the factor variable term by the scoring variable polarity.

Questo esercizio fa parte del corso

Sentiment Analysis in R

Visualizza il corso

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

moby_tidy_sentiment <- moby %>% 
  # Inner join to bing lexicon by term = word
  inner_join(bing, by = c("term" = "word")) %>% 
  # Count by term and sentiment, weighted by count
  count(___, ___, wt = ___) %>%
  # Pivot sentiment, using n as values
  pivot_wider(names_from = ___, values_from = ___, values_fill = ___) %>%
  # Mutate to add a polarity column
  mutate(polarity = ___ - ___)

# Review
moby_tidy_sentiment
Modifica ed esegui il codice