library (tidyverse)
creations <- bakeoff:: challenges |>
select (- technical) |>
pivot_longer (c (signature, showstopper)) |>
group_by (series) |>
mutate (
chocolat = sum (grepl ("[Cc]hocolat" , value)),
framboise = sum (grepl ("[Rr]aspberr" , value)),
orange = sum (grepl ("[Oo]range" , value))
) |>
select (series, chocolat, framboise, orange) |>
unique () |>
pivot_longer (- series, names_to = "ingredient" ) |>
mutate (
rank = rank (- value, ties.method = "min" ),
mary_berry = case_when (series < 8 ~ "oui" , TRUE ~ "non" )
)
couleurs_accessibles <- c (
"chocolat" = "#5F1C34" ,
"orange" = "#DCA113" ,
"framboise" = "#d33b66" ,
"mary" = "#F2CAE4"
)
creations |>
ggplot (aes (
x = series,
y = value,
colour = ingredient,
fill = ingredient
)) +
annotate (
geom = "rect" ,
xmin = - Inf ,
xmax = 7.5 ,
ymin = - Inf ,
ymax = Inf ,
fill = couleurs_accessibles["mary" ],
alpha = 0.3
) +
geom_line (show.legend = FALSE ) +
geom_vline (xintercept = 7.5 , linewidth = 0.2 , colour = "#ca3e8c" ) +
ggtext:: geom_textbox (
data = data.frame (),
aes (x = 7.5 , y = 31 , label = "**Les années Mary Berry**" ),
hjust = 1 ,
halign = 1 ,
box.colour = NA ,
colour = "#3f4a57" ,
family = "Inclusive Sans" ,
fill = NA
) +
geom_point (aes (shape = ingredient), size = 8 , colour = "#3f4a57" ) +
labs (
title = "Le chocolat demeure l'ingrédient le plus utilisé, même s'il s'est fait brièvement doubler par les oranges en Saison 8" ,
subtitle = "Le nombre de créations incluant du chocolat était bien plus élevé pendant que Mary Berry était dans le jury. On anticipe d'avoir besoin de deux fois plus de chocolat la saison prochaine si elle revient." ,
x = "Saison" ,
y = "Nombre de créations"
) +
scale_shape_manual (
values = c ("chocolat" = 22 , "orange" = 21 , "framboise" = 25 ),
) +
scale_fill_manual (values = couleurs_accessibles) +
scale_colour_manual (values = couleurs_accessibles) +
scale_y_continuous (limits = c (0 , 31 ), expand = expansion (add = c (0 , 2 ))) +
scale_x_continuous (breaks = c (1 : 10 )) +
theme_minimal (base_size = 12 ) +
theme (
plot.title.position = "plot" ,
text = element_text (family = "Inclusive Sans" , colour = "#3f4a57" ),
axis.text = element_text (family = "Inclusive Sans" , colour = "#3f4a57" ),
axis.title = element_text (family = "Inclusive Sans" , colour = "#3f4a57" ),
plot.title = marquee:: element_marquee (
width = 1 ,
style = marquee:: classic_style (weight = "bold" ),
margin = margin (12 , 0 , 18 , 0 ),
size = rel (1.6 ),
lineheight = 1.15 ,
family = "Inclusive Sans" ,
colour = "#071526"
),
plot.subtitle = marquee:: element_marquee (
width = 1 ,
vjust = 0 ,
size = rel (1.2 ),
family = "Inclusive Sans" ,
colour = "#3f4a57" ,
lineheight = 1.2 ,
margin = margin (12 , 0 , 24 , 0 )
),
legend.title = element_blank (),
legend.position = "bottom" ,
legend.justification = 0.5 ,
panel.grid.minor.x = element_blank (),
plot.margin = margin_auto (16 * 1.5 ),
plot.background = element_rect (fill = "#f8f8f8" , colour = "#f8f8f8" )
)