Republican and Democratic Conventions of 2020

Author

Meghan Coyne

Hypothesis

How do the Republican and Democratic conventions of 2020 compare to each other in the realm of common words used and overall positivity or negativity?

First, I installed all the necessary packages.

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(ggthemes)
library(plotly) 

Attaching package: 'plotly'

The following object is masked from 'package:ggplot2':

    last_plot

The following object is masked from 'package:stats':

    filter

The following object is masked from 'package:graphics':

    layout

Next, downloaded all of the speeches from the 2020 Democratic Convention.

library(readr)
alexandria_ocasio_cortex <- read_delim("dem/alexandria_ocasio-cortex.txt", 
                                       delim = "^", escape_double = FALSE, col_names = FALSE, 
                                       trim_ws = TRUE) 
Rows: 1 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.
alexandria_ocasio_cortex |> 
  unnest_tokens(word, X1) |> 
  mutate(Speaker = "Ocasio_Cortez") |> 
  mutate(Party = "Democratic") -> alexandria_ocasio_cortex 

#
library(readr)
andrew_cuomo <- read_delim("dem/andrew_cuomo.txt", 
                           delim = "^", escape_double = FALSE, col_names = FALSE, 
                           trim_ws = TRUE)
Rows: 1 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.
andrew_cuomo |> 
  unnest_tokens(word, X1) |> 
  mutate(Speaker = "Andrew_Cuomo") |> 
  mutate(Party = "Democratic") -> andrew_cuomo  

#
library(readr)
andrew_yang <- read_delim("dem/andrew_yang.txt", 
                          delim = "^", escape_double = FALSE, col_names = FALSE, 
                          trim_ws = TRUE)
Rows: 1 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.
andrew_yang |> 
  unnest_tokens(word, X1) |>  
  mutate(Speaker = "Andrew_Yang") |> 
  mutate(Party = "Democratic") -> andrew_yang  

#
library(readr)
barack_obama <- read_delim("dem/barack_obama.txt", 
                           delim = "^", escape_double = FALSE, col_names = FALSE, 
                           trim_ws = TRUE)
Rows: 1 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.
barack_obama |> 
  unnest_tokens(word, X1) |>  
  mutate(Speaker = "Barack_Obama") |> 
  mutate(Party = "Democratic") -> barack_obama 

#
library(readr)
bernie_sanders <- read_delim("dem/bernie_sanders.txt", 
                             delim = "^", escape_double = FALSE, col_names = FALSE, 
                             trim_ws = TRUE)
Rows: 1 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.
bernie_sanders |> 
  unnest_tokens(word, X1) |> 
  mutate(Speaker = "Bernie_Sanders") |> 
  mutate(Party = "Democratic") -> bernie_sanders  

#
library(readr)
bill_clinton <- read_delim("dem/bill_clinton.txt", 
                           delim = "^", escape_double = FALSE, col_names = FALSE, 
                           trim_ws = TRUE)
Rows: 1 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.
bill_clinton |> 
  unnest_tokens(word, X1) |> 
  mutate(Speaker = "Bill_Clinton") |> 
  mutate(Party = "Democratic") -> bill_clinton  

#
library(readr)
chuck_schumer <- read_delim("dem/chuck_schumer.txt", 
                            delim = "^", escape_double = FALSE, col_names = FALSE, 
                            trim_ws = TRUE)
Rows: 1 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.
chuck_schumer |> 
  unnest_tokens(word, X1) |>  
  mutate(Speaker = "Chuck_Schumer") |> 
  mutate(Party = "Democratic") -> chuck_schumer 

#
library(readr)
colin_powell <- read_delim("dem/colin_powell.txt", 
                           delim = "^", escape_double = FALSE, col_names = FALSE, 
                           trim_ws = TRUE)
Rows: 1 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.
colin_powell |> 
  unnest_tokens(word, X1) |> 
  mutate(Speaker = "Colin_Powell") |> 
  mutate(Party = "Democratic") -> colin_powell  

