Hi jcblum,
Thanks again for your continued response... this is my code right after creating a scv file. most of it is without error when I run, but still am unable see the plotted image...
## Wordcorpus- (Bag-of-words)
# Load the data as a corpus
some_txt6 <- Corpus(VectorSource(some_txt5))
toSpace <- content_transformer(function (x , pattern ) gsub(pattern, " ", x))
cleancorpus <- function(some_txt6){
some_txt6 <- tm_map(some_txt6, removePunctuation)
some_txt6 <- tm_map(some_txt6, content_transformer(tolower))
some_txt6 <- tm_map(some_txt6, removeWords, stopwords("english"))
some_txt6 <- tm_map(some_txt6, stripWhitespace)
some_txt6 <- tm_map(some_txt6, stemDocument)
return(some_txt6)
}
# Build a term-document matrix
dtm <- TermDocumentMatrix(some_txt6)
m <- as.matrix(dtm)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)
head(d, 10)
## the result
str(dtm)
## Wordcloud
library(tm)
library(SnowballC)
library(wordcloud)
library(RColorBrewer)
pal <- brewer.pal(8, "Dark2")
png("wordcloud_packages.png", width=1500,height=1500)
wordcloud(some_txt6, min.freq = 5, max.words=Inf, random.order=FALSE, rot.per=0.35,
colors=pal)
## Sentiment Analysis
library(ggplot2)
library(syuzhet)
# Build a term-document matrix -2-
mysentiment <- get_nrc_sentiment(some_txt5)
SentimentScores <- data.frame(colSums(mysentiment[,]))
names(SentimentScores) <- "Score"
SentimentScores <- cbind("sentiment" = rownames(SentimentScores), SentimentScores)
rownames(SentimentScores) <- NULL
# plot Sentiment Score data on a graph
#(working but not plotting image)
ggplot(SentimentScores, aes(x = factor(Sentiment), y = Score, fill = factor(Sentiment))) +
geom_bar(stat="identity", width = 0.7) +
labs(x = "Sentiment", y = "Score", fill = "Score") +
theme_minimal(base_size = 14)
# plot Sentiment Score data on a graph (not working)
ggplot(data = SentimentScores, aes(x = Sentiment, y=Score)) +
geom_bar(aes(fill = Sentiment), stat = "identity") +
theme(legend.position = "none") +
xlab("Sentiment") + ylab("Score") +
ggtitle("Total Sentiment Score Based on Tweets")