Charlotte Turner Text Project of Civil War Speeches

MEA 3290 Text Project

By: Charlotte Turner

For my Text Analysis project, I will be analyzing the differences in sentiment between speeches made by Confederate military leaders and speeches made by Union military leaders during the Civil War in America. This war took place between 1871-1875 and the speeches. I am analyzing all took place during these years. For my hypothesis about these speeches, I believe that the overall sentiment of Confederate speeches will include more negative diction than the Union speeches. I also hypothesize that Union speeches will include more positive description words of the common words in my bigram analysis.

First, I had to upload the necessary libraries for this project:

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── 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
library(tidytext)
library(textdata)
library(wordcloud2)
library(ggplot2)

The Union speeches I am analyzing include Abraham Lincoln’s “First Inaugural Address” and his “Gettysburg Address” speeches, along with William Sherman’s speech to the Union army. The Confederate speeches I am analyzing include Jefferson Davis’ speeches to the Confederate army in both Richmond and Danville, Virginia, and Alexander Stephens’“Cornerstone” speech. All of these speeches were given by major military leaders for both armys during the war.

library(readr)
UnionSpeeches <- read_csv("~/R Studio Files/Downloaded Data/UnionSpeeches.txt", col_names = FALSE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
  dat <- vroom(...)
  problems(dat)
Rows: 22 Columns: 1
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (1): X1

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
library(readr)
ConfederateSpeeches <- read_delim("~/R Studio Files/Downloaded Data/ConfederateSpeeches.txt", delim = "\t", escape_double = FALSE, col_names = FALSE, trim_ws = TRUE)
Rows: 61 Columns: 1
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (1): X1

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Displays of Analysis

Common Words: Charts

For my first display, I will be creating a table that displays the top 15 most frequent words & phrases included within the speeches. I will separate my displays by ’Union” and “Confederacy”.

UnionSpeeches |>
  unnest_tokens(word, X1) |>
  count(word, sort = TRUE) |>
  anti_join(stop_words) |> 
  head(15) -> US_TopCommonWords
Joining with `by = join_by(word)`
  US_TopCommonWords |> 
    ggplot(aes(word, n, fill = word)) + geom_col() + theme_classic() + labs (title = "Most Common Union Words")

ConfederateSpeeches |>
    unnest_tokens(word, X1) |>
    count(word, sort = TRUE) |>
    anti_join(stop_words) |> 
    head(15) -> CS_TopCommonWords
Joining with `by = join_by(word)`
CS_TopCommonWords |> 
  ggplot(aes(word, n, fill = word)) + geom_col() + theme_classic() + labs (title = "Most Common Confederate Words")

Based on these tables, “constitution”, “government”, and “laws” are the overlapping most common words for both militaries. Both tables also contain “constitution” as the most common word. For Union speeches, the word “Union” is within the top 15 words, but for Confederate speeches, the word “Confederate” or “Confederacy” is not within the top 15 words. Because the Confederacy refrained from officially labeling their military and highlighting their affiliation, this might relate to the Confederacy’s lack of official Presidential and US Federal support during the Civil War in America.

Common Words: Wordcloud Display

For my next display, I will create a more visually appealing method of display and create a word cloud to show all of the most common words for both speech types. I created another table with all of the common words, without a maximum.

 UnionSpeeches |>
    unnest_tokens(word, X1) |>
    count(word, sort = TRUE) |>
    anti_join(stop_words) -> US_CommonWords
Joining with `by = join_by(word)`
  wordcloud2(US_CommonWords)
ConfederateSpeeches |> 
    unnest_tokens(word, X1) |>
    count(word, sort = TRUE) |>
    anti_join(stop_words) -> CS_CommonWords
Joining with `by = join_by(word)`
  wordcloud2(CS_CommonWords)

These displays show how Union speeches more commonly included their label or name of their military, along with other nouns and terms related to the Union/general war. The displays also show how Confederate speeches more commonly included more descriptive and randomized words, but specifically lacked a label or name for their military. This might reflect the lack of official title that the Confederacy had during the war due to the President and Federal legislators not supporting their ideals.

Bi-gram Analysis: “Constitution”

Next for my displays, I want to analyze the words that come before and after the common word “constitution” in both Union and Confederate speeches. First, I began with creating a bi-gram analysis of the words, highlighting the word “constitution”.

UnionSpeeches |> 
    unnest_tokens(bigram, X1, token="ngrams", n=2) -> US_Bigrams
  
  US_Bigrams |> 
    separate(bigram, c('word1', 'word2'),sep=" ") |>
    filter(!word1%in% stop_words$word) |>
    filter(!word2%in% stop_words$word) |>
    count(word1, word2, sort=TRUE) -> US_BigramSandwich
  
  US_BigramSandwich |> 
    filter(word1 %in% 'constitution') |> 
    arrange(desc(n))
# A tibble: 2 × 3
  word1        word2          n
  <chr>        <chr>      <int>
1 constitution amended        1
2 constitution unimpaired     1
  US_BigramSandwich |> 
    filter(word2 %in% 'constitution') |> 
    arrange(desc(n))
# A tibble: 1 × 3
  word1    word2            n
  <chr>    <chr>        <int>
1 national constitution     3
ConfederateSpeeches |> 
    unnest_tokens(bigram, X1, token="ngrams", n=2) -> CS_Bigrams
  
  CS_Bigrams |> 
    separate(bigram, c('word1', 'word2'),sep=" ") |>
    filter(!word1%in% stop_words$word) |>
    filter(!word2%in% stop_words$word) -> CS_BigramSandwich
  
 CS_BigramSandwich |> 
   filter(word1 %in% 'constitution') |> 
   count(word1, word2, sort=TRUE) |> 
   arrange(desc(n))
# A tibble: 2 × 3
  word1        word2         n
  <chr>        <chr>     <int>
1 constitution provision     1
2 constitution relates       1
  CS_BigramSandwich |> 
  filter(word2 %in% 'constitution') |> 
  count(word1, word2, sort=TRUE) |> 
  arrange(desc(n))
# A tibble: 1 × 3
  word1   word2            n
  <chr>   <chr>        <int>
1 british constitution     1

These displays show differences in descriptions of the Constitution in the Union and Confederate speeches. In the Union Bi-grams, the Constitution is defined as “unimpaired” and “amended”. In the Confederate Bi-grams, the Constitution is described using words of “provision” and mentions the “British” Constitution. This shows how the Union military was fighting for no changes to legislation, as opposed to the Confederacy which aimed to change the foundational document.

Sentiment Analysis

For my final display, I will be analyzing the overall sentiments of both types of speeches. I will create a graph that separates the speeches and displays the negative and positive sentiments of both speech types.

union_df <- data.frame(text = UnionSpeeches, label = "Union")
confederate_df <- data.frame(text = ConfederateSpeeches, label = "Confederate")
combined_df <- rbind(union_df, confederate_df)
  
 combined_sentiment <- combined_df |> 
  unnest_tokens(word, X1) |> 
  anti_join(stop_words) |> 
  inner_join(get_sentiments('afinn')) |> 
  group_by(label) |> 
  summarize(sentiment_score = sum(value))
Joining with `by = join_by(word)`
Joining with `by = join_by(word)`
  ggplot(combined_sentiment, aes(x = label, y = sentiment_score, fill = label)) +
    geom_bar(stat = "identity") +
    labs(title = "Sentiment Analysis of Union and Confederate Speeches", x = "Label", y = "Sentiment Score") +
    scale_fill_manual(values = c("Union" = "blue", "Confederate" = "red")) + theme_minimal()

This sentiment analysis displays how the words used in Confederate speeches contain majority positive (high) sentiments, and words in Union speeches contain majority negative (low) sentiments. This does not support my prior hypothesis that Union speeches would be more positive than Confederate speeches. With these findings, they might reflect the supportive nature of the Confederate army. Also, this data might reflect how the Union army did not support the ideals and behaviors of America at the time.

Conclusion

In conclusion, I have analyzed the major differences between the Union and Confederate military speeches. Through word frequency, I analyzed the most common words of both militaries and individually. I also created visualizations to display the differences of the speech types. I further determined that the word “constitution” was described in differing ways in both militaries the Union taking a firm stance, and the Confederate taking a more change-embraced stance. Overall, the sentiments of both speech types are different. The Confederate speeches took a more positive route, supporting their internal military. The Union took a more negative route, diminishing slavery and the nation’s actions. These analyses helped me better understand the differences between Union and Confederate military practices and outlooks.