#
library(readr)
cory_booker <- read_delim("dem/cory_booker.txt", 
                          delim = "^", escape_double = FALSE, col_names = FALSE, 
                          trim_ws = TRUE)
Rows: 1 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.
cory_booker |> 
  unnest_tokens(word, X1) |> 
  mutate(Speaker = "Cory_Booker") |> 
  mutate(Party = "Democratic") -> cory_booker 

#
library(readr)
dr_jill_biden <- read_delim("dem/dr_jill_biden.txt", 
                            delim = "^", escape_double = FALSE, col_names = FALSE, 
                            trim_ws = TRUE)
Rows: 1 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.
dr_jill_biden |> 
  unnest_tokens(word, X1) |> 
  mutate(Speaker = "Dr_Jill_Biden") |> 
  mutate(Party = "Democratic") -> dr_jill_biden 

#
library(readr)
elizabeth_warren <- read_delim("dem/elizabeth_warren.txt", 
                               delim = "^", escape_double = FALSE, col_names = FALSE, 
                               trim_ws = TRUE)
Rows: 1 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.
elizabeth_warren |> 
  unnest_tokens(word, X1) |> 
  mutate(Speaker = "Elizabeth_Warren") |> 
  mutate(Party = "Democratic") -> elizabeth_warren  

#
library(readr)
gavin_newsom <- read_delim("dem/gavin_newsom.txt", 
                           delim = "^", escape_double = FALSE, col_names = FALSE, 
                           trim_ws = TRUE)
Rows: 1 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.
gavin_newsom |> 
  unnest_tokens(word, X1) |> 
  mutate(Speaker = "Gavin_Newsom") |> 
  mutate(Party = "Democratic") -> gavin_newsom  

#
library(readr)
hillary_clinton <- read_delim("dem/hillary_clinton.txt", 
                              delim = "^", escape_double = FALSE, col_names = FALSE, 
                              trim_ws = TRUE)
Rows: 1 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.
hillary_clinton |> 
  unnest_tokens(word, X1) |> 
  mutate(Speaker = "Hillary_Clinton") |> 
  mutate(Party = "Democratic") -> hillary_clinton 

#
library(readr)
joe_biden <- read_delim("dem/joe_biden.txt", 
                        delim = "^", escape_double = FALSE, col_names = FALSE, 
                        trim_ws = TRUE)
Rows: 1 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.
joe_biden |> 
  unnest_tokens(word, X1) |> 
  mutate(Speaker = "Joe_Biden") |> 
  mutate(Party = "Democratic") -> joe_biden 

#
library(readr)
john_kasich <- read_delim("dem/john_kasich.txt", 
                          delim = "^", escape_double = FALSE, col_names = FALSE, 
                          trim_ws = TRUE)
Rows: 1 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.
john_kasich |> 
  unnest_tokens(word, X1) |>  
  mutate(Speaker = "John_Kasich") |> 
  mutate(Party = "Democratic") -> john_kasich 

#
library(readr)
kamala_harris <- read_delim("dem/kamala_harris.txt", 
                            delim = "^", escape_double = FALSE, col_names = FALSE, 
                            trim_ws = TRUE)
Rows: 1 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.
kamala_harris |> 
  unnest_tokens(word, X1) |>   
  mutate(Speaker = "Kamala_Harris") |> 
  mutate(Party = "Democratic") -> kamala_harris  

#
library(readr)
michael_bloomberg <- read_delim("dem/michael_bloomberg.txt", 
                                delim = "^", escape_double = FALSE, col_names = FALSE, 
                                trim_ws = TRUE)
Rows: 1 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.
michael_bloomberg |> 
  unnest_tokens(word, X1) |>    
  mutate(Speaker = "Michael_Bloomberg") |> 
  mutate(Party = "Democratic") -> michael_bloomberg  

#
library(readr)
michelle_obama <- read_delim("dem/michelle_obama.txt", 
                             delim = "^", escape_double = FALSE, col_names = FALSE, 
                             trim_ws = TRUE)
Rows: 1 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.
michelle_obama |> 
  unnest_tokens(word, X1) |>     
  mutate(Speaker = "Michelle_Obama") |> 
  mutate(Party = "Democratic") -> michelle_obama  

#
library(readr)
nancy_pelosi <- read_delim("dem/nancy_pelosi.txt", 
                           delim = "^", escape_double = FALSE, col_names = FALSE, 
                           trim_ws = TRUE)
Rows: 1 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.
nancy_pelosi |> 
  unnest_tokens(word, X1) |>      
  mutate(Speaker = "Nancy_Pelosi") |> 
  mutate(Party = "Democratic") -> nancy_pelosi  

#
library(readr)
pete_buttigieg <- read_delim("dem/pete_buttigieg.txt", 
                             delim = "^", escape_double = FALSE, col_names = FALSE, 
                             trim_ws = TRUE)
Rows: 1 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.
pete_buttigieg |> 
  unnest_tokens(word, X1) |>       
  mutate(Speaker = "Pete_Buttigieg") |> 
  mutate(Party = "Democratic") -> pete_buttigieg 

#
library(readr)
sarah_cooper <- read_delim("dem/sarah_cooper.txt", 
                           delim = "^", escape_double = FALSE, col_names = FALSE, 
                           trim_ws = TRUE)
Rows: 1 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.
sarah_cooper |> 
  unnest_tokens(word, X1) |>        
  mutate(Speaker = "Sarah_Cooper") |> 
  mutate(Party = "Democratic") -> sarah_cooper 

I then merged all the democratic speeches into one data set,

dem2020 <- rbind(sarah_cooper, pete_buttigieg, nancy_pelosi, michael_bloomberg, michelle_obama, kamala_harris, john_kasich, joe_biden, hillary_clinton, gavin_newsom, elizabeth_warren, dr_jill_biden, cory_booker, colin_powell,chuck_schumer, bill_clinton,bernie_sanders, barack_obama, andrew_cuomo, andrew_yang, alexandria_ocasio_cortex) 

I repeated the same process by downloading all speeches from the 2020 Republican Convention.

library(readr)
ben_carson <- read_delim("rep/ben_carson.txt", 
                         delim = "^", escape_double = FALSE, col_names = FALSE, 
                         trim_ws = TRUE)
Rows: 1 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.
ben_carson |> 
  unnest_tokens(word, X1) |>        
  mutate(Speaker = "Ben_Carson") |> 
  mutate(Party = "Republican") -> ben_carson 
#
library(readr)
chen_guangcheng <- read_delim("rep/chen_guangcheng.txt", 
                              delim = "^", escape_double = FALSE, col_names = FALSE, 
                              trim_ws = TRUE)
Rows: 1 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.
chen_guangcheng |> 
  unnest_tokens(word, X1) |>         
  mutate(Speaker = "Chen_Guangcheng") |> 
  mutate(Party = "Republican") -> chen_guangcheng 
#
library(readr)
dan_crenshaw <- read_delim("rep/dan_crenshaw.txt", 
                           delim = "^", escape_double = FALSE, col_names = FALSE, 
                           trim_ws = TRUE)
Rows: 1 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.
dan_crenshaw |> 
  unnest_tokens(word, X1) |>          
  mutate(Speaker = "Dan_Crenshaw") |> 
  mutate(Party = "Republican") -> dan_crenshaw 
#
library(readr)
dana_white <- read_delim("rep/dana_white.txt", 
                         delim = "^", escape_double = FALSE, col_names = FALSE, 
                         trim_ws = TRUE)
Rows: 1 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.
dana_white|> 
  unnest_tokens(word, X1) |>           
  mutate(Speaker = "Dana_White") |> 
  mutate(Party = "Republican") -> dana_white 
#
library(readr)
donald_trump_first_speech <- read_delim("rep/donald_trump_first_speech.txt", 
                                        delim = "^", escape_double = FALSE, col_names = FALSE, 
                                        trim_ws = TRUE)
Rows: 1 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.
donald_trump_first_speech|> 
  unnest_tokens(word, X1) |>           
  mutate(Speaker = "Donald_Trump") |> 
  mutate(Party = "Republican") -> donald_trump_first_speech 
#
library(readr)
donald_trump_jr <- read_delim("rep/donald_trump_jr.txt", 
                              delim = "^", escape_double = FALSE, col_names = FALSE, 
                              trim_ws = TRUE)
Rows: 1 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.
donald_trump_jr |> 
  unnest_tokens(word, X1) |> 
  mutate(Speaker = "Donald_Trump_JR") |> 
  mutate(Party = "Republican") -> donald_trump_jr 
#
library(readr)
donald_trump_second_speech <- read_delim("rep/donald_trump_second_speech.txt", 
                                         delim = "^", escape_double = FALSE, col_names = FALSE, 
                                         trim_ws = TRUE)
Rows: 1 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.
donald_trump_second_speech |> 
  unnest_tokens(word, X1) |>  
  mutate(Speaker = "Donald_Trump") |> 
  mutate(Party = "Republican") -> donald_trump_second_speech 
#
library(readr)
eric_trump <- read_delim("rep/eric_trump.txt", 
                         delim = "^", escape_double = FALSE, col_names = FALSE, 
                         trim_ws = TRUE)
Rows: 1 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.
eric_trump |> 
  unnest_tokens(word, X1) |>   
  mutate(Speaker = "Eric_Trump") |> 
  mutate(Party = "Republican") -> eric_trump 
#
library(readr)
herschel_walker <- read_delim("rep/herschel_walker.txt", 
                              delim = "^", escape_double = FALSE, col_names = FALSE, 
                              trim_ws = TRUE)
Rows: 1 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.
herschel_walker |> 
  unnest_tokens(word, X1) |>    
  mutate(Speaker = "Herschel_Walker") |> 
  mutate(Party = "Republican") -> herschel_walker 
#
library(readr)
ivanka_trump <- read_delim("rep/ivanka_trump.txt", 
                           delim = "^", escape_double = FALSE, col_names = FALSE, 
                           trim_ws = TRUE)
Rows: 1 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.
ivanka_trump |> 
  unnest_tokens(word, X1) |>      
  mutate(Speaker = "Ivanka_Trump") |> 
  mutate(Party = "Republican") -> ivanka_trump  
#
library(readr)
jack_brewer <- read_delim("rep/jack_brewer.txt", 
                          delim = "^", escape_double = FALSE, col_names = FALSE, 
                          trim_ws = TRUE)
Rows: 1 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.
jack_brewer |> 
  unnest_tokens(word, X1) |>      
  mutate(Speaker = "Jack_Brewer") |> 
  mutate(Party = "Republican") -> jack_brewer  
#
library(readr)
jim_jordan <- read_delim("rep/jim_jordan.txt", 
                         delim = "^", escape_double = FALSE, col_names = FALSE, 
                         trim_ws = TRUE)
Rows: 1 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.
jim_jordan |> 
  unnest_tokens(word, X1) |>       
  mutate(Speaker = "Jim_Jordan") |> 
  mutate(Party = "Republican") -> jim_jordan  
#
library(readr)
karen_pence <- read_delim("rep/karen_pence.txt", 
                          delim = "^", escape_double = FALSE, col_names = FALSE, 
                          trim_ws = TRUE)
Rows: 1 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.
karen_pence |> 
  unnest_tokens(word, X1) |>        
  mutate(Speaker = "Karen_Pence") |> 
  mutate(Party = "Republican") -> karen_pence  
#
library(readr)
kayleigh_mcenany <- read_delim("rep/kayleigh_mcenany.txt", 
                               delim = "^", escape_double = FALSE, col_names = FALSE, 
                               trim_ws = TRUE)
Rows: 1 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.
kayleigh_mcenany |> 
  unnest_tokens(word, X1) |>         
  mutate(Speaker = "Kayleigh_McEnany") |> 
  mutate(Party = "Republican") -> kayleigh_mcenany 
