【发布时间】:2017-07-03 16:46:53
【问题描述】:
我正在尝试在 R 中创建一个词云,其中我有一个包含正负词的矩阵,但是,我想用两种不同的颜色(比如绿色和红色)显示正负词。有人可以帮我解决这个问题。谢谢!
library(qdap)
x1 = x[a0]
pol = polarity(x1)
wc = pol$all[,2]
val = pol$all[,3]
p = pol$all[,4]
n = pol$all[,5]
positive_words = unique(setdiff(unlist(p),"-")) # Positive words list
negative_words = unique(setdiff(unlist(n),"-")) # Negative words list
total_words1 =cbind(positive_words,negative_words)
pos.tdm = dtm[,which(colnames(dtm) %in% total_words1)]
m = as.matrix(pos.tdm)
v1 = sort(colSums(m), decreasing = TRUE)
windows() # opens new image window
wordcloud(names(v1), v1, scale=c(4,1),1, max.words=100,colors=brewer.pal(8, "Dark2"))
title(sub = "Words - Wordcloud")
【问题讨论】:
标签: r word-cloud