Repair Cafes

ocean
Repair Cafes.
Author

Cole Baril

Published

April 7, 2026

Load Packages

require(pacman)
p_load(tidytuesdayR, tidyverse, trashpanda, magick)

Load Data

tuesdata <- tidytuesdayR::tt_load('2026-04-07')
repairs <- tuesdata$repairs
repairs_text <- tuesdata$repairs_text

df <- repairs |> 
  mutate(year = year(repair_date)) |> 
  mutate(repair_score = case_when(repaired == "yes" ~ 1,
                                  repaired == "half" ~ 0.5,
                                  repaired == "no" ~ 0)) |> 
  reframe(mean_repair_score = mean(repair_score, na.rm = TRUE),
           n = n(),
          .by = c(category, year)) |> 
  drop_na() |> 
  filter(n > 1)

df_overall <- repairs |> 
  mutate(year = year(repair_date)) |> 
  mutate(repair_score = case_when(
    repaired == "yes" ~ 1,
    repaired == "half" ~ 0.5,
    repaired == "no" ~ 0
  )) |> 
  summarise(
    overall_mean = mean(repair_score, na.rm = TRUE),
    .by = category
  ) |> 
  drop_na()

Plot

plot <- df |> 
  ggplot() +
  geom_point(aes(x = as_factor(year), y = mean_repair_score),
             color = "#2C7FB8", size = 2, alpha = 0.8) +
  geom_smooth(
    color = "#084081", linewidth = 1,
    se = FALSE,
    method = "lm",
    aes(x = as_factor(year), y = mean_repair_score, group = category)
  ) +
  geom_label(
    data = df_overall,
    aes(
      x = Inf,
      y = Inf,
      label = paste0("Overall: ", round(overall_mean, 2)),
      fill = overall_mean
    ),
    hjust = 1.05,
    vjust = 1.2,
    fontface = "bold",
    size = 3.5,
    linewidth = 0.25,   # border thickness

    alpha = 0.9,
    inherit.aes = FALSE
  ) +

  scale_x_discrete(breaks = function(x) x[seq(1, length(x), by = 2)]) +
  scale_fill_gradientn(
  colours = c("#D73027", "#FEE08B", "#1A9850"),
  name = "Overall Mean Repair Completeness Score"
  ) +
  facet_wrap(~category, ncol = 2) +
  theme_cole(remove_grid = TRUE) +
  add_caption_cwb() +
  theme(
    axis.line = element_line(),
    panel.border = element_rect(),
    axis.title.x = element_text(margin = margin(t = 10, b = 10)),
    plot.title = element_text(hjust = 0),
    plot.subtitle = element_text(hjust = 0),
    legend.position = "top",
    legend.justification = "left",
    legend.key.width = unit(2, "cm"),
    legend.title.position = "top",
    strip.text = element_text(face = "bold", margin = margin(b = 1)),
    panel.spacing = unit(1, "lines")
  ) +
  labs(x = "Repair Year", y = "Mean Repair Completeness Score",
       title = "Repair Completeness for Household Goods",
       subtitle = str_wrap("In general, non-electric items have higher repair completeness scores compared to their electric counterparts (and goods that can't be electric, such as textiles). The repair completeness score for some items is increasing, while others are decreasing. Each point shows the yearly average “repair completeness” score (yes = 1, half repaired = 0.5, no = 0)."))

# Save and display images
current_dir <- dirname(knitr::current_input())
plot_name <- "repair_rates.png"

ggsave(plot = plot, 
       dpi = "screen",
       width = 10,
       height = 22,
       device = ragg::agg_png,
       filename = file.path(current_dir, plot_name))


# Read the big plot
img <- image_read(file.path(current_dir, plot_name))

# Force 16:9 aspect ratio with minimal padding
# Target size: 1200x675 px (16:9)
img_card <- image_scale(img, "1200x675")           # scale to fit inside 16:9
img_card <- image_extent(
  img_card,
  geometry = "1200x675",
  gravity = "center"
)

