我目前将wordle用于词云的许多艺术用途。我认为R的词云可能会更好地控制。

1)您如何在单词云中保持单词大写? [解决了]

2)如何在单词云中将两个单词保持为一块? (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))

最佳答案

您问了两个问题:


您可以通过为TermDocumentMatrix指定控制参数来控制大小写(或不大写)
毫无疑问,某个地方有一个参数可以控制~,但这是一个简单的解决方法:在绘制之前的步骤中,使用gsub~更改为空白。


一些代码:

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)

10-08 02:10