The Struggle for Human Rights - Wordcloud

Sam Benetatos

12/10/2019

Title Slide

The Struggle for Human Rights, Sam Benetatos, 12/10/19

Tools

https://www.americanrhetoric.com/speeches/eleanorroosevelt.html Creating a wordcloud with R is easy.

But first, you will need a few packages:

and

Once you have those package installed, just load them.

library(tm)
library(NLP)
library(wordcloud)
library(readr)

Slide 2 - Loading the text

sfhr <- read_lines("data/er_struggle_for_human_rights.txt")
sfhrCorpus <- Corpus(VectorSource(sfhr))

Slide 3 - Cleaning up

sfhrCorpus <- tm_map(sfhrCorpus, tolower)
sfhrCorpus <- tm_map(sfhrCorpus, removePunctuation)
sfhrCorpus <- tm_map(sfhrCorpus,removeWords, 
                    stopwords('english'))
sfhrCorpus <- tm_map(sfhrCorpus, removeNumbers)

Slide 4 - Transforming the text

sfhr_dtm <- TermDocumentMatrix(sfhrCorpus)
sfhr_dtm_matrix <- as.matrix(sfhr_dtm)

Slide 5 - Counting and ordering words

v <- sort(rowSums(sfhr_dtm_matrix), decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)

Slide 6 - Taking a look at the top 10 words

# insert the code that prints the top 10 words. Only the output, 
# not the code, should be rendered.

Slide 7 - Producing the wordcloud

set.seed(1234)
wordcloud(words = d$word, freq = d$freq, min.freq = 2,
          max.words=200, random.order=FALSE, rot.per=0.35, 
          colors=brewer.pal(8, "Paired"))

Slide 8 - Taking a look at the wordcloud

Wordcloud of W.E.B. Dubois's Niagara Movement Speech

Wordcloud of W.E.B. Dubois’s Niagara Movement Speech