wpa
wpa copied to clipboard
Refactor: word cloud with `ggplot2`
Currently, word clouds are created with the package ggwordcloud
. There is an alternative implementation that uses only ggplot2
, as shown at https://stackoverflow.com/q/47080052/5539702.
The code given is:
library(ggplot2)
library(ggrepel)
df %>%
filter(book %in% c("Sense & Sensibility", "Pride & Prejudice",
"Mansfield Park", "Emma")) %>%
ggplot(., aes(x = 1, y = 1, size = n, label = word)) +
geom_text_repel(segment.size = 0, segment.alpha = 0) +
scale_size(range = c(2, 15), guide = FALSE) +
theme_void() +
theme(panel.border = element_rect(colour = "black", fill=NA, size=1)) +
facet_wrap(~book) +
labs(title = "Jane Austen Word Clouds")
ggsave("jane_austen_gg.png", width = 11, height = 11)
And seems to work better aesethetically: