library(ggplot2) library(lubridate) library(syuzhet) library(dplyr ) text <- readLines("speech.txt") Sentiment <- get_nrc_sentiment(text) head(Sentiment) text <- cbind(text,Sentiment) TotalSentiment <- data.frame(colSums(text[,c(2:11)])) names(TotalSentiment) <- "count" TotalSentiment <- cbind("sentiment" = rownames(TotalSentiment), TotalSentiment) rownames(TotalSentiment) <- NULL ggplot(data = TotalSentiment, aes(x = sentiment, y = count)) + geom_bar(aes(fill = sentiment), stat = "identity") + theme(legend.position = "none") + xlab("Sentiment") + ylab("Total Count") + ggtitle("Total Sentiment Score")