-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from nrennie/nrennie-patch-1
Add american idol plot
- Loading branch information
Showing
5 changed files
with
174 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
# Load packages ----------------------------------------------------------- | ||
|
||
library(tidyverse) | ||
library(showtext) | ||
library(ggtextcircle) | ||
library(camcorder) | ||
library(ggtext) | ||
library(nrBrand) | ||
library(glue) | ||
library(ggimage) | ||
|
||
|
||
# Load data --------------------------------------------------------------- | ||
|
||
tuesdata <- tidytuesdayR::tt_load("2024-07-23") | ||
auditions <- tuesdata$auditions | ||
eliminations <- tuesdata$eliminations | ||
finalists <- tuesdata$finalists | ||
ratings <- tuesdata$ratings | ||
seasons <- tuesdata$seasons | ||
songs <- tuesdata$songs | ||
|
||
|
||
# Load fonts -------------------------------------------------------------- | ||
|
||
font_add_google("Ubuntu") | ||
font_add_google("Passion One") | ||
showtext_auto() | ||
|
||
body_font <- "Ubuntu" | ||
title_font <- "Passion One" | ||
|
||
|
||
# Define colours ---------------------------------------------------------- | ||
|
||
bg_col <- "#fafafa" | ||
text_col <- "#00186d" | ||
highlight_col <- "#06c7ff" | ||
|
||
|
||
# Data wrangling ---------------------------------------------------------- | ||
|
||
plot_data <- eliminations |> | ||
mutate( | ||
place = case_when( | ||
str_detect(place, "–") ~ str_extract(place, "(?<=–).*"), | ||
str_detect(place, "-") ~ str_extract(place, "(?<=-).*"), | ||
TRUE ~ place | ||
), | ||
place = as.numeric(place) | ||
) |> | ||
filter(place <= 10) |> | ||
select(contestant, place) |> | ||
mutate( | ||
place = if_else(place == "1", highlight_col, text_col) | ||
) | ||
|
||
|
||
# Start recording --------------------------------------------------------- | ||
|
||
gg_record( | ||
dir = file.path("2024", "2024-07-23", "recording"), | ||
device = "png", | ||
width = 7, | ||
height = 7, | ||
units = "in", | ||
dpi = 300 | ||
) | ||
|
||
|
||
# Define text ------------------------------------------------------------- | ||
|
||
social <- nrBrand::social_caption( | ||
bg_colour = bg_col, | ||
icon_colour = highlight_col, | ||
font_colour = text_col, | ||
font_family = body_font | ||
) | ||
st <- glue::glue( | ||
"All **American Idol** <span style='color: {highlight_col};'>winners</span> | ||
and contestants who made the top 10 in each season." | ||
) | ||
cap <- paste0( | ||
"**Data**: Wikipedia | **Image**: Wikipedia <br>**Graphic**: ", social | ||
) | ||
|
||
|
||
# Plot -------------------------------------------------------------------- | ||
|
||
ggplot() + | ||
geom_textcircle( | ||
data = plot_data, | ||
mapping = aes(label = contestant, colour = place), | ||
family = body_font, | ||
r = 4 | ||
) + | ||
geom_image( | ||
data = slice_head(plot_data, n = 1), | ||
aes( | ||
x = 0, | ||
y = 0.5, | ||
image = "2024/2024-07-23/logo.png" | ||
), | ||
size = 0.3 | ||
) + | ||
geom_textbox( | ||
data = data.frame(x = 0, y = -1, label = st), | ||
mapping = aes(x = x, y = y, label = label), | ||
hjust = 0.5, | ||
halign = 0.5, | ||
colour = text_col, | ||
family = body_font, | ||
lineheight = 0.5, | ||
fill = "transparent", | ||
box.colour = "transparent", | ||
size = 9, | ||
minwidth = 0.45 | ||
) + | ||
scale_colour_identity() + | ||
scale_x_continuous(limits = c(-5, 5)) + | ||
scale_y_continuous(limits = c(-5, 5)) + | ||
labs(caption = cap) + | ||
coord_fixed() + | ||
theme_void(base_size = 20) + | ||
theme( | ||
plot.margin = margin(5, 5, 5, 5), | ||
plot.background = element_rect( | ||
fill = bg_col, colour = bg_col | ||
), | ||
panel.background = element_rect( | ||
fill = bg_col, colour = bg_col | ||
), | ||
plot.caption = element_textbox_simple( | ||
colour = text_col, | ||
hjust = 0, | ||
halign = 0, | ||
margin = margin(b = 5, t = -5, l = 5), | ||
lineheight = 0.5, | ||
family = body_font | ||
) | ||
) | ||
|
||
|
||
# Save image -------------------------------------------------------------- | ||
|
||
ggsave( | ||
"2024/2024-07-23/20240723.png", | ||
width = 7, | ||
height = 7 | ||
) | ||
|
||
|
||
# Save gif ---------------------------------------------------------------- | ||
|
||
gg_playback( | ||
name = file.path("2024", "2024-07-23", paste0("20240723", ".gif")), | ||
first_image_duration = 4, | ||
last_image_duration = 20, | ||
frame_duration = .25, | ||
background = bg_col | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<h1 align="center"> American Idol </h1> | ||
|
||
<p align="center"> | ||
<img src="/2024/2024-07-23/20240723.png" width="60%"> | ||
</p> | ||
|
||
The making of this visualisation was also recorded using the {camcorder} package. | ||
|
||
<p align="center"> | ||
<img src="/2024/2024-07-23/20240723.gif" width="60%"> | ||
</p> |