Skip to content

Instantly share code, notes, and snippets.

@loukesio
Created May 4, 2025 22:36
Show Gist options
  • Select an option

  • Save loukesio/cf71659d5ae68ab75b636a9593498054 to your computer and use it in GitHub Desktop.

Select an option

Save loukesio/cf71659d5ae68ab75b636a9593498054 to your computer and use it in GitHub Desktop.
test how different fonts look
demo_font_text <- function(
google_names,
families = tolower(gsub("\\s+", "", google_names)),
label_text = "Showtext shows text. Wow. What an insight.",
size = 13
) {
# dependencies
library(showtext)
library(ggplot2)
library(dplyr)
library(purrr)
# turn on showtext
showtext_auto()
# import each font
walk2(google_names, families, ~ font_add_google(.x, .y))
# build a little tibble so that each font gets its own row
n <- length(families)
plot_data <- tibble(
family = families,
x = 0,
y = seq(0, 1, length.out = n),
label = label_text
)
# make the plot
ggplot(plot_data, aes(x, y, label = label)) +
geom_text(aes(family = family), size = size, hjust = 0, colour = "dodgerblue4") +
coord_cartesian(xlim = c(0, 1), ylim = c(0, 1)) +
theme_void()
}
#Single font
demo_font_text(
google_names = "Lobster",
families = "lobster",
label_text = "This is Lobster!"
)
#Multiple fonts at once
demo_font_text(
google_names = c("Lora", "Fira Sans", "Syne Mono"),
families = c("lora", "firasans", "synemono"),
label_text = "Hello, world!"
)
#Let it autoderive family names
demo_font_text(
google_names = c("Lora", "Lobster", "Anton"),
label_text = "Try these out!"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment