Just after that up-front judgment on plots as achieved in FDV (Wilke). Looking at extending to code and outputs.


knitr::opts_chunk$set(eval = T)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.0     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.1     ✔ tibble    3.2.0
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
readLines("https://raw.githubusercontent.com/clauswilke/dviz.supp/master/R/stamp.R") %>% 
  writeLines("stamp.R")

source("stamp.R")

tidytitanic::passengers %>% 
  tibble() %>% 
  mutate(cat_survived = ifelse(survived, "survived", "not survived"), 
         .before = 1)
## # A tibble: 1,313 × 6
##    cat_survived name                                   class   age sex   survi…¹
##    <chr>        <chr>                                  <chr> <dbl> <chr>   <int>
##  1 survived     Allen, Miss Elisabeth Walton           1st   29    fema…       1
##  2 not survived Allison, Miss Helen Loraine            1st    2    fema…       0
##  3 not survived Allison, Mr Hudson Joshua Creighton    1st   30    male        0
##  4 not survived Allison, Mrs Hudson JC (Bessie Waldo … 1st   25    fema…       0
##  5 survived     Allison, Master Hudson Trevor          1st    0.92 male        1
##  6 survived     Anderson, Mr Harry                     1st   47    male        1
##  7 survived     Andrews, Miss Kornelia Theodosia       1st   63    fema…       1
##  8 not survived Andrews, Mr Thomas, jr                 1st   39    male        0
##  9 survived     Appleton, Mrs Edward Dale (Charlotte … 1st   58    fema…       1
## 10 not survived Artagaveytia, Mr Ramon                 1st   71    male        0
## # … with 1,303 more rows, and abbreviated variable name ¹​survived
judge <- function(p, color, alpha, label, family = dviz_font_family_bold,
                  fontface = "plain", clip = "on")
{
  ggdraw(p, clip = clip) +
    draw_text(paste0(label, "  "), x=1, y=1, vjust=1.1, hjust=1, size=35, angle = 0,
              color=color, alpha=alpha, family = family, fontface = fontface) +
    draw_line(c(1, 1), c(0, 1), size=2.8, color=color, alpha=alpha)
}

theme_set(new = theme_classic(base_size = 30) + theme(plot.margin = margin(50,20,30,10)))

tidytitanic::passengers %>% 
  mutate(adult = age >=18 ) %>% 
  filter(!is.na(age)) %>% 
ggplot() + 
  aes(x = adult) + 
  geom_bar() ->
  p; p

library(cowplot)
## 
## Attaching package: 'cowplot'
## 
## The following objects are masked _by_ '.GlobalEnv':
## 
##     stamp, stamp_bad, stamp_good, stamp_ugly, stamp_wrong
## 
## The following object is masked from 'package:lubridate':
## 
##     stamp
p %>% judge(family = "Helvetica", color = "red", alpha = .9, label = "ugly", fontface = "bold")

p + 
  facet_grid(~ survived) ->
p2

p2 %>% judge(family = "Helvetica", color = "red", alpha = .9, label = "bad", fontface = "bold")

tidytitanic::passengers %>% 
  ggplot() + 
  aes(x = ind_recode(survived)) + 
  geom_bar() + 
  labs(x = NULL)
tidytitanic::passengers %>% 
  ggplot() + 
  aes(x = ifelse(survived, 
                 "survived",
                 "not survived")) + 
  geom_bar() + 
  labs(x = NULL)
knitr::knit_code$get("chunk") |>  
  paste(collapse = "\n") ->
text


# text <- "tidytitanic::passengers %>% \n  mutate(adult = age >=18 ) %>% \n  filter(!is.na(age)) %>% \nggplot() + \n  aes(x = adult) + \n  geom_bar()"
library(ggplot2)
ggplot(data = data.frame(x = c(0, 1), y = c(0,1))) +
  aes(x = x, y = y) +
  geom_blank() +
  annotate("text", label = text, x = 0, y = 1, hjust = 0, vjust = 1, size = 5, family = "Courier") + 
  theme_void() ->
syntax_plot

syntax_plot %>% judge(family = "Helvetica", color = "red", alpha = .9, label = "repetitive", fontface = "bold")

sink("temp.txt")
library(magrittr)
tidytitanic::passengers |> 
  janitor::tabyl(sex, survived)
sink()
readLines("temp.txt") %>% 
  paste(collapse = "\n")->
  text


library(ggplot2)
ggplot(data = data.frame(x = c(0, 1), y = c(0,1))) +
  aes(x = x, y = y) +
  geom_blank() +
  annotate("text", label = text, x = 0, y = 1, hjust = 0, vjust = 1, size = 5, family = "Courier") + 
  theme_void() ->
output_plot

output_plot %>% judge(family = "Helvetica", color = "red", alpha = .9, label = "awkward", fontface = "bold")