:
::penguins |>
palmerpenguinsgroup_by(species) |>
count() |>
mutate(species = factor(species,
levels = c("Adelie", "Gentoo", "Chinstrap"))) |>
arrange(desc(n)) |>
ggplot() +
::geom_waffle(aes(fill = species,
wafflevalues = n),
colour = "#FFFFFF",
make_proportional = FALSE,
size = 2) +
labs(fill = "Species") +
coord_equal() +
theme_void() +
theme(legend.position = "top")
TODO Title
Two #rstats #dataviz aha moments from this morning
- 🧇 ordering the fill colour when using waffle::geom_waffle()
- 🐮 getting rid of white space around a plot with fixed coords (such as, for example, a waffle plot)
🧇 The order of the fill colour is determined by the order in the dataframe, not by the order of factor levels. To make sure the waffle is in the order you want, rearrange your dataframe first!
group_by(species) |> count() |> mutate(species = factor(species, levels = c(“Adelie”, “Gentoo”, “Chinstrap”))) |> ggplot() + waffle::geom_waffle(aes(fill = species, values = n), colour = “#FFFFFF”, make_proportional = FALSE, size = 2) + labs(fill = “Species”) + coord_equal() + theme_void() + theme(legend.position = “top”)
🐮 Integrating a plot into a report styled with a coloured background can be a pain when using a plot which has fixed coords or uses coord_polar() because you end up with white space around it and a lot of trial an error with plot sizes to get rid of it!
{cowplot} to the rescue!
Alt text: NA
Alt text: NA
Alt text: NA
Now to get some lunch - waffles, anyone?
(Code snippet for second tweet: https://gist.github.com/cararthompson/8e9451341cde62c5e89f878c3b8e6edf)