Word cloud in R

Asked

Viewed 1,941 times

3

I’m using the following program:

library("wordcloud")
library("tm")
library("RColorBrewer")
dados=read.csv("C:/teste/dados.csv", sep=";", dec=",",header=TRUE) 
capa=dados$mensagem
corpus  <- VCorpus(VectorSource(capa))
corpus1  <- tm_map(corpus, stripWhitespace)
corpus2  <- tm_map(corpus1, tolower)
corpus2  <- tm_map(corpus2, removePunctuation)
wordcloud(corpus2, random.order = F, colors = brewer.pal(5, "Dark2"))

And you’re making the following mistake:

Error: Inherits(doc, "Textdocument") is not TRUE

2 answers

4

I wanted to comment but can not yet, you need the vector with the words in text format what appears if you do this class(capa)? This is the way I do:

texto = readLines("cloud.txt", encoding = "UTF-8")

texto = Corpus(VectorSource(texto))

texto <- tm_map(texto, stripWhitespace)

texto <- tm_map(texto, tolower)

texto <- tm_map(texto, removeWords, stopwords("portuguese"))

texto <- tm_map(texto, stemDocument)

wordcloud(texto, scale=c(5,0.5), max.words=100, random.order=FALSE, rot.per=0.35, use.r.layout=FALSE, colors=brewer.pal(8, "Dark2"))

m = TermDocumentMatrix(texto, control = list(minWordLength = 1))

m = as.matrix(m)

v = sort(rowSums(m), decreasing = TRUE)

If you want something more complete take a look at this link

  • Thanks. I did a transformation and it worked. Use the following command: corpus_clean <- tm_map(corpus, content_transformer(tolower))

  • @user20273, answer your own question ! so it is recorded your problem, I was going to answer, I was just preparing the xD R environment

2

Just use a transformation, the problem is solved:

corpus_clean <- tm_map(corpus, content_transformer(tolower))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.