── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Load the project gutenberg texts and text data for processing
usher <-gutenberg_download(932)
Determining mirror for Project Gutenberg from https://www.gutenberg.org/robot/harvest
# Combine corpus1 and corpus2data_pos_neg <-bind_rows(corpus1, corpus2) %>%mutate(sentiment =ifelse(sentiment_score %in%c(1, 2, 3), "negative", "positive")) %>%filter(sentiment %in%c("positive", "negative"))# Display the number of rows after filteringprint("Number of rows after filtering:")
[1] "Number of rows after filtering:"
print(nrow(data_pos_neg))
[1] 851
# Display the first few rows of data_pos_negprint("First few rows of data_pos_neg:")
Emotional Words Without Negative and Positive Sentiments
# Assuming sentiment_score is a column in corpus1 and corpus2# Filter emotional words without positive and negative sentimentusher_emotional <- corpus1 %>%filter(sentiment_score !="positive"& sentiment_score !="negative")red_circle_emotional <- corpus2 %>%filter(sentiment_score !="positive"& sentiment_score !="negative")# Create plots for emotional words distributionusher_emotional_plot <-ggplot(usher_emotional, aes(x = word)) +geom_bar() +labs(title ="Emotional Words Distribution in 'The Fall of the House of Usher'",x ="Words", y ="Count") +theme_minimal()red_circle_emotional_plot <-ggplot(red_circle_emotional, aes(x = word)) +geom_bar() +labs(title ="Emotional Words Distribution in 'The Adventure of the Red Circle'",x ="Words", y ="Count") +theme_minimal()
Create bar plots for negative and positive sentiments
# Convert sentiment_score to factordata_pos_neg$sentiment_score <-factor(data_pos_neg$sentiment_score, levels =c("positive", "negative"))# Create bar plots for positive and negative sentiment words distributionpositive_words_plot <-ggplot(data_pos_neg, aes(x = word, y = sentiment_score, fill = sentiment)) +geom_bar(stat ="identity", position ="dodge") +theme_minimal() +labs(title ="Positive Sentiment Words Distribution",x ="Words", y ="Sentiment") +# Change "Sentiment Score" to "Sentiment"scale_fill_manual(values =c("positive"="#31A354", "negative"="#E4BFBF")) # Use scale_fill_manual for discrete valuesnegative_words_plot <-ggplot(data_pos_neg, aes(x = word, y = sentiment_score, fill = sentiment)) +geom_bar(stat ="identity", position ="dodge") +theme_minimal() +labs(title ="Negative Sentiment Words Distribution",x ="Words", y ="Sentiment") +# Change "Sentiment Score" to "Sentiment"scale_fill_manual(values =c("positive"="#31A354", "negative"="#E4BFBF")) # Use scale_fill_manual for discrete values