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

This commit is contained in:
2026-06-21 03:13:56 +00:00
parent 41162597cf
commit e256b73053
3 changed files with 45 additions and 17 deletions
+19 -8
View File
@@ -36,10 +36,9 @@
#' 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 `FALSE` (default), the plot and panel
#' backgrounds are transparent (`fill = NA`). Set to `TRUE` to fill them
#' with the warm `paper` color for a branded cream canvas.
#'
#' @section Font size hierarchy:
#' All text sizes are derived from `font_size` using relative scale factors.
@@ -64,11 +63,23 @@
#' @return A complete ggplot2 [ggplot2::theme()] object.
#' @export
#'
#' @section Transparent device background:
#' Setting `paper_bg = FALSE` makes the theme's `plot.background` and
#' `panel.background` transparent (`fill = NA`), but the graphics device
#' itself may still paint a solid background. To produce fully transparent
#' PNGs, also pass a transparent device background:
#'
#' ```r
#' ragg::agg_png("plot.png", background = "transparent")
#' print(p)
#' dev.off()
#' ```
#'
#' @examples
#' \dontrun{
#' library(ggplot2)
#'
#' # Default editorial theme
#' # Default: transparent background
#' ggplot(mpg, aes(displ, hwy)) +
#' geom_point() +
#' theme_civilytics()
@@ -79,10 +90,10 @@
#' scale_color_civilytics() +
#' theme_civilytics(grid = "both")
#'
#' # Transparent background for embedding
#' # Branded cream 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 +113,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