TaylorCote-Project2

In this project I wanted to look at Oscar speeches. The data set used, includes speeches from 1939 to 2017. I wanted to see what words were used most often and the sentiment of the speeches.

We first need to download packages.

library(tidytext)
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(textdata)
library(tidyr)
library(wordcloud2)

This is the first large part of this project. It is not original code. It is taking a messy data set and making it easier to use and work with.

speeches <- read.csv("https://raw.githubusercontent.com/jmparelman/Oscars_speeches/master/Speeches.csv",
                     stringsAsFactors = FALSE)

speeches <- speeches %>%
  filter(Category != "") %>%
  mutate(cat_2 = case_when(
    Category == " Sound" ~ "Sound",
    Category == " Sound Recording" ~ "Sound Recording",
    Category == " Sound Effects" ~ "Sound Effects",
    Category == " Sound Editing" ~ "Sound Editing",
    Category == " Sound Mixing" ~ "Sound Mixing",
    Category == " Best Motion Picture" ~ "Best Picture",
    Category == " Best Picture" ~ "Best Picture",
    Category == " Writing (Original Screenplay)" ~ "Writing (Original Screenplay)",
    Category == " Writing (Original Story)" ~ "Writing (Original Screenplay)",
    Category == " Writing (Screenplay)" ~ "Writing (Screenplay)",
    Category == " Writing (Screenplay--based on material from another medium)" ~ "Writing (Adapted Screenplay)",
    Category == " Writing (Story and Screenplay--written directly for the screen)" ~ "Writing (Original Screenplay)",
    Category == " Writing (Screenplay Adapted from Other Material)" ~ "Writing (Adapted Screenplay)",
    Category == " Writing (Screenplay Written Directly for the Screen--based on factual material or on story material not previously published or produced)" ~ "Writing (Original Screenplay)",
    Category == " Writing (Screenplay Based on Material from Another Medium)" ~ "Writing (Adapted Screenplay)",
    Category == " Writing (Screenplay Written Directly for the Screen)" ~ "Writing (Original Screenplay)",
    Category == " Writing (Adapted Screenplay)" ~ "Writing (Adapted Screenplay)",
    Category == " Special Effects" ~ "Visual Effects",
    Category == " Special Visual Effects" ~ "Visual Effects",
    Category == " Visual Effects" ~ "Visual Effects",
    Category == " Actor" ~ "Leading Actor",
    Category == " Actor in a Leading Role" ~ "Leading Actor",
    Category == " Actor in a Supporting Role" ~ "Supporting Actor",
    Category == " Film Editing" ~ "Film Editing",
    Category == " Foreign Language Film" ~ "Foreign Language Film",
    Category == " Actress" ~ "Leading Actress",
    Category == " Actress in a Leading Role" ~ "Leading Actress",
    Category == " Actress in a Supporting Role" ~ "Supporting Actress",
    Category == " Costume Design" ~ "Costume Design",
    Category == " Cinematography" ~ "Cinematography",
    Category == " Documentary (Feature)" ~ "Documentary (Feature)",
    Category == " Documentary (Short Subject)" ~ "Documentary (Short)",
    Category == " Directing" ~ "Director",
    Category == " Music (Music Score of a Dramatic or Comedy Picture)" ~ "Music (Best Score)",
    Category == " Music (Scoring of a Musical Picture)" ~ "Music (Musical Score)",
    Category == " Music (Song)" ~ "Music (Song)",
    Category == " Music (Music Score--substantially original)" ~ "Music (Best Score)",
    Category == " Music (Scoring of Music--adaptation or treatment)" ~ "Music (Musical Score)",
    Category == " Music (Original Music Score)" ~ "Music (Best Score)",
    Category == " Music (Original Score--for a motion picture [not a musical])" ~ "Music (Best Score)",
    Category == " Music (Song--Original for the Picture)" ~ "Music (Song)",
    Category == " Music (Original Score)" ~ "Music (Best Score)",
    Category == " Music (Original Song Score)" ~ "Music (Musical Score)",
    Category == " Music (Original Dramatic Score)" ~ "Music (Best Score)",
    Category == " Music (Scoring: Adaptation and Original Song Score)" ~ "Music (Musical Score)",
    Category == " Music (Scoring: Original Song Score and Adaptation -or- Scoring: Adaptation)" ~ "Music (Musical Score)",
    Category == " Music (Original Song)" ~ "Music (Song)",
    Category == " Makeup" ~ "Makeup",
    Category == " Makeup and Hairstyling" ~ "Makeup"
  ))

