Created
January 28, 2023 11:00
-
-
Save AlbertRapp/bcc97b006d1ea3014417c3cec29981da to your computer and use it in GitHub Desktop.
after_scale_demo.R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(ggtext) | |
library(showtext) | |
font_add_google('Fira Sans', 'firasans') | |
font_add_google('Roboto Mono', 'robotomono') | |
font_add('fa-brands', '00_fonts/Font Awesome 6 Brands-Regular-400.otf') | |
showtext_auto() | |
update_geom_defaults("violin", list(ymin = NULL)) | |
palmerpenguins::penguins |> | |
dplyr::filter(!is.na(sex)) |> | |
ggplot(aes(x = body_mass_g, y = species, fill = species)) + | |
geom_violin(aes(ymin = after_scale(y))) + | |
theme_minimal(base_size = 16) + | |
theme( | |
text = element_text(family = 'firasans', color = 'grey20'), | |
legend.position = 'none', | |
plot.title.position = 'plot', | |
plot.title = element_text(size = 24), | |
plot.subtitle = element_markdown(), | |
plot.caption = element_markdown() | |
) + | |
scale_fill_manual(values = thematic::okabe_ito(3)) + | |
labs( | |
x = 'Body weight (in g)', | |
y = element_blank(), | |
title = 'Penguin weights (by species)', | |
subtitle = paste0( | |
'This is a demo to include half-geoms with', | |
' <span style="font-family:robotomono;color:#0072B2;">**after_scale()**</span>', | |
' which I learned from', | |
' <span style="font-family:fa-brands;color:#0072B2;"></span>', | |
'<span style="font-family:robotomono;color:#0072B2;">**teunbrand/ggplot_tricks**</span>' | |
), | |
caption = paste0( | |
'Data: palmerpenguins R Package | Visualization: ', | |
'<span style="font-family:fa-brands;color:#0072B2;"></span> rappa753' | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment