我目前使用wordle用于词云的许多艺术用途。我认为R的词云可能具有更好的控制能力。
1)你如何在词云中保留一个词? [解决]
2)如何在wordcloud中将两个单词保留为一个块? (wordle使用〜运算符来实现这一点,R的单词云只打印〜原样)[例如,在“to”和“be”之间有一个〜我喜欢单词云中的空格]
require(wordcloud)
y<-c("the", "the", "the", "tree", "tree", "tree", "tree", "tree",
"tree", "tree", "tree", "tree", "tree", "Wants", "Wants", "Wants",
"Wants", "Wants", "Wants", "Wants", "Wants", "Wants", "Wants",
"Wants", "Wants", "to~be", "to~be", "to~be", "to~be", "to~be",
"to~be", "to~be", "to~be", "to~be", "to~be", "to~be", "to~be",
"to~be", "to~be", "to~be", "to~be", "to~be", "to~be", "to~be",
"to~be", "when", "when", "when", "when", "when", "familiar", "familiar",
"familiar", "familiar", "familiar", "familiar", "familiar", "familiar",
"familiar", "familiar", "familiar", "familiar", "familiar", "familiar",
"familiar", "familiar", "familiar", "familiar", "familiar", "familiar",
"leggings", "leggings", "leggings", "leggings", "leggings", "leggings",
"leggings", "leggings", "leggings", "leggings")
wordcloud(names(table(y)), table(y))
答案 0 :(得分:4)
你问了两个问题:
TermDocumentMatrix
~
,但这是一个简单的解决方法:在绘图前的步骤中使用gsub
将~
更改为空格。< / LI>
醇>
一些代码:
corpus <- Corpus(VectorSource(y))
tdm <- TermDocumentMatrix(corpus, control=list(tolower=FALSE)) ## Edit 1
m <- as.matrix(tdm)
v <- sort(rowSums(m), decreasing = TRUE)
d <- data.frame(word = names(v), freq = v)
d$word <- gsub("~", " ", d$word) ## Edit 2
wordcloud(d$word, d$freq)