acting <- c("Leading Actor", "Supporting Actor", "Leading Actress", "Supporting Actress")
technical <- c("Sound", "Sound Recording", "Sound Effects", "Sound Editing", "Sound Mixing",
               "Visual Effects", "Film Editing", "Costume Design", "Cinematography", "Makeup")
music <- c("Music (Best Score)", "Music (Musical Score)", "Music (Song)")
writing <- c("Writing (Original Screenplay)", "Writing (Adapted Screenplay)", "Writing (Screenplay)")
directing <- "Director"
production <- c("Best Picture", "Foreign Language Film", "Documentary (Feature)", "Documentary (Short)")

speeches <- speeches %>%
  mutate(cat_3 = case_when(cat_2 %in% acting ~ "acting",
                           cat_2 %in% technical ~ "technical",
                           cat_2 %in% music ~ "music",
                           cat_2 %in% writing ~ "writing",
                           cat_2 %in% directing ~ "directing",
                           cat_2 %in% production ~ "production"))

speeches$year_2 <- NA

for (i in 1:nrow(speeches)) {
  speeches$year_2[i] <- str_split(speeches$Year[i], " ")[[1]][2]
  }

Once the data is organized better we can move into visualizing and analyzing the data set.

First I want to see the most common words used in Oscar speeches.

speeches |> 
  unnest_tokens(word,Speech) |> 
  anti_join(stop_words) |>  
  count(word, sort = TRUE) %>% 
  head(20) %>% 
  ggplot(aes(reorder(word, n),n)) + geom_col() +
  coord_flip()
Joining with `by = join_by(word)`

We can now see the most common word is “academy.” I thought the most common word would be “thank,” but this makes senses because the Oscars are academy awards. All the the words on this list make sense to be common in Oscar speeches. The only one I wonder about is “john.” I am thinking John might be a common name of people who are being thanked during these speeches.

Next I wanted to find the sentiment of the speeches. In this code I am filtering out filler words like “it” and “the.” I wanted to filter by movie title to see if the sentiment changed based off the type of movie. I wanted to know if the sadder movies would also have winners giving sadder speeches.

speeches |> 
  unnest_tokens(word, Speech) |> 
inner_join(get_sentiments("afinn")) -> speech_sentiment
Joining with `by = join_by(word)`
speech_sentiment |> 
  count(cat_2, sort = TRUE)
                           cat_2    n
1                   Best Picture 1398
2                Leading Actress 1276
3                  Leading Actor 1249
4                       Director  927
5             Supporting Actress  901
6               Supporting Actor  895
7          Documentary (Feature)  779
8                   Music (Song)  736
9  Writing (Original Screenplay)  680
10                  Film Editing  645
11           Documentary (Short)  642
12            Music (Best Score)  599
13  Writing (Adapted Screenplay)  588
14                Visual Effects  561
15                Cinematography  531
16                Costume Design  477
17                        Makeup  473
18                         Sound  424
19         Foreign Language Film  319
20                 Sound Editing  262
21                  Sound Mixing  214
22         Music (Musical Score)  116
23                 Sound Effects   32
24          Writing (Screenplay)    4
25               Sound Recording    3
speech_sentiment |> 
  filter(cat_2 %in% c('Best Picture','Leading Actress','Leading Actor',
                      'Director',' Supporting Actress','Supporting Actor')) |> 
  group_by(Film.Title) |> 
  summarize(avg_sentiment = mean(value, na.rm = TRUE)) -> sentiment_summary


ggplot(sentiment_summary, aes(reorder(Film.Title,avg_sentiment), avg_sentiment, fill = avg_sentiment)) +
  geom_col() +
  coord_flip() 

Lastly I wanted to create a word cloud. The most common words are different from this word cloud because it is using a different sub set of data.

speech_sentiment |> 
  filter(value > 0) |> 
  count(word, sort = TRUE) |> 
  wordcloud2(minRotation = pi/3, maxRotation = pi/5)

It makes sense to me that “thank” would be the largest word. I can only imagine that every speech is mostly thanking others for the part they played in the winner’s win.