plot_net_sentiment_long_nrc: Plot sentiment counts in a text

Description Usage Arguments Value Examples

View source: R/plot_net_sentiment_long_nrc.R

Description

Bar plots of NRC sentiment counts in one or more documents.

Usage

1
plot_net_sentiment_long_nrc(net_sentiment_long_nrc)

Arguments

net_sentiment_long_nrc

A data frame from tidy_net_sentiment_nrc.

Value

A ggplot (ggplot::geom_col).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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

# 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

plot_net_sentiment_long_nrc(net_sentiment_long_nrc)

CDU-data-science-team/experienceAnalysis documentation built on Dec. 17, 2021, 12:53 p.m.