1

I want to make a wordcloud separated by grouping of autor variable and I did it:

# Create a dataframe that save freq of each word

tw <- tw_token %>% count(autor, word, sort=TRUE)

# head of data 
dput(head(tw))
structure(list(autor = c("Mayoredlee", "Mayoredlee", "Elonmusk", 
"Mayoredlee", "Mayoredlee", "Elonmusk"), word = c("sf", "city", 
"tesla", "residents", "housing", "model"), n = c(775L, 320L, 
263L, 260L, 180L, 163L)), row.names = c(NA, 6L), class = "data.frame")


# Make wordcloud 

wordcloud(words = tw$word, freq = tw$n, min.freq = 1,  
          max.words=200, random.order=FALSE, rot.per=0.45,  
          colors=brewer.pal(8, "Dark2"))

The output of wordcloud enter image description here

Maria MJ
  • 35
  • 4
  • Can you provide a sample of the dataset with `dput(head(DATA))` that we can copy and paste to better understand the issue and test solutions? (See [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)) ... and please tell us what the desired output would look like! – ktiu Jun 03 '21 at 15:26
  • Thanks for your answer, I edited the post – Maria MJ Jun 03 '21 at 15:33

1 Answers1

0

I think something like this might be what you are looking for:

par(mfrow = c(2, 2)) # output wordclouds on a 2 x 2 grid, adjust if necessary

tw %>%
  split(~ autor) %>%
  purrr::walk(~ with(., wordcloud(words        = word,
                                  freq         = n,
                                  min.freq     = 1,
                                  max.words    = 200,
                                  random.order = FALSE,
                                  rot.per      = 0.45)))
ktiu
  • 2,606
  • 6
  • 20
  • I try it but I get the next error: Error in unique.default(x, nmax = nmax) : unique() applies only to vectors – Maria MJ Jun 03 '21 at 15:49
  • You changed the object name in your question to `tw`, I changed the answer to reflect that change. Did you use the code on the correct object? It works for me on the object you provided. – ktiu Jun 03 '21 at 15:55
  • the name of object is tw – Maria MJ Jun 04 '21 at 09:16