このワード クラウド チュートリアルを複製していますが、次のようになります。
strwidth(words[i], cex = size[i], ...) のエラー: 無効な 'cex' 値 さらに: 警告メッセージ: 1: max(freq) 内: max に欠落していない引数はありません。-Inf 2 を返します: In max(freq) : max に欠落していない引数はありません。-Inf を返す
コードの各ステップで何が起こっているのかよくわかりませんが、問題は生成された行列が異なる行または列を持つことに関連している可能性があると思います。これは私が使用しているコードです:
install.packages(c("devtools", "rjson", "bit64", "httr"))
library(devtools)
install_github("twitteR", username="geoffjentry")
library(twitteR)
##
api_key= "xxxxxx"
api_secret= "xxxxxx"
access_token="xxxxxxxxxxxx"
access_token_secret= "xxxxxx"
setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret)
searchTwitter("amlo")
library(twitteR)
install.packages("tm")
library(tm)
install.packages("wordcloud")
library(wordcloud)
library(RColorBrewer)
mh370 <- searchTwitter("#PrayForMH370", since = "2014-03-08", until = "2014-03-20", n = 1000)
mh370_text = sapply(mh370, function(x) x$getText())
mh370_corpus = Corpus(VectorSource(mh370_text))
tdm = TermDocumentMatrix(
mh370_corpus,
control = list(
removePunctuation = TRUE,
stopwords = c("prayformh370", "prayformh", stopwords("english")),
removeNumbers = TRUE, tolower = TRUE)
)
m = as.matrix(tdm)
# get word counts in decreasing order
word_freqs = sort(rowSums(m), decreasing = TRUE)
# create a data frame with words and their frequencies
dm = data.frame(word = names(word_freqs), freq = word_freqs)
wordcloud(dm$word, dm$freq, random.order = FALSE, colors = brewer.pal(8, "Dark2"))