Part 49 Case Study: Martin Luther King Jr.’s Speech
We are going to look at Martin Luther King Jr.’s “I Have a Dream” speech found here.
Lets read it in. Since it’s in a .txt
file we can use read.table()
and specify some things:
<- read.table(
speech_txt ::here("data", "martin_luther_king_speech.txt"),
herequote = "",
header = FALSE,
sep = "\n",
stringsAsFactors = FALSE
|>
) as_tibble() |>
rename(line = V1)
49.1 Wrangle our text
49.1.1 unnest_tokens()
Wielding the power of tidytext
:
<-
speech_unnest |>
speech_txt unnest_tokens(word, line)
speech_unnest
49.1.2 Remove stop words
<-
speech_unnest |>
speech_unnest anti_join(stop_words, by = "word")
speech_unnest
49.1.3 Count the words
<-
speech_unnest |>
speech_unnest count(word, sort = TRUE)
speech_unnest
49.2 Visualizing the words
|>
speech_unnest filter(n >= 4) |> # look at words that only occurred 4 or more times
ggplot() +
aes(y = n, x = forcats::fct_reorder(word, n, max)) + # sort our bars
geom_col() +
coord_flip() + # flip the coords (easier to digest graph)
labs(y = "word",
x = "count")