Exercise

Bing tidy polarity: Call me Ishmael (with ggplot2)!

The last Bing lexicon exercise! In this exercise you will use the pipe operator (%>%) to create a timeline of the sentiment in Moby Dick. In the end you will also create a simple visual following the code structure below. The next chapter goes into more depth for visuals.

ggplot(pivoted_data, aes(index_column, polarity_column)) +
  geom_smooth(se = FALSE)

Instructions 1/2

undefined XP
    1
    2
  • Inner join moby to the bing lexicon.
    • Call inner_join() to join the tibbles.
    • Join by the term column in the text and the word column in the lexicon.
  • Count by sentiment and index.
  • Reshape so that each sentiment has its own column.
    • Call pivot_wider().
    • The names_from column (to split into multiple columns) is sentiment.
    • The values_from column (containing the counts) is n.
    • Also specify values_fill = 0 to fill out missing values with a zero.
  • Use mutate() to add the polarity column. Define it as the difference between the positive and negative columns.
  • arrange is used to order the rows before examination in the final %>%