I want to use the Wordcloud function for doing a cloud on twitter data. I have installed the twitter package and the working with the api. I do the following after that.
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)
This produces the error message for the Wordcloud command:
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
I have tried different corpus commands but cant seem to get it right. Any ideas?
You can try this :
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)
With tm_0.6
and wordcloud_2.5
both ways works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With