Skip to content

Instantly share code, notes, and snippets.

@jonspring
Last active October 2, 2023 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonspring/f8d411d2fe82e7a99fa421cc260fc8a8 to your computer and use it in GitHub Desktop.
Save jonspring/f8d411d2fe82e7a99fa421cc260fc8a8 to your computer and use it in GitHub Desktop.
library(showtext)
font_add_google("Special Elite", "elite")
showtext_auto()
library(magick)
library(tidyverse)
# first part is common punctuation
chars = c(strsplit(intToUtf8(c(33:47, 58:64, 91:96)), "")[[1]],
0:9, letters, LETTERS)
fills = numeric(length(chars))
for(i in 1:length(chars)) {
filename = tempfile(paste0("character_", i), fileext = ".png")
ggplot() +
geom_text(aes(x=a, y=b, label = chars[i]),
family = "elite",
data.frame(a = 1:10, b = 1:10) |>
complete(a, b)) +
theme_void()
ggsave(filename, width = 0.5, height = 0.7, dpi = 300)
r <- image_read(filename)
r
t <- image_trim(r)
t
image_data(t) %>%
apply(2:3, paste, collapse = "") %>%
as.vector %>% table() %>% as.data.frame %>%
mutate(share = Freq / sum(Freq)) %>%
filter(. != "00000000") %>%
summarize(share = sum(share)) %>%
pull(share) -> fills[i]
message(i)
}
data.frame(chars, fills) %>%
arrange(fills) %>%
mutate(chars = factor(chars %>% fct_inorder)) %>%
ggplot(aes(chars, fills, label = chars)) +
geom_text(family = "elite") +
theme_void()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment