|
|
|
|
|
|
|
```{r} |
|
setwd(here::here('cookie_monster')) |
|
library(tidyverse) |
|
library(ggtext) |
|
library(showtext) |
|
library(ggimage) |
|
|
|
showtext_auto() |
|
showtext_opts(dpi = 300) |
|
|
|
font_add_google('Fira Sans', 'firasans') |
|
# Font downloaded from Google |
|
# https://fonts.google.com/specimen/Solitreo?preview.text=C%20is%20for%20Cookie&preview.text_type=custom&category=Handwriting |
|
font_add('solitreo', 'Solitreo-Regular.ttf') |
|
# Font downloaded from Fontawesome |
|
# https://fontawesome.com/download |
|
font_add('fa-brands', '00_fonts/Font Awesome 6 Brands-Regular-400.otf') |
|
|
|
camcorder::gg_record( |
|
dir = 'imgs', |
|
device = 'png', |
|
width = 16, |
|
height = 16, |
|
units = 'cm', |
|
dpi = 300 |
|
) |
|
``` |
|
|
|
|
|
|
|
```{r} |
|
fandom_url <- 'https://muppet.fandom.com/wiki/Cookie_Monster_Through_the_Years' |
|
src_links <- rvest::read_html(fandom_url) |> |
|
rvest::html_elements('img') |> |
|
rvest::html_attr('src') |
|
|
|
datasrc_links <- rvest::read_html(fandom_url) |> |
|
rvest::html_elements('img') |> |
|
rvest::html_attr('data-src') |
|
|
|
|
|
cookie_imgs <- c(src_links[4:6], datasrc_links[7:13]) |
|
file_names <- paste0( |
|
'cookie_imgs/', |
|
seq_along(cookie_imgs), |
|
if_else(str_detect(cookie_imgs, 'png'), '.png', '.jpg') |
|
) |
|
|
|
walk2( |
|
cookie_imgs, |
|
file_names, |
|
\(x, y) download.file(x, y, mode = 'wb') |
|
) |
|
|
|
read_crop_write_image <- function(img_path, dim) { |
|
magick::image_read(img_path) |> |
|
magick::image_crop(dim) |> |
|
magick::image_scale('800') |> |
|
magick::image_write(str_replace(img_path, '\\.', '_cropped.')) |
|
} |
|
``` |
|
|
|
|
|
```{r} |
|
dims <- case_when( |
|
seq_along(file_names) %in% c(3, 4, 5, 6) ~ '250x150+0+25', |
|
T ~ '250x150' |
|
) |
|
|
|
walk2(file_names, dims, read_crop_write_image) |
|
``` |
|
|
|
|
|
```{r} |
|
|
|
shift_vector <- c(2, 0.9, -0.2, -1.3, -2.4) |
|
tibble( |
|
x = c(rep(0.5, 5), rep(2.25, 5)), |
|
y = rev(seq_along(x)) + c(shift_vector, shift_vector + 2.825), |
|
img = str_replace(file_names, '\\.', '_cropped.'), |
|
hex = c('#737373', '#294a1f', '#9b6a7f', '#1a3b68', '#398aaa', '#254264', '#6692b8', '#496696', '#4d6a9a', '#0050a2'), |
|
year = c('1966', '1967', '1969', '1969-1971', '1971-1982', '1982-1984', '1984-2016*', '1984-2016*', '2014-pres*', '2016-pres*' |
|
), |
|
label = paste0('**', year, '**:<br>', hex) |
|
) |> |
|
ggplot(mapping = aes(x = x, y = y)) + |
|
geom_image( |
|
aes(image = img), |
|
size = 0.25 |
|
) + |
|
geom_tile( |
|
aes(fill = hex), |
|
width = 0.75, |
|
height = 2.025, |
|
position = position_nudge(x = 0.825) |
|
) + |
|
geom_richtext( |
|
aes(label = label), |
|
position = position_nudge(x = 0.825), |
|
color = 'white', |
|
size = 3.75, |
|
fill = NA, |
|
label.colour = NA, |
|
family = 'firasans' |
|
) + |
|
labs( |
|
title = 'C is for Cookie', |
|
subtitle = 'The color of the Cookie Monster over the years', |
|
caption = paste0( |
|
'*Multiple puppets were used in this time period<br>', |
|
'<span style="font-size:8pt"> Data: Muppet Fandom Wiki | Visualization: </span>', |
|
'<span style="font-family:fa-brands;color:#0072B2;font-size:8pt"></span>', |
|
'<span style="font-size:8pt">rappa753</span>' |
|
) |
|
) + |
|
coord_cartesian(xlim = c(-0, 3.5), ylim = c(0, 13.5), expand = FALSE) + |
|
scale_fill_identity() + |
|
theme_void(base_family = 'firasans') + |
|
theme( |
|
text = element_text(color = 'grey15'), |
|
plot.margin = margin(2, 2, 2, 2, 'mm'), |
|
plot.title = element_text(family = 'solitreo', size = 32), |
|
plot.subtitle = element_text(family = 'solitreo', size = 16), |
|
plot.caption = element_markdown(lineheight = 1.75), |
|
plot.background = element_rect(fill = '#DBD4D3', color = NA) |
|
) |
|
``` |
|
|