5

私は現在、ワードクラウドの多くの芸術的な使用にワードルを使用しています。Rのワードクラウドは、潜在的に、より適切に制御できると思います。

1)ワードクラウドで単語を大文字にするにはどうすればよいですか?[解決済み]

2)wordcloudで2つの単語を1つのチャンクとして保持するにはどうすればよいですか?(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))
4

1 に答える 1

4

あなたは2つの質問をしました:

  1. 制御引数を指定することにより、大文字と小文字を制御できます(または制御できません)。TermDocumentMatrix
  2. を制御するための議論がどこかにあることは間違いありません~が、簡単な回避策があります。プロットする直前のステップで空白に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)

ここに画像の説明を入力してください

于 2011-11-09T18:37:34.563 に答える