Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ea7333835 | ||
|
|
0d523c83de | ||
|
|
fc9383555d |
@@ -111,7 +111,9 @@ nvals <- function(x){
|
||||
#' simpleCap(my_string)
|
||||
simpleCap <- function(x) {
|
||||
stopifnot(class(x) == "character")
|
||||
s <- strsplit(x, " ")[[1]]
|
||||
sapply(x, function(word) {
|
||||
s <- strsplit(word, " ")[[1]]
|
||||
paste(toupper(substring(s, 1, 1)), substring(s, 2),
|
||||
sep = "", collapse = " ")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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 (the Civilytics cream canvas).
|
||||
#'
|
||||
#' @section Font size hierarchy:
|
||||
#' All text sizes are derived from `font_size` using relative scale factors.
|
||||
@@ -68,26 +67,29 @@
|
||||
#' \dontrun{
|
||||
#' library(ggplot2)
|
||||
#'
|
||||
#' # Default editorial theme
|
||||
#' # Transparent background (default) — composites cleanly onto any surface
|
||||
#' ggplot(mpg, aes(displ, hwy)) +
|
||||
#' geom_point() +
|
||||
#' theme_civilytics()
|
||||
#'
|
||||
#' # Warm paper canvas (opt-in)
|
||||
#' ggplot(mpg, aes(displ, hwy)) +
|
||||
#' geom_point() +
|
||||
#' theme_civilytics(paper_bg = TRUE)
|
||||
#'
|
||||
#' # With both gridlines and brand colors
|
||||
#' ggplot(mpg, aes(displ, hwy, colour = class)) +
|
||||
#' geom_point() +
|
||||
#' scale_color_civilytics() +
|
||||
#' theme_civilytics(grid = "both")
|
||||
#'
|
||||
#' # Transparent background for embedding
|
||||
#' ggplot(mpg, aes(displ, hwy)) +
|
||||
#' geom_point() +
|
||||
#' theme_civilytics(paper_bg = FALSE)
|
||||
#'
|
||||
#' # Larger text for poster or display
|
||||
#' ggplot(mpg, aes(displ, hwy)) +
|
||||
#' geom_point() +
|
||||
#' theme_civilytics(font_size = 18)
|
||||
#'
|
||||
#' # Note: for fully-transparent PNGs, also set a transparent device
|
||||
#' # background (e.g. `ggsave("plot.png", bg = NA)`).
|
||||
#' }
|
||||
theme_civilytics <- function(
|
||||
font_size = 14,
|
||||
@@ -102,7 +104,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
|
||||
|
||||
@@ -31,7 +31,7 @@ safe_max <- function(x) {
|
||||
#' pretty_per(0.2, ndigit = 1)
|
||||
#' pretty_per(c(0.2, 0.332423, 0.4, 0.342342), ndigit = 2)
|
||||
pretty_per <- function(x, ndigit = 1) {
|
||||
if (any(x >= 100) & !all(is.na(x))) {
|
||||
if (any(x >= 100) && !all(is.na(x))) {
|
||||
message("Values over 100 found, did you mean to use proportions?")
|
||||
}
|
||||
x <- format(round(x, digits = ndigit + 2) * 100, nsmall = ndigit)
|
||||
@@ -283,7 +283,7 @@ get_stabbr <- function(fips) {
|
||||
fips_codes <- fips_codes[!duplicated(fips_codes),]
|
||||
if (length(fips) != 1) {
|
||||
out <- rep(NA, length(fips))
|
||||
for (i in length(fips)) {
|
||||
for (i in seq_along(fips)) {
|
||||
out[i] <- fips_codes[fips_codes$state_code == fips, 1]
|
||||
|
||||
}
|
||||
@@ -375,7 +375,7 @@ random_round <- function(x) {
|
||||
add = rep(as.integer(0),length(r))
|
||||
add[r>test] <- as.integer(1)
|
||||
value = v + add
|
||||
ifelse(is.na(value) | value<0, 0, value)
|
||||
value <- ifelse(is.na(value) | value < 0, 0, value)
|
||||
return(value)
|
||||
}
|
||||
|
||||
|
||||
@@ -133,9 +133,17 @@ 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 has transparent background by default", {
|
||||
th <- theme_civilytics()
|
||||
expect_true(is.na(th$plot.background$fill))
|
||||
expect_true(is.na(th$panel.background$fill))
|
||||
expect_null(th$legend.background$fill)
|
||||
})
|
||||
|
||||
test_that("theme_civilytics paper_bg=TRUE opt-in fills with cream", {
|
||||
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 uses paper_2 for strip background by default", {
|
||||
|
||||
Reference in New Issue
Block a user