feat: resolve #7 theme_civilytics(): default to a transparent background, opt-in for Civilytics cream

This commit is contained in:
2026-06-21 23:49:51 -04:00
parent 41162597cf
commit 6d3c0a79d2
2 changed files with 19 additions and 14 deletions
+12 -8
View File
@@ -36,10 +36,14 @@
#' to [civilytics_colors]`["paper_2"]` (`#F2EDE4`).
#' @param grid Character. Which major gridlines to draw: `"y"` (default,
#' horizontal only), `"x"` (vertical only), `"both"`, or `"none"`.
#' @param paper_bg Logical. If `TRUE` (default), fill the plot and panel
#' backgrounds with the warm `paper` color. Set to `FALSE` for a
#' transparent background (useful for slides or overlay on colored
#' surfaces).
#' @param paper_bg Logical. If `TRUE`, fill the plot and panel
#' backgrounds with the warm `paper` color (the Civilytics cream,
#' `#FAF7F2`). Default is `FALSE` for a transparent background,
#' which composes cleanly onto report pages, slides, and web
#' backgrounds of any color. To get fully transparent PNGs you also
#' need a transparent graphics device (e.g. `ragg::agg_png(...,
#' background = "transparent")`); the theme alone cannot make the
#' device canvas transparent.
#'
#' @section Font size hierarchy:
#' All text sizes are derived from `font_size` using relative scale factors.
@@ -68,7 +72,7 @@
#' \dontrun{
#' library(ggplot2)
#'
#' # Default editorial theme
#' # Default editorial theme (transparent background)
#' ggplot(mpg, aes(displ, hwy)) +
#' geom_point() +
#' theme_civilytics()
@@ -79,10 +83,10 @@
#' scale_color_civilytics() +
#' theme_civilytics(grid = "both")
#'
#' # Transparent background for embedding
#' # Branded cream paper canvas (opt-in)
#' ggplot(mpg, aes(displ, hwy)) +
#' geom_point() +
#' theme_civilytics(paper_bg = FALSE)
#' theme_civilytics(paper_bg = TRUE)
#'
#' # Larger text for poster or display
#' ggplot(mpg, aes(displ, hwy)) +
@@ -102,7 +106,7 @@ theme_civilytics <- function(
accent = unname(civilytics_colors["ember_600"]),
strip_color = unname(civilytics_colors["paper_2"]),
grid = c("y", "x", "both", "none"),
paper_bg = TRUE) {
paper_bg = FALSE) {
grid <- match.arg(grid)
half_line <- font_size / 2
+7 -6
View File
@@ -133,9 +133,10 @@ test_that("theme_civilytics uses brand ink color for text", {
expect_equal(th$text$colour, unname(civilytics_colors["ink"]))
})
test_that("theme_civilytics uses brand paper color for plot background", {
test_that("theme_civilytics defaults to transparent plot background", {
th <- theme_civilytics()
expect_equal(th$plot.background$fill, unname(civilytics_colors["paper"]))
expect_true(is.na(th$plot.background$fill))
expect_true(is.na(th$panel.background$fill))
})
test_that("theme_civilytics uses paper_2 for strip background by default", {
@@ -178,10 +179,10 @@ test_that("theme_civilytics grid parameter controls gridlines", {
expect_s3_class(th_none$panel.grid.major.y, "element_blank")
})
test_that("theme_civilytics paper_bg=FALSE gives transparent background", {
th <- theme_civilytics(paper_bg = FALSE)
expect_true(is.na(th$plot.background$fill))
expect_true(is.na(th$panel.background$fill))
test_that("theme_civilytics paper_bg=TRUE gives cream paper background", {
th <- theme_civilytics(paper_bg = TRUE)
expect_equal(th$plot.background$fill, unname(civilytics_colors["paper"]))
expect_equal(th$panel.background$fill, unname(civilytics_colors["paper"]))
})
test_that("theme_civilytics has plot-aligned title and caption", {