#
library(readr)
kellyanne_conway <- read_delim("rep/kellyanne_conway.txt", 
                               delim = "^", escape_double = FALSE, col_names = FALSE, 
                               trim_ws = TRUE)
Rows: 1 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.
kellyanne_conway |> 
  unnest_tokens(word, X1) |>          
  mutate(Speaker = "KellyAnne_Conway") |> 
  mutate(Party = "Republican") -> kellyanne_conway 
#
library(readr)
kimberly_guilfoyle <- read_delim("rep/kimberly_guilfoyle.txt", 
                                 delim = "^", escape_double = FALSE, col_names = FALSE, 
                                 trim_ws = TRUE)
Rows: 1 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.
kimberly_guilfoyle |> 
  unnest_tokens(word, X1) |>          
  mutate(Speaker = "Kimberly_Guilfoyle") |> 
  mutate(Party = "Republican") -> kimberly_guilfoyle  
#
library(readr)
lara_trump <- read_delim("rep/lara_trump.txt", 
                         delim = "^", escape_double = FALSE, col_names = FALSE, 
                         trim_ws = TRUE)
Rows: 1 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.
lara_trump |> 
  unnest_tokens(word, X1) |>           
  mutate(Speaker = "Lara_Trump") |> 
  mutate(Party = "Republican") -> lara_trump 
#
library(readr)
lou_holtz <- read_delim("rep/lou_holtz.txt", 
                        delim = "^", escape_double = FALSE, col_names = FALSE, 
                        trim_ws = TRUE)
Rows: 1 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.
lou_holtz |> 
  unnest_tokens(word, X1) |>             
  mutate(Speaker = "Lou_Holtz") |> 
  mutate(Party = "Republican") -> lou_holtz 
#
library(readr)
melania_trump <- read_delim("rep/melania_trump.txt", 
                            delim = "^", escape_double = FALSE, col_names = FALSE, 
                            trim_ws = TRUE)
Rows: 1 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.
melania_trump |> 
  unnest_tokens(word, X1) |>              
  mutate(Speaker = "Melania_Trump") |> 
  mutate(Party = "Republican") -> melania_trump 
#
library(readr)
mike_pence <- read_delim("rep/mike_pence.txt", 
                         delim = "^", escape_double = FALSE, col_names = FALSE, 
                         trim_ws = TRUE)
Rows: 1 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.
mike_pence |> 
  unnest_tokens(word, X1) |>                
  mutate(Speaker = "Mike_Pence") |> 
  mutate(Party = "Republican") -> mike_pence 
#
library(readr)
mike_pompeo <- read_delim("rep/mike_pompeo.txt", 
                          delim = "^", escape_double = FALSE, col_names = FALSE, 
                          trim_ws = TRUE)
Rows: 1 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.
mike_pompeo |> 
  unnest_tokens(word, X1) |>                 
  mutate(Speaker = "Mike_Pompeo") |> 
  mutate(Party = "Republican") -> mike_pompeo 
#
library(readr)
mitch_mcconnell <- read_delim("rep/mitch_mcconnell.txt", 
                              delim = "^", escape_double = FALSE, col_names = FALSE, 
                              trim_ws = TRUE)
Rows: 1 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.
mitch_mcconnell |> 
  unnest_tokens(word, X1) |>                  
  mutate(Speaker = "Mitch_McConnell") |> 
  mutate(Party = "Republican") -> mitch_mcconnell 
#
library(readr)
nicholas_sandmann <- read_delim("rep/nicholas_sandmann.txt", 
                                delim = "^", escape_double = FALSE, col_names = FALSE, 
                                trim_ws = TRUE)
Rows: 1 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.
nicholas_sandmann |> 
  unnest_tokens(word, X1) |>                   
  mutate(Speaker = "Nicholas_Sandmann") |> 
  mutate(Party = "Republican") -> nicholas_sandmann  
