# Emotional Analysis of “The Fall of the House of Usher” and “The Adventure of the Red Circle”
Download the following two books from Project Gutenberg: - “The Fall of the House of Usher” by Edgar Allan Poe (#932) - “The Adventure of the Red Circle” by Arthur Conan Doyle (#2345)
Use the NRC dictionary to conduct an analysis of emotional words in both texts.
Emotional Words without Positive and Negative Sentiment
# FINAL Project =======================================# Download the following two books from project Gutenberg# "The Fall of the House of Usher" by Edgar Allan Poe (#932)# &# "The Adventure of the Red Circle" by Arthur Conan Doyle (#2345)# Use the nrc dictionary.# conduct an analysis of emotional words in both texts# First, emotional words without positive and negative sentiment# Second, just positive and negative sentiment# Provide your results in a Quarto Document; include visual displays.# Submit an html version of your Quarto document.library(quanteda)
Warning in .recacheSubclasses(def@className, def, env): undefined subclass
"ndiMatrix" of class "replValueSp"; definition not updated
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(tidyr)library(ggplot2)
# Download the texts from Project Gutenbergusher <-gutenberg_download(932)
Determining mirror for Project Gutenberg from https://www.gutenberg.org/robot/harvest
Using mirror http://aleph.gutenberg.org
red_circle <-gutenberg_download(2345)str(usher)
tibble [789 × 2] (S3: tbl_df/tbl/data.frame)
$ gutenberg_id: int [1:789] 932 932 932 932 932 932 932 932 932 932 ...
$ text : chr [1:789] "The Fall of the House of Usher" "" "" " Son coeur est un luth suspendu;" ...
Warning in inner_join(., distinct(nrc), by = "word"): Detected an unexpected many-to-many relationship between `x` and `y`.
ℹ Row 2 of `x` matches multiple rows in `y`.
ℹ Row 13214 of `y` matches multiple rows in `x`.
ℹ If a many-to-many relationship is expected, set `relationship =
"many-to-many"` to silence this warning.
red_circle_sentiments <- red_circle_tokens %>%inner_join(distinct(nrc), by ="word") %>%group_by(word) %>%summarise(sentiment =n_distinct(sentiment))
Warning in inner_join(., distinct(nrc), by = "word"): Detected an unexpected many-to-many relationship between `x` and `y`.
ℹ Row 2 of `x` matches multiple rows in `y`.
ℹ Row 11348 of `y` matches multiple rows in `x`.
ℹ If a many-to-many relationship is expected, set `relationship =
"many-to-many"` to silence this warning.
# Emotional words without positive and negative sentimentusher_emotional <- usher_sentiments %>%filter(!sentiment %in%c("positive", "negative"))red_circle_emotional <- red_circle_sentiments %>%filter(!sentiment %in%c("positive", "negative"))
# Create visual displaysusher_emotional_plot <-ggplot(usher_emotional, aes(x = sentiment, fill = sentiment)) +geom_bar() +labs(title ="Emotional Words Distribution in 'The Fall of the House of Usher'",x ="Sentiment", y ="Count") +theme_minimal()red_circle_emotional_plot <-ggplot(red_circle_emotional, aes(x = sentiment, fill = sentiment)) +geom_bar() +labs(title ="Emotional Words Distribution in 'The Adventure of the Red Circle'",x ="Sentiment", y ="Count") +theme_minimal()usher_pos_neg_plot <-ggplot(usher_pos_neg, aes(x = sentiment, fill = sentiment)) +geom_bar() +labs(title ="Positive and Negative Sentiment Words Distribution in 'The Fall of the House of Usher'",x ="Sentiment", y ="Count") +theme_minimal()red_circle_pos_neg_plot <-ggplot(red_circle_pos_neg, aes(x = sentiment, fill = sentiment)) +geom_bar() +labs(title ="Positive and Negative Sentiment Words Distribution in 'The Adventure of the Red Circle'",x ="Sentiment", y ="Count") +theme_minimal()
# Save plotsggsave("usher_emotional_plot.png", usher_emotional_plot)
Saving 7 x 5 in image
Warning: The following aesthetics were dropped during statistical transformation: fill.
ℹ This can happen when ggplot fails to infer the correct grouping structure in
the data.
ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
Warning: The following aesthetics were dropped during statistical transformation: fill.
ℹ This can happen when ggplot fails to infer the correct grouping structure in
the data.
ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?