library(ggh4x)
library(ggtext)
strip_ektheme <- strip_nested(
text_x = distribute_args(
size = c(14, 10), colour = c("darkred", "black"),
face = c("bold", "plain"),
fill = list(NA, "lightblue"),
box.color = list(NA, "darkblue"),
halign = list(0.5, 0.5), valign = list(1, 0.5),
linetype = list(0, 1), r = list(NULL, unit(5, "pt")),
width = list(NULL, unit(1, "npc")),
padding = list(NULL, margin(5, 0, 4, 0)),
margin = list(margin(1, 0, 2, 0), margin(7, 3, 3, 3)),
.fun = element_textbox),
size = "variable",
by_layer_x = TRUE
)
pivot_longer(penguins, names_to = c("what", "measure"),
values_to = "value",
bill_length_mm:body_mass_g, names_sep = "_") |>
ggplot(aes(x = species, y = log(value))) +
geom_violin(trim = FALSE) +
facet_nested(~ what + measure, strip = strip_ektheme, #<<
nest_line = TRUE, resect = unit(15, "mm"), #<<
axes = TRUE, remove_labels = TRUE) + #<<
theme_classic(14) +
theme(strip.background = element_blank(),
axis.text.x = element_text(angle = 45, hjust = 1),
ggh4x.facet.nestline = element_line(colour = "rosybrown")) #<<