plot_net_sentiment_long_nrc.Rd
Bar plots of NRC sentiment counts in one or more documents.
plot_net_sentiment_long_nrc(net_sentiment_long_nrc)
net_sentiment_long_nrc | A data frame from
|
---|
A ggplot
(ggplot::geom_col
).
library(experienceAnalysis) books <- janeaustenr::austen_books() # Jane Austen books emma <- paste(books[books$book == "Emma", ], collapse = " ") # String with whole book pp <- paste(books[books$book == "Pride & Prejudice", ], collapse = " ") # String with whole book # Make data frame with books Emma and Pride & Prejudice x <- data.frame( text = c(emma, pp), book = c("Emma", "Pride & Prejudice") ) # Net sentiment in each book net_sentiment_wide_nrc <- calc_net_sentiment_nrc(x, target_col_name = "book", text_col_name = "text", filter_class = NULL) net_sentiment_wide_nrc#> # A tibble: 2 x 13 #> text linenumber anger anticipation disgust fear joy negative positive #> <chr> <int> <int> <int> <int> <int> <int> <int> <int> #> 1 "c(\"EMMA~ 1 1548 4821 1323 2343 4432 4473 9471 #> 2 "c(\"PRID~ 2 1295 3596 973 1767 3336 3641 7443 #> # ... with 4 more variables: sadness <int>, surprise <int>, trust <int>, #> # book <chr># Tidy net_sentiment_wide_nrc and place the most "angry" book at the top net_sentiment_long_nrc <- tidy_net_sentiment_nrc(net_sentiment_wide_nrc, sorting_sentiments = "anger", num_of_docs = 2) %>% dplyr::select(-text) net_sentiment_long_nrc#> # A tibble: 20 x 4 #> linenumber book name value #> <fct> <chr> <fct> <int> #> 1 1 Emma anger 1548 #> 2 1 Emma anticipation 4821 #> 3 1 Emma disgust 1323 #> 4 1 Emma fear 2343 #> 5 1 Emma joy 4432 #> 6 1 Emma negative 4473 #> 7 1 Emma positive 9471 #> 8 1 Emma sadness 2253 #> 9 1 Emma surprise 2220 #> 10 1 Emma trust 5613 #> 11 2 Pride & Prejudice anger 1295 #> 12 2 Pride & Prejudice anticipation 3596 #> 13 2 Pride & Prejudice disgust 973 #> 14 2 Pride & Prejudice fear 1767 #> 15 2 Pride & Prejudice joy 3336 #> 16 2 Pride & Prejudice negative 3641 #> 17 2 Pride & Prejudice positive 7443 #> 18 2 Pride & Prejudice sadness 1755 #> 19 2 Pride & Prejudice surprise 1665 #> 20 2 Pride & Prejudice trust 4180plot_net_sentiment_long_nrc(net_sentiment_long_nrc)