#
library(readr)
nikki_haley <- read_delim("rep/nikki_haley.txt", 
                          delim = "^", escape_double = FALSE, col_names = FALSE, 
                          trim_ws = TRUE)
Rows: 1 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.
nikki_haley |> 
  unnest_tokens(word, X1) |>                    
  mutate(Speaker = "Nikki_Haley") |> 
  mutate(Party = "Republican") -> nikki_haley 
#
library(readr)
pam_bondi <- read_delim("rep/pam_bondi.txt", 
                        delim = "^", escape_double = FALSE, col_names = FALSE, 
                        trim_ws = TRUE)
Rows: 1 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.
pam_bondi |> 
  unnest_tokens(word, X1) |>                     
  mutate(Speaker = "Pam_Bondi") |> 
  mutate(Party = "Republican") -> pam_bondi  
#
library(readr)
rand_paul <- read_delim("rep/rand_paul.txt", 
                        delim = "^", escape_double = FALSE, col_names = FALSE, 
                        trim_ws = TRUE)
Rows: 1 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.
rand_paul|> 
  unnest_tokens(word, X1) |>                      
  mutate(Speaker = "Rand_Paul") |> 
  mutate(Party = "Republican") -> rand_paul  
#
library(readr)
rudy_giuliani <- read_delim("rep/rudy_giuliani.txt", 
                            delim = "^", escape_double = FALSE, col_names = FALSE, 
                            trim_ws = TRUE)
Rows: 1 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.
rudy_giuliani|> 
  unnest_tokens(word, X1) |>                       
  mutate(Speaker = "Rudy_Giuliani") |> 
  mutate(Party = "Republican") -> rudy_giuliani 
#
library(readr)
tiffany_trump <- read_delim("rep/tiffany_trump.txt", 
                            delim = "^", escape_double = FALSE, col_names = FALSE, 
                            trim_ws = TRUE)
Rows: 1 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.
tiffany_trump|> 
  unnest_tokens(word, X1) |>                        
  mutate(Speaker = "Tiffany_Trump") |> 
  mutate(Party = "Republican") -> tiffany_trump 
#
library(readr)
tim_scott <- read_delim("rep/tim_scott.txt", 
                        delim = "^", escape_double = FALSE, col_names = FALSE, 
                        trim_ws = TRUE)
Rows: 1 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.
tim_scott|> 
  unnest_tokens(word, X1) |>                          
  mutate(Speaker = "Tim_Scott") |> 
  mutate(Party = "Republican") -> tim_scott 
#
library(readr)
tom_cotton <- read_delim("rep/tom_cotton.txt", 
                         delim = "^", escape_double = FALSE, col_names = FALSE, 
                         trim_ws = TRUE)
Rows: 1 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.
tom_cotton|> 
  unnest_tokens(word, X1) |>                          
  mutate(Speaker = "Tom_Cotton") |> 
  mutate(Party = "Republican") -> tom_cotton 

I then merged all republican speeches into one data set.

rep2020 <- rbind(tom_cotton, tim_scott, tiffany_trump, rudy_giuliani, rand_paul, pam_bondi, nikki_haley, nicholas_sandmann, mitch_mcconnell, mike_pompeo, mike_pence, melania_trump, lou_holtz, lara_trump, kimberly_guilfoyle, kellyanne_conway, kayleigh_mcenany, karen_pence, jim_jordan, jack_brewer, ivanka_trump, herschel_walker, eric_trump, donald_trump_jr, dana_white, dan_crenshaw, chen_guangcheng, ben_carson, donald_trump_first_speech, donald_trump_second_speech) 

Observation 1

For the first analysis, I found the most common words spoken by both parties. Usually, the most common words in any text would be “and”, “or”, “but”, etc. To stop these from being considered as “words”, I added in the function “anti_join(stop_words)”. This function removed these words from the table

Top Words of 2020 Democratic Convention

dem2020 |> 
  anti_join(stop_words) |> 
  count(word, sort = TRUE) 
