In the project, we plot two wordclouds. The first plot shows the most freqent words before President McKinley (1901). The second plot shows the most frequent words after President Roosevelt (1905). For comparison, the former is black and the latter is colorful.

require(tm)
## Loading required package: tm
## Loading required package: NLP
require(jiebaR)
## Loading required package: jiebaR
## Loading required package: jiebaRD
require(wordcloud)
## Loading required package: wordcloud
## Loading required package: RColorBrewer
USpresidentNameList <- read.table("~/Desktop/hw4_4/usP/before1901.txt",header=FALSE,sep='\n')
USpresidentList <-list()
total = c()
for (president in USpresidentNameList$V1){
    year <- substr(president,1,4)
    USpresidentList <- c(USpresidentList,year)
    fileName <- paste(c("usP",president),collapse='/')
    txt = scan(fileName, what = 'char')
    words_vector = worker() <= txt # word segmentation
    total <- append(total,words_vector)
}
t=table(total)
s=sort(t,decreasing=TRUE)
write.csv(s,'middle.csv')
oba <- read.csv('middle.csv')
words <- oba[,1]
word_freq <- oba[,2]
system("rm middle.csv")
wordcloud(words,word_freq,min.freq=30)

# Before 1901

USpresidentNameList <- read.table("~/Desktop/hw4_4/usP/after1905.txt",header=FALSE,sep='\n')
USpresidentList <-list()
total = c()
for (president in USpresidentNameList$V1){
    year <- substr(president,1,4)
    USpresidentList <- c(USpresidentList,year)
    fileName <- paste(c("usP",president),collapse='/')
    txt = scan(fileName, what = 'char')
    words_vector = worker() <= txt # word segmentation
    total <- append(total,words_vector)
}
t=table(total)
s=sort(t,decreasing=TRUE)
write.csv(s,'middle.csv')
oba <- read.csv('middle.csv')
words <- oba[,1]
word_freq <- oba[,2]
system("rm middle.csv")
pa12 <- brewer.pal(8,"Dark2")
wordcloud(words,word_freq,min.freq=30,colors=pa12)