-1

I'm trying to create a wordcloud from a large data set. I've already read the text in and cleaned it. I have tried using wordcloud with the data in a dataframe format as well as in a matrix format, but I get an error either way stating there is an error in UseMethod for TermDocumentMatrix applied to an object class "data.frame" or "matrix".

Below is a shortened version of dput I'm attempting to work with in this capacity:

> dput(billing.mat)
structure(c("", "newest", "managers", "are", "doing", "really", "well", 
"responses", "to", "client", "questions", "have", "been", "much", 
"better", "than", "expected", "for", "the", "short", "time", 
"they", "have", "been", "in", "their", "position", "", "trainee", 
"mentioned", "they", "didnt", "feel", "like", "they", "were", 
"getting", "enough", "supporthelp", "with", "the", "specific", 
"things", "their", "team", "does", "the", "team", "puts", "properties"
), .Dim = c(50L, 
1L), .Dimnames = list(NULL, "billing"))
> 
data_life
  • 387
  • 1
  • 11
  • 1
    [See here](https://stackoverflow.com/q/5963269/5325862) on making a reproducible example that is easier for folks to help with. It's hard to know what's going wrong without any of the code that causes the problem – camille Feb 03 '22 at 19:29

1 Answers1

1

Not sure exactly what you are doing but you can create a word cloud from a vector like this.

library(wordcloud)
library(tm)

data <- structure(c("", "newest", "managers", "are", "doing", "really", "well", 
                    "responses", "to", "client", "questions", "have", "been", "much", 
                    "better", "than", "expected", "for", "the", "short", "time", 
                    "they", "have", "been", "in", "their", "position", "", "trainee", 
                    "mentioned", "they", "didnt", "feel", "like", "they", "were", 
                    "getting", "enough", "supporthelp", "with", "the", "specific", 
                    "things", "their", "team", "does", "the", "team", "puts", "properties"
), .Dim = c(50L, 
            1L), .Dimnames = list(NULL, "billing"))
wordcloud(data)

enter image description here

norie
  • 9,609
  • 2
  • 11
  • 18
  • @data_life You can either visualize a single document using [`wordcloud::wordcloud()`](https://rdrr.io/rforge/wordcloud/man/wordcloud.html), or you can compare multiple documents using either [`wordcloud::comparison.cloud()`](https://rdrr.io/rforge/wordcloud/man/comparison.cloud.html) or [`wordcloud::commonality.cloud()`](https://rdrr.io/rforge/wordcloud/man/commonality.cloud.html). – Greg Feb 03 '22 at 19:22
  • 1
    @data_life Given your sample data, it looks like you have a *single* "billing" document, yet you're trying to use either `comparison.cloud()` or `commonality.cloud()`, which each accept a [`TermDocumentMatrix`](https://rdrr.io/rforge/wordcloud/man/commonality.cloud.html#heading-2). [@norie](https://stackoverflow.com/u/2850026)'s solution simply uses `wordcloud()`, which accepts a simple [`character`](https://rdrr.io/rforge/wordcloud/man/wordcloud.html#heading-3) vector (or here a matrix) of words. – Greg Feb 03 '22 at 19:28