# Save as card preview
image_write(img_card, path = file.path(current_dir, "preview.png"))

knitr::include_graphics(
  file.path(current_dir, plot_name)
)

References

cite_packages(format = "rmd")
  1. Ooms J (2025). magick: Advanced Graphics and Image-Processing in R. doi:10.32614/CRAN.package.magick https://doi.org/10.32614/CRAN.package.magick, R package version 2.9.0, https://CRAN.R-project.org/package=magick.

  2. Baril C (2026). trashpanda: Cole’s Personal Collection of R Functions, Themes, and Palettes. R package version 0.0.1, commit d16de29303b66b1398238885a35c8a8b1aaf077f, https://github.com/colebaril/trashpanda.

  3. Grolemund G, Wickham H (2011). “Dates and Times Made Easy with lubridate.” Journal of Statistical Software, 40(3), 1-25. https://www.jstatsoft.org/v40/i03/.

  4. Wickham H (2025). forcats: Tools for Working with Categorical Variables (Factors). doi:10.32614/CRAN.package.forcats https://doi.org/10.32614/CRAN.package.forcats, R package version 1.0.1, https://CRAN.R-project.org/package=forcats.

  5. Wickham H (2025). stringr: Simple, Consistent Wrappers for Common String Operations. doi:10.32614/CRAN.package.stringr https://doi.org/10.32614/CRAN.package.stringr, R package version 1.6.0, https://CRAN.R-project.org/package=stringr.

  6. Wickham H, François R, Henry L, Müller K, Vaughan D (2023). dplyr: A Grammar of Data Manipulation. doi:10.32614/CRAN.package.dplyr https://doi.org/10.32614/CRAN.package.dplyr, R package version 1.1.4, https://CRAN.R-project.org/package=dplyr.

  7. Wickham H, Henry L (2026). purrr: Functional Programming Tools. doi:10.32614/CRAN.package.purrr https://doi.org/10.32614/CRAN.package.purrr, R package version 1.2.1, https://CRAN.R-project.org/package=purrr.

  8. Wickham H, Hester J, Bryan J (2025). readr: Read Rectangular Text Data. doi:10.32614/CRAN.package.readr https://doi.org/10.32614/CRAN.package.readr, R package version 2.1.6, https://CRAN.R-project.org/package=readr.

  9. Wickham H, Vaughan D, Girlich M (2025). tidyr: Tidy Messy Data. doi:10.32614/CRAN.package.tidyr https://doi.org/10.32614/CRAN.package.tidyr, R package version 1.3.2, https://CRAN.R-project.org/package=tidyr.

  10. Müller K, Wickham H (2026). tibble: Simple Data Frames. doi:10.32614/CRAN.package.tibble https://doi.org/10.32614/CRAN.package.tibble, R package version 3.3.1, https://CRAN.R-project.org/package=tibble.

  11. Wickham H (2016). ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. ISBN 978-3-319-24277-4, https://ggplot2.tidyverse.org.

  12. Wickham H, Averick M, Bryan J, Chang W, McGowan LD, François R, Grolemund G, Hayes A, Henry L, Hester J, Kuhn M, Pedersen TL, Miller E, Bache SM, Müller K, Ooms J, Robinson D, Seidel DP, Spinu V, Takahashi K, Vaughan D, Wilke C, Woo K, Yutani H (2019). “Welcome to the tidyverse.” Journal of Open Source Software, 4(43), 1686. doi:10.21105/joss.01686 https://doi.org/10.21105/joss.01686.

  13. Harmon J, Hughes E (2025). tidytuesdayR: Access the Weekly ‘TidyTuesday’ Project Dataset. doi:10.32614/CRAN.package.tidytuesdayR https://doi.org/10.32614/CRAN.package.tidytuesdayR, R package version 1.2.1, https://CRAN.R-project.org/package=tidytuesdayR.

  14. Rinker TW, Kurkiewicz D (2018). pacman: Package Management for R. version 0.5.0, http://github.com/trinker/pacman.