params <-
list(family = "red", preset = "homage", base_size = 13L, content_width = 80L, 
    style = "minimal")

## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE, comment = "#>", fig.align = "center", fig.retina = 2,
  out.width = "100%", fig.width = 7, fig.asp = 0.6, message = FALSE, warning = FALSE
)
library(ggplot2)
if (requireNamespace("ragg", quietly = TRUE)) knitr::opts_chunk$set(dev = "ragg_png")
if (
  requireNamespace("systemfonts", quietly = TRUE) &&
  requireNamespace("albersdown", quietly = TRUE) &&
  "albers_register_fonts" %in% getNamespaceExports("albersdown")
) {
  albersdown::albers_register_fonts()
}
if (requireNamespace("ggplot2", quietly = TRUE) && requireNamespace("albersdown", quietly = TRUE)) {
  ggplot2::theme_set(albersdown::theme_albers(family = params$family, preset = params$preset))
}

## ----albers-classes, echo=FALSE, results='asis'-------------------------------
cat(sprintf(
  paste0(
    '<script>document.addEventListener("DOMContentLoaded",function(){',
    'document.body.classList.remove("palette-red","palette-lapis","palette-ochre","palette-teal","palette-green","palette-violet","preset-homage","preset-interaction","preset-study","preset-structural","preset-adobe","preset-midnight");',
    'document.body.classList.add("palette-%s","preset-%s");',
    '});</script>'
  ),
  params$family,
  params$preset
))

## ----families-swatch, fig.height=2.4------------------------------------------
albersdown::albers_swatch(c("red", "lapis", "ochre", "teal", "green", "violet"))

## ----accent-families, fig.height=5.4------------------------------------------
families <- c("red", "lapis", "ochre", "teal", "green", "violet")
accent_a700 <- vapply(families, function(f) albersdown::albers_palette(f)[["A700"]], character(1))

plot_df <- do.call(rbind, lapply(seq_along(families), function(i) {
  d <- mtcars
  d$family <- families[[i]]
  d
}))
plot_df$family <- factor(plot_df$family, levels = families)

ggplot(plot_df, aes(wt, mpg, colour = family)) +
  geom_point(alpha = 0.85, size = 1.7) +
  facet_wrap(~family, ncol = 3) +
  scale_color_manual(values = accent_a700) +
  labs(
    title = "The same data in each family's A700 accent",
    subtitle = "Geometry held constant, only the accent family changes",
    x = "weight", y = "mpg"
  ) +
  theme(legend.position = "none")

## ----homage-plot--------------------------------------------------------------
ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
  geom_point(size = 2.2) +
  albersdown::scale_color_albers(family = "red") +
  labs(title = "Homage direction", subtitle = "Warm cream ground, red family", colour = "cyl") +
  albersdown::theme_albers(family = "red", preset = "homage")

## ----interaction-plot---------------------------------------------------------
ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
  geom_point(size = 2.2) +
  albersdown::scale_color_albers(family = "lapis") +
  labs(title = "Interaction direction", subtitle = "Cool grey ground, lapis family", colour = "cyl") +
  albersdown::theme_albers(family = "lapis", preset = "interaction")

## ----recipes-table------------------------------------------------------------
recipes <- data.frame(
  profile = c("homage-red", "homage-teal", "interaction-lapis", "interaction-ochre"),
  family = c("red", "teal", "lapis", "ochre"),
  direction = c("homage", "homage", "interaction", "interaction"),
  mood = c("warm, classic", "warm, calm", "cool, technical", "cool, earthy"),
  stringsAsFactors = FALSE
)
knitr::kable(recipes, format = "html", caption = "A few coherent direction + family pairings.")