Joining with `by = join_by(word)`
# A tibble: 2,677 × 2
   word          n
   <chr>     <int>
 1 joe         118
 2 president    95
 3 america      86
 4 people       74
 5 country      68
 6 biden        58
 7 nation       52
 8 vote         46
 9 trump        43
10 americans    38
# ℹ 2,667 more rows

Top Words of 2020 Republican Convention

rep2020 |> 
  anti_join(stop_words) |> 
  count(word, sort = TRUE) 
Joining with `by = join_by(word)`
# A tibble: 4,603 × 2
   word          n
   <chr>     <int>
 1 president   315
 2 trump       215
 3 america     214
 4 american    173
 5 country     164
 6 people      164
 7 biden       139
 8 joe         104
 9 americans    90
10 time         84
# ℹ 4,593 more rows

Next, I wanted to graph the ten most common words said by each party. To do so, I set a head count of 10.

Top 10 Democratic Convention Words

dem2020 |> 
  anti_join(stop_words) |> 
  count(word, Party, sort = TRUE) |> 
  arrange(desc(n)) |> 
  head(10) |> 
  ggplot(aes(reorder(word, n), n, fill = Party)) +
  geom_col() + coord_flip() +
  scale_fill_manual(values = c('blue')) + theme_clean() +ggtitle("Top 10 Words of 2020 Democratic Convention") +
  labs(y= "Count", x = "Word") 
Joining with `by = join_by(word)`

The top ten words of the Democratic Convention encompass the central idea of promoting Joe Biden for presidency. It makes sense that “Trump” would be among the top words, as that was his running mate at the time.

Top 10 Republican Convention Words

rep2020 |> 
  anti_join(stop_words) |> 
  count(word, Party, sort = TRUE) |> 
  arrange(desc(n)) |> 
  head(10) |> 
  ggplot(aes(reorder(word, n), n, fill = Party)) +
  geom_col() + coord_flip() +
  scale_fill_manual(values = c('red')) + theme_clean() +ggtitle("Top 10 Words of 2020 Republican Convention") +
  labs(y= "Count", x = "Word") 
Joining with `by = join_by(word)`

The top ten words of the Republican Convention makes sense, as at this time Trump was the incumbent.

Common words among both parties were “America”, “country”, and “people”. It could be assumed that these words would be used as a “call-to-action” for many people- encouraging them to vote when the time comes.

Observation 2

Secondly, I wanted to create an easily conceptualized visual that encapsulated the most common words of each convention. To do that, I created a word cloud. For this function, I specifically used the “wordcloud2” package. Similar to the observation made previously, I removed all stop words for a closer look at the main ideas of both conventions.

Democratic WordCloud

dem2020 |> 
  anti_join(stop_words) |> 
  count(word, sort = TRUE) |> 
  wordcloud2() 
Joining with `by = join_by(word)`

Republican Wordcloud

rep2020 |> 
  anti_join(stop_words) |> 
  count(word, sort = TRUE) |> 
  wordcloud2() 
Joining with `by = join_by(word)`

Observation 3

Third, I calculated the mean of both conventions. This was to measure the overall positivity or negativity of both Democrats and republicans. To find the mean, I used the function of ‘afinn’ and implemented sentiments.

dem2020 |> 
  anti_join(stop_words) |> 
  inner_join(get_sentiments('afinn')) -> dem_sentiment 
Joining with `by = join_by(word)`
Joining with `by = join_by(word)`
dem_sentiment |> 
  filter(Party %in% "Democratic") -> dem_sentiment 
mean(dem_sentiment$value) 
[1] 0.09067797

The mean value of the 2020 Democratic Convention was 0.09. Next, I will do the same process with the Republican Convention.

rep2020 |> 
  anti_join(stop_words) |> 
  inner_join(get_sentiments('afinn')) -> rep_sentiment 
Joining with `by = join_by(word)`
Joining with `by = join_by(word)`
rep_sentiment |> 
  filter(Party %in% "Republican") -> rep_sentiment 
