You are not showing from where w
comes from and I have no way to know it. Can you please turn this into a proper reproducible example as explained in the guide I gave you earlier?
library(tm)
library(wordcloud2)
imm <- read.csv("https://cdn.simfileshare.net/download/1605492/?dl", header = T)
# Build corpus
corpus <- iconv(imm$text, to = "utf-8")
corpus <- Corpus(VectorSource(corpus))
inspect(corpus[1:5])
#> <<SimpleCorpus>>
#> Metadata: corpus specific: 1, document level (indexed): 0
#> Content: documents: 5
#>
#> [1] <NA>
#> [2] <NA>
#> [3] Great evening with Richmond Hill Youth cooking! Friday night pizza <U+0001F60A><U+0001F355> https://t.co/P1wxnEe37y
#> [4] <NA>
#> [5] <NA>
# Clean text
corpus <- tm_map(corpus, tolower)
#> Warning in tm_map.SimpleCorpus(corpus, tolower): transformation drops documents
inspect(corpus[1:5])
#> <<SimpleCorpus>>
#> Metadata: corpus specific: 1, document level (indexed): 0
#> Content: documents: 5
#>
#> [1] <NA>
#> [2] <NA>
#> [3] great evening with richmond hill youth cooking! friday night pizza <u+0001f60a><u+0001f355> https://t.co/p1wxnee37y
#> [4] <NA>
#> [5] <NA>
corpus <- tm_map(corpus, removePunctuation)
#> Warning in tm_map.SimpleCorpus(corpus, removePunctuation): transformation drops
#> documents
inspect(corpus[1:5])
#> <<SimpleCorpus>>
#> Metadata: corpus specific: 1, document level (indexed): 0
#> Content: documents: 5
#>
#> [1] <NA>
#> [2] <NA>
#> [3] great evening with richmond hill youth cooking friday night pizza u0001f60au0001f355 httpstcop1wxnee37y
#> [4] <NA>
#> [5] <NA>
corpus <- tm_map(corpus, removeNumbers)
#> Warning in tm_map.SimpleCorpus(corpus, removeNumbers): transformation drops
#> documents
inspect(corpus[1:5])
#> <<SimpleCorpus>>
#> Metadata: corpus specific: 1, document level (indexed): 0
#> Content: documents: 5
#>
#> [1] <NA>
#> [2] <NA>
#> [3] great evening with richmond hill youth cooking friday night pizza ufauf httpstcopwxneey
#> [4] <NA>
#> [5] <NA>
cleanset <- tm_map(corpus, removeWords, stopwords('english'))
#> Warning in tm_map.SimpleCorpus(corpus, removeWords, stopwords("english")):
#> transformation drops documents
inspect(cleanset[1:5])
#> <<SimpleCorpus>>
#> Metadata: corpus specific: 1, document level (indexed): 0
#> Content: documents: 5
#>
#> [1] <NA>
#> [2] <NA>
#> [3] great evening richmond hill youth cooking friday night pizza ufauf httpstcopwxneey
#> [4] <NA>
#> [5] <NA>
cleanset <- tm_map(cleanset, stripWhitespace)
#> Warning in tm_map.SimpleCorpus(cleanset, stripWhitespace): transformation drops
#> documents
inspect(cleanset[1:5])
#> <<SimpleCorpus>>
#> Metadata: corpus specific: 1, document level (indexed): 0
#> Content: documents: 5
#>
#> [1] <NA>
#> [2] <NA>
#> [3] great evening richmond hill youth cooking friday night pizza ufauf httpstcopwxneey
#> [4] <NA>
#> [5] <NA>
# Term document matrix
tdm <- TermDocumentMatrix(cleanset)
tdm
#> <<TermDocumentMatrix (terms: 1186, documents: 1000)>>
#> Non-/sparse entries: 2956/1183044
#> Sparsity : 100%
#> Maximal term length: 24
#> Weighting : term frequency (tf)
tdm <- as.matrix(tdm)
tdm[1:10, 1:20]
#> Docs
#> Terms 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#> cooking 0 0 1 0 0 1 0 1 1 1 1 0 0 0 0 1 0 1 1 1
#> evening 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#> friday 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
#> great 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#> hill 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#> httpstcopwxneey 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#> night 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
#> pizza 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#> richmond 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#> ufauf 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
w <- data.frame(names(w), w)
#> Error in data.frame(names(w), w): objeto 'w' no encontrado
colnames(w) <- c('word', 'freq')
#> Error in colnames(w) <- c("word", "freq"): objeto 'w' no encontrado
wordcloud2(w,
size = 0.7,
shape = 'triangle',
rotateRatio = 0.5,
minSize = 1)
#> Error in "table" %in% class(data): objeto 'w' no encontrado
Created on 2020-02-01 by the reprex package (v0.3.0)
If I assume w
is derived from tdm
, I can't reproduce your issue, I don't get any error message
w <- data.frame(rownames(tdm), rowSums(tdm))
colnames(w) <- c('word', 'freq')
wordcloud2(w,
size = 0.7,
shape = 'triangle',
rotateRatio = 0.5,
minSize = 1)