R中的Wordcloud + corpus错误

6

我想使用Wordcloud功能对Twitter数据进行云图。我已经安装了Twitter软件包并正在使用API。之后,我按照以下步骤操作。

bigdata <- searchTwitter("#bigdata", n=20)

bigdata_list <- sapply(bigdata, function(x) x$getText())
bigdata_corpus <- Corpus(VectorSource(bigdata_list))
bigdata_corpus <- tm_map(bigdata_corpus, content_transformer(tolower), lazy=TRUE)
bigdata_corpus <- tm_map(bigdata_corpus, removePunctuation, lazy=TRUE)
bigdata_corpus <- tm_map(bigdata_corpus, 
                           function(x)removeWords(x,stopwords()), lazy=TRUE)
wordcloud(bigdata_corpus)

这会导致Wordcloud命令产生错误信息:

Error in UseMethod("meta", x) : 
  no applicable method for 'meta' applied to an object of class "try-error"
In addition: Warning messages:
1: In mclapply(x$content[i], function(d) tm_reduce(d, x$lazy$maps)) :
  all scheduled cores encountered errors in user code
2: In mclapply(unname(content(x)), termFreq, control) :
  all scheduled cores encountered errors in user code

我尝试了不同的语料库命令,但似乎都无法正确执行。有什么想法吗?

1个回答

1
你可以尝试这个:

你可以尝试这个:

library("tm")
# Transform your corpus in a term document matrix
bigdata_tdm <- as.matrix(TermDocumentMatrix(bigdata_corpus))
# Get the frequency by words
bigdata_freq <- data.frame(Words = rownames(bigdata_tdm), Freq = rowSums(bigdata_tdm), stringsAsFactors = FALSE)
# sort
bigdata_freq <- bigdata_freq[order(bigdata_freq$Freq, decreasing = TRUE), ]
# keep the 50 most frequent words
bigdata_freq <- bigdata_freq[1:50, ]

# Draw the wordcloud
library("wordcloud")
wordcloud(words = bigdata_freq$Words, freq = bigdata_freq$Freq)

使用 tm_0.6wordcloud_2.5 两种方式都可以。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接