Sentiment Analysis Using Text Mining in R: Jane Austen and Macbeth

Author

Lionel Desroses

Published

November 8, 2026

Introduction

Sentiment analysis is a text mining technique used to identify and measure the emotional tone expressed within a body of text. By comparing words in a document against a predefined sentiment lexicon, researchers can quantify positive, negative, and emotional content. This approach is widely used in fields such as social media analysis, customer feedback evaluation, political science, and literary analysis.

In Chapter 2 of Text Mining with R, Silge and Robinson demonstrate how sentiment analysis can be performed using the tidytext framework and several sentiment lexicons. Their example analyzes the text of Jane Austen novels and explores how sentiment changes throughout the books.

In This assignment i will attempt to reproduces the sentiment analysis example from Chapter 2 and then extends the analysis in two ways. First, I will use and analyze the text , Shakespeare’s Macbeth, using the same methodology. Second, I will use an additional sentiment lexicon to incorporated and provide a more detailed examination of emotional content. The results from these analyses will be compared to determine how different texts and lexicons influence sentiment measurements.

Approach

The assignment will be completed in two phases. in The first phase,I will reproduce the example presented in Chapter 2 of Text Mining with R. The Jane Austen text corpus provided through the janeaustenr package will be processed using the tidytext package. The text will be tokenized into individual words and matched against the Bing sentiment lexicon to classify words as positive or negative. Visualizations will be generated to illustrate sentiment trends throughout the novels.

In The second phase, I will extend the analysis by replacing the Jane Austen corpus with Shakespeare’s Macbeth, obtained from Project Gutenberg. The same text mining workflow will be applied to allow for direct comparison with the original example.

To further enhance the analysis, the NRC sentiment lexicon will be incorporated. The NRC lexicon categorizes words into emotional dimensions such as joy, fear, anger, trust, sadness, anticipation, surprise, and disgust. This additional analysis will provide a more detailed understanding of the emotional themes present in Macbeth.

The results from both corpora and both lexicons will be summarized and compared through tables, visualizations, and narrative discussion.