dgrtwo / tidy-text-mining

Manuscript of the book "Tidy Text Mining with R" by Julia Silge and David Robinson
http://tidytextmining.com
Other
1.32k stars 806 forks source link

Evolve facets from traditional tilde notation to vars() #87

Open arencambre opened 3 years ago

arencambre commented 3 years ago

Per the facet_wrap() documentation, the tilde notation in the facets argument is for "compatibility with the classic interface". It appears vars() should be used instead.

There are a few places in this book where facet_wrap() uses the tilde. It may be best to convert to vars().

For example, near the end of chapter 1 is this code example:

ggplot(frequency, aes(x = proportion, y = `Jane Austen`,
                      color = abs(`Jane Austen` - proportion))) +
  geom_abline(color = "gray40", lty = 2) +
  geom_jitter(alpha = 0.1, size = 2.5, width = 0.3, height = 0.3) +
  geom_text(aes(label = word), check_overlap = TRUE, vjust = 1.5) +
  scale_x_log10(labels = percent_format()) +
  scale_y_log10(labels = percent_format()) +
  scale_color_gradient(limits = c(0, 0.001),
                       low = "darkslategray4", high = "gray75") +
  facet_wrap(~author, ncol = 2) +
  theme(legend.position="none") +
  labs(y = "Jane Austen", x = NULL)

The facet_wrap() function call may be changed to facet_wrap(vars(author), ncol = 2).

In chapter 2 is this code example:

ggplot(jane_austen_sentiment, aes(index, sentiment, fill = book)) +
  geom_col(show.legend = FALSE) +
  facet_wrap(~book, ncol = 2, scales = "free_x")

The facet_wrap() function call may be changed to facet_wrap(vars(book), ncol = 2, scales = "free_x").

dev881B commented 2 years ago

Yes 👍 X