Wordcloud with r
- 8 years ago
When I tried the original code, it worked with older versions of R, 3.2.3 but not newer versions of R, 3.3.1 and 3.4.2. The Corpus construction was returning only numbers which were then stripped out by the rest of the code causing problems. So, I hacked together a variation of the original code based upon comments and have a working version here:
require(tm) require(wordcloud) require(RColorBrewer) datain = as.data.frame(table(as.character(dataset[,1]))) words <- Corpus(VectorSource(dataset$text)) words <- tm_map(words, stripWhitespace) words <- tm_map(words, content_transformer(tolower)) words <- tm_map(words, removeNumbers) words <- tm_map(words, removePunctuation) words <- tm_map(words, removeWords, stopwords("english")) words <- tm_map(words, stemDocument) wordcloud(words, scale=c(5,0.75), max.words=50, random.order=FALSE, rot.per=0.35, use.r.layout=FALSE, colors=brewer.pal(8, "Dark2"))The main change is the construction of the Corpus, VectorSource(dataset) becomes VectorSource(dataset$text)
This is based upon the original PBIX file included in the original post.
Hi, Thanks for sharing.
I have a problem with special charaters braking the visualisation.
Can you help me what to do with it.
The R code is working when no special charaters present.
This is the Error Message i get:
Error Message:
R script error.
Error in type.convert(data[[i]], as.is = as.is[i], dec = dec, numerals = numerals, :
invalid input '@MSEmpresasLatam @DiegoBek exactamente! Es la era de la inteligencia #AzureML #SQLEnterprise #PowerBI #IoT ðŸ˜' in 'utf8towcs'
Calls: read.csv -> read.table -> type.convert
Execution halted
This is the R code i have:
library(tm)
library(SnowballC)
library(wordcloud)
dataset <-Corpus(VectorSource(dataset))
dataset <- tm_map(dataset, removePunctuation)
dataset <-tm_map(dataset, removeWords, c('powerbi','PowerBI',stopwords('english')))
dataset <-tm_map(dataset, stemDocument)
wordcloud(dataset, max.words = 100, random.order = FALSE)
Thanks in advance if anyone could help.
Best Regards,
Kávási Mihály