mean(rep_sentiment$value) 
[1] 0.2359893

The mean value of the 2020 Republican Convention was 0.23.

Overall, the Republican Convention was more positive when compared the the Democratic Convention. However, they were only 0.14 points apart. Because of such a slim margin, it can be assumed that both parties had a similar tone amongst all speeches.

Observation 4

I will be measuring the sentiment of each parties convention. Sentiments measure positivity or negativity from speech. By using this function, it analyzes the most common words and gives them a positive or negative value. The “n” value seen in the charts below encompasses the amount of times the word was spoken.

Democratic Convention Sentiment

dem2020 %>% 
  anti_join(stop_words) %>% 
  inner_join(get_sentiments("bing")) %>% 
  group_by(sentiment) %>% 
  count() %>% 
  knitr::kable()  
Joining with `by = join_by(word)`
Joining with `by = join_by(word)`
sentiment n
negative 607
positive 620
dem2020 %>% 
  anti_join(stop_words) %>% 
  inner_join(get_sentiments("afinn")) %>% 
  group_by(value) %>% 
  count(word, sort=TRUE) %>% 
  head(12) %>% 
  knitr::kable() 
Joining with `by = join_by(word)`
Joining with `by = join_by(word)`
value word n
3 love 31
1 united 28
-1 fight 24
-3 lost 20
1 promise 18
2 hope 17
-3 crisis 16
-1 hard 16
2 care 16
2 justice 16
1 god 15
1 protect 15

From the Democratic Convention, “love” was the most positive word, whereas “crisis” and “loss” were seen as the most negative (-3).

Republican Convention Sentiment

rep2020 %>% 
  anti_join(stop_words) %>% 
  inner_join(get_sentiments("bing")) %>% 
  group_by(sentiment) %>% 
  count() %>% 
  knitr::kable() 
Joining with `by = join_by(word)`
Joining with `by = join_by(word)`
sentiment n
negative 1056
positive 1511
rep2020 %>% 
  anti_join(stop_words) %>% 
  inner_join(get_sentiments("afinn")) %>% 
  group_by(value) %>% 
  count(word, sort=TRUE) %>% 
  head(12) %>% 
  knitr::kable() 
Joining with `by = join_by(word)`
Joining with `by = join_by(word)`
value word n
1 united 51
1 god 50
2 freedom 42
3 love 42
-1 fight 40
2 heroes 39
2 proud 35
2 support 31
2 opportunity 30
-2 war 28
1 dream 28
1 safe 26

Similar to the Democratic Convention, “love” was the most positive word of the Republican Convention. The Republican Convention had far less negative words. Their most negative word was scored at a -2, which was “war”.

Observation 5

Lastly, I wanted to see how the two parties compare to each other in terms of sentiments. For this to be accomplished, I merged both convention data sets.

convention2020 <- rbind(dem2020, rep2020) 

Next, I graphed the sentiments from both parties. I believe that by graphing them together, it can easily be conceptualized by a larger audience.

convention2020 %>% 
  anti_join(stop_words) |> 
  inner_join(get_sentiments("afinn")) |>  
  group_by(Party) |>  
  summarize(average = mean(value)) |> 
  ggplot(aes(reorder(Party, -average), average, fill=average)) + geom_col() + theme_clean() +ggtitle("2020 Democratic and Republican Convention Sentiments") +
  labs(y= "Sentiment Value", x = "Party") 
Joining with `by = join_by(word)`
Joining with `by = join_by(word)`

Related to the results previously, the 2020 Republican Convention was overall more positive when compared to the Democratic Convention. On this chart, the Republican party doubled the Democratic party in sentiment value.

Conclusion

Overall, the Republican Convention of 2020 was a more positive event. The Republican Party scored higher in overall positivity in specific words used, and the sentiment of all speeches combined. The Democratic Convention was a close runner up in terms of sentiment, but used more negative words, according to the function “afinn”. Both parties encapsulated promoting their candidate, while supporting the idea of bettering America.