Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: word cloud with ggplot2 #174

Open
martinctc opened this issue Jul 13, 2021 · 0 comments
Open

Refactor: word cloud with ggplot2 #174

martinctc opened this issue Jul 13, 2021 · 0 comments
Labels
aesthetics Stylistic changes that do not affect logic refactor Code that neither fixes a bug nor changes feature

Comments

@martinctc
Copy link
Member

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:

image

@martinctc martinctc added aesthetics Stylistic changes that do not affect logic refactor Code that neither fixes a bug nor changes feature labels Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aesthetics Stylistic changes that do not affect logic refactor Code that neither fixes a bug nor changes feature
Projects
None yet
Development

No branches or pull requests

1 participant