Cloud of words in R

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 it's giving the following error:

  

Error: inherits (doc, "TextDocument") is not TRUE

    
asked by anonymous 21.02.2015 / 21:05

2 answers

4

I wanted to comment but I can not yet, you need the vector with the words in text format what appears if you do this class(capa) ? Here's how I do it:

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

    
21.02.2015 / 23:24
2

Just use a transformation, the problem is solved:

corpus_clean <- tm_map(corpus, content_transformer(tolower))
    
22.02.2015 / 17:26