manifesto_words |>inner_join(bing) |>count(word, sentiment, sort =TRUE) |>group_by(sentiment) |>top_n(10) |>ungroup() |>mutate(word =reorder(word, n)) |>ggplot(aes(word, n, fill = sentiment)) +geom_col(show.legend =FALSE) +facet_wrap(vars(sentiment), scales ="free") +labs(y ="Manifestos: Words that contribute the most to each sentiment",x =NULL) +scale_fill_viridis_d() +coord_flip() +theme_minimal()
Joining with `by = join_by(word)`
Selecting by n
These graphs show the most common positive and negative words in the manifestos.
manifestos |>unnest_tokens(bigram, text, token ="ngrams", n =2) |>select(bigram) -> manifesto_bigrams
manifesto_bigrams |>count(bigram, sort = T)
# A tibble: 14,954 × 2
bigram n
<chr> <int>
1 of the 159
2 in the 81
3 to the 69
4 i was 60
5 and the 56
6 to be 43
7 political correctness 37
8 i had 34
9 it is 34
10 it was 30
# ℹ 14,944 more rows
This table shows the most common bigrams present in the manifestos.
# A tibble: 4,861 × 1
bigram
<chr>
1 industrial society
2 future introduction
3 introduction 1
4 industrial revolution
5 human race
6 greatly increased
7 life expectancy
8 advanced countries
9 destabilized society
10 made life
# ℹ 4,851 more rows
This table shows the most common bigrams present in the manifestos when the stop words are removed.
# A tibble: 142 × 3
word1 word2 n
<chr> <chr> <int>
1 my life 28
2 my mother 25
3 my father 21
4 my parents 18
5 my first 10
6 my father’s 7
7 my favorite 7
8 my new 6
9 world population 6
10 my class 5
# ℹ 132 more rows
This table shows the the most common words that came after the words “my” and “world” in the manifestos.
first_word <-c("my", "world")manifesto_bigrams |>count(bigram, sort = T) |>separate(bigram, c("word1", "word2"), sep =" ") |>filter(word1 %in% first_word) |>count(word1, word2, wt = n, sort =TRUE) |>mutate(word2 =factor(word2, levels =rev(unique(word2)))) |>group_by(word1) |>top_n(5) |>ggplot(aes(word2, n, fill = word1)) +scale_fill_viridis_d() +geom_col(show.legend =FALSE) +labs(x =NULL, y =NULL, title ="Word following:") +facet_wrap(~word1, scales ="free") +coord_flip() +theme_minimal()
Selecting by n
These graphs show the most common words that came after the words “my” or “world” in the manifestos.