1

How to put a title in a wordcloud with wordcloud2 in R?

df <- structure(list(age = c(18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L), definition = c("eye", "car", "nose", "bird", "hot", "balloon", "ouch", "kitty", "vroom", "ear", "night night", "juice", "grandma*", "quack quack", "apple", "bubbles", "cookie", "bath", "cheese", "milk", "thank you", "hat", "fish (animal)", "grandpa*", "cat", "up", "yes", "truck", "choo choo", "shh/shush/hush", "bear", "hello"), frequency = c(0.665158371040724, 0.656108597285068, 0.649321266968326, 0.626696832579186, 0.606334841628959, 0.601809954751131, 0.601809954751131, 0.595022624434389, 0.595022624434389, 0.588235294117647, 0.588235294117647, 0.581447963800905, 0.579185520361991, 0.579185520361991, 0.576923076923077, 0.576923076923077, 0.570135746606335, 0.567873303167421, 0.565610859728507, 0.565610859728507, 0.563348416289593, 0.542986425339366, 0.538461538461538, 0.538461538461538, 0.53393665158371, 0.513574660633484, 0.513574660633484, 0.51131221719457, 0.506787330316742, 0.504524886877828, 0.502262443438914, 0.5)), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), row.names = c(NA, -32L), groups = structure(list(    age = 18L, .rows = structure(list(1:32), ptype = integer(0), class = c("vctrs_list_of",     "vctrs_vctr", "list"))), row.names = c(NA, -1L), class = c("tbl_df", "tbl", "data.frame"), .drop = TRUE))

library(wordcloud2)

for (a in sort(unique(df$age))) {
  wordcloud2(
    subset(df, age == a)[c('definition', 'frequency')], size = 0.7, rotateRatio = 0, color = "random-dark", backgroundColor = 'skyblue', widgetsize = c(1200, 675)) |> 
  print()
}

enter image description here

Julien
  • 1,613
  • 1
  • 10
  • 26

0 Answers0