Author SHA1 Message Date
kodor 6cb75f72ef fix: address review round 5 for #7 2026-06-20 03:37:55 +00:00
kodor 7469d4cf0f fix: address review round 4 for #7
R-CMD-check / R CMD check (pull_request) Failing after 3m45s
2026-06-20 03:29:49 +00:00
kodor bbee17ef16 feat: resolve #7 theme_civilytics(): default to a transparent background, opt-in for Civilytics cream
R-CMD-check / R CMD check (pull_request) Failing after 3m52s
2026-06-20 03:02:46 +00:00
jared 41162597cf Merge pull request 'Fix issues #1, #3, #5: misc improvements' (#6) from fix/issues-1-3-5-misc-improvements into master
R-CMD-check / R CMD check (push) Successful in 4m25s
R-CMD-check / R CMD check (pull_request) Successful in 4m6s
Reviewed-on: #6
2026-06-04 14:04:44 -04:00
3 changed files with 28 additions and 12 deletions
+2 -2
View File
@@ -29,9 +29,9 @@ Imports:
sysfonts sysfonts
Encoding: UTF-8 Encoding: UTF-8
Suggests: Suggests:
quarto,
testthat (>= 3.0.0), testthat (>= 3.0.0),
tidycensus, tidycensus
quarto
Config/testthat/edition: 3 Config/testthat/edition: 3
Config/roxygen2/version: 8.0.0 Config/roxygen2/version: 8.0.0
RoxygenNote: 7.3.3 RoxygenNote: 7.3.3
+18 -9
View File
@@ -29,17 +29,26 @@
#' @param ink Character. Hex code for foreground/text color. Defaults to #' @param ink Character. Hex code for foreground/text color. Defaults to
#' [civilytics_colors]`["ink"]` (`#0E1A2B`). #' [civilytics_colors]`["ink"]` (`#0E1A2B`).
#' @param paper Character. Hex code for background color. Defaults to #' @param paper Character. Hex code for background color. Defaults to
#' [civilytics_colors]`["paper"]` (`#FAF7F2`). #' [civilytics_colors]`["paper"]` (`#FAF7F2`). Only used when
#' `paper_bg = TRUE`.
#' @param accent Character. Hex code for accent/highlight color. Defaults to #' @param accent Character. Hex code for accent/highlight color. Defaults to
#' [civilytics_colors]`["ember_600"]` (`#C25311`). #' [civilytics_colors]`["ember_600"]` (`#C25311`).
#' @param strip_color Character. Hex code for facet strip background. Defaults #' @param strip_color Character. Hex code for facet strip background. Defaults
#' to [civilytics_colors]`["paper_2"]` (`#F2EDE4`). #' to [civilytics_colors]`["paper_2"]` (`#F2EDE4`).
#' @param grid Character. Which major gridlines to draw: `"y"` (default, #' @param grid Character. Which major gridlines to draw: `"y"` (default,
#' horizontal only), `"x"` (vertical only), `"both"`, or `"none"`. #' horizontal only), `"x"` (vertical only), `"both"`, or `"none"`.
#' @param paper_bg Logical. If `TRUE` (default), fill the plot and panel #' @param paper_bg Logical. If `TRUE`, fill the plot and panel
#' backgrounds with the warm `paper` color. Set to `FALSE` for a #' backgrounds with the warm `paper` color. Default `FALSE` for a
#' transparent background (useful for slides or overlay on colored #' transparent background (recommended for embedding figures on
#' surfaces). #' colored surfaces, slides, or report pages). Set to `TRUE` to
#' enable the branded cream canvas.
#'
#' @section Device background note:
#' When saving plots to PNG with `ggsave()`, the transparent default
#' means the plot area will not have a solid background fill. If you
#' need a solid background in your exported PNG, set `paper_bg = TRUE`
#' or add `+ theme(plot.background = element_rect(fill = "white"))`
#' before saving.
#' #'
#' @section Font size hierarchy: #' @section Font size hierarchy:
#' All text sizes are derived from `font_size` using relative scale factors. #' All text sizes are derived from `font_size` using relative scale factors.
@@ -68,7 +77,7 @@
#' \dontrun{ #' \dontrun{
#' library(ggplot2) #' library(ggplot2)
#' #'
#' # Default editorial theme #' # Default transparent background
#' ggplot(mpg, aes(displ, hwy)) + #' ggplot(mpg, aes(displ, hwy)) +
#' geom_point() + #' geom_point() +
#' theme_civilytics() #' theme_civilytics()
@@ -79,10 +88,10 @@
#' scale_color_civilytics() + #' scale_color_civilytics() +
#' theme_civilytics(grid = "both") #' theme_civilytics(grid = "both")
#' #'
#' # Transparent background for embedding #' # Branded cream canvas (opt-in)
#' ggplot(mpg, aes(displ, hwy)) + #' ggplot(mpg, aes(displ, hwy)) +
#' geom_point() + #' geom_point() +
#' theme_civilytics(paper_bg = FALSE) #' theme_civilytics(paper_bg = TRUE)
#' #'
#' # Larger text for poster or display #' # Larger text for poster or display
#' ggplot(mpg, aes(displ, hwy)) + #' ggplot(mpg, aes(displ, hwy)) +
@@ -102,7 +111,7 @@ theme_civilytics <- function(
accent = unname(civilytics_colors["ember_600"]), accent = unname(civilytics_colors["ember_600"]),
strip_color = unname(civilytics_colors["paper_2"]), strip_color = unname(civilytics_colors["paper_2"]),
grid = c("y", "x", "both", "none"), grid = c("y", "x", "both", "none"),
paper_bg = TRUE) { paper_bg = FALSE) {
grid <- match.arg(grid) grid <- match.arg(grid)
half_line <- font_size / 2 half_line <- font_size / 2
+8 -1
View File
@@ -133,9 +133,16 @@ test_that("theme_civilytics uses brand ink color for text", {
expect_equal(th$text$colour, unname(civilytics_colors["ink"])) 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() th <- theme_civilytics()
expect_true(is.na(th$plot.background$fill))
expect_true(is.na(th$panel.background$fill))
})
test_that("theme_civilytics paper_bg=TRUE restores cream background", {
th <- theme_civilytics(paper_bg = TRUE)
expect_equal(th$plot.background$fill, unname(civilytics_colors["paper"])) expect_equal(th$plot.background$fill, unname(civilytics_colors["paper"]))
expect_equal(th$panel.background$fill, unname(civilytics_colors["paper"]))
}) })
test_that("theme_civilytics uses paper_2 for strip background by default", { test_that("theme_civilytics uses paper_2 for strip background by default", {