Last active
December 13, 2021 20:46
-
-
Save malcalakovalski/c00c3cbf3816da019d9b44bd5708deae to your computer and use it in GitHub Desktop.
Hamilton theme demo
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
# Setup ------------------------------------------------------------------- | |
librarian::shelf(tidyverse, palmerpenguins, ggbrookings) | |
devtools::load_all() | |
# Import fonts if they are new | |
import_thp_fonts() | |
# Register them so R can find them | |
register_thp_fonts() | |
# Set the default theme as thp | |
theme_set(theme_thp()) | |
# Example 1 --------------------------------------------------------------- | |
ggplot(penguins, aes(x = flipper_length_mm, | |
y = body_mass_g)) + | |
geom_point(aes(color = sex), | |
size = 2, | |
show.legend = FALSE) + | |
scale_color_brookings('thp_gender', na.translate = FALSE) + | |
labs(title = "Penguin flipper and body mass", | |
subtitle = "Dimensions for <span style = 'color:#6E2585;'>**male**</span> and <span style = 'color:#006983;'>**female**</span> Adelie, Chinstrap and Gentoo Penguins at Palmer Station LTER", | |
caption = '**Source:** Palmer Penguins<br>', | |
tag = 'FIGURE 3', | |
x = "Flipper length (mm)", | |
y = "Body mass (g)", | |
color = "Penguin sex") + | |
scale_x_continuous(expand = expansion()) + | |
scale_y_continuous(expand = expansion()) + | |
facet_wrap(species ~ ., nrow = 3, ncol = 1) | |
# Save plot with sensible defaults | |
brookings_save('misc/penguins.png', height = 7) | |
penguins_plot <- add_logo('misc/penguins.png', logo_path = 'thp', 'bottom right', 5, height_padding = 0.02) | |
image_write(penguins_plot, "misc/penguins.png") | |
# Example 2 --------------------------------------------------------------- | |
ggplot(data = penguins, aes(x = flipper_length_mm)) + | |
geom_histogram(aes(fill = species), | |
alpha = 0.5, | |
position = "identity", | |
bins = 30) + | |
scale_fill_brookings(palette = "thp_categorical2") + | |
labs(x = "Flipper length (mm)", | |
y = "Frequency", | |
title = "Penguin flipper lengths", | |
caption = '**Source:** Palmer Penguins', | |
tag = 'FIGURE 2') + | |
scale_x_continuous(expand = expansion()) + | |
scale_y_continuous(expand = expansion()) | |
# Save plot with sensible defaults | |
brookings_save('misc/penguins_hist.png') | |
penguins_hist_plot <- add_logo('misc/penguins_hist.png', logo_path = 'thp', 'bottom right', 5, height_padding = 0.02) | |
image_write(penguins_hist_plot, "misc/penguins_hist.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment