add a title and remove whitespace from wordcloud2

Viewed 632

I'm trying to add a title to a wordcloud2 plot. I found a way to add the title, but it really makes the plot look ugly because the whitespace is way too much.

Here is a dataframe for example:

df <- structure(list(key = c("Hello", "Okay", "Apple", "Orange", "Cheerios", 
"Today", "Tomorrow", "Water", "Steve", "Basket"), count = c(52L, 
51L, 25L, 21L, 20L, 12L, 12L, 12L, 11L, 9L)), row.names = c(57L, 
53L, 20L, 36L, 18L, 3L, 16L, 50L, 13L, 15L), class = "data.frame")

I managed to add a title with htmlwidgets::prependContent, but,there is just way too much whitespace. What can I do to make this look better and remove whitespace?

library(wordcloud2)

wordcloud2(data = df, size=.5, color='random-dark') %>% 
htmlwidgets::prependContent(htmltools::tags$h1("Title")) 

enter image description here

1 Answers

I tried these codes below on my own wordcloud (unfortunately I didn't use wordcloud2 but I hope this work too on the function).

Use cex to scale up the font, i.e. 150% is cex = 1.5, 200% is cex = 2

## codes for creating canvas for the text (placeholder)
layout(matrix(c(1, 2), nrow=2), heights=c(1, 4))
par(mar=rep(0, 4))
plot.new()
text(x = 0.5, y = 0.5, "The intended title", cex = 1.5, font = 2)

## then your wordcloud
wordcloud2(data = df, size=.5, color='random-dark')
Related