feat: add brand color system, showtext fonts, and dark theme
R-CMD-check / R CMD check (push) Failing after 1m39s
R-CMD-check / R CMD check (push) Failing after 1m39s
- R/colors.R: civilytics_colors named vector (from --cv-* CSS vars on civilytics.com), three palettes (main/sequential/diverging), scale_color_civilytics() and scale_fill_civilytics() for ggplot2 - R/fonts.R: auto-loads Inter + Libre Franklin from Google Fonts via showtext in .onLoad(); exports civilytics_load_fonts() for manual retry - R/theme.R: wires ggplot2 4.0 ink/paper/accent params into theme_grey() base, adds title_family + strip_color params; new theme_civilytics_dark() using navy_dark background and warm off-white text - R/logo.R: make_logo_grob(variant) accepts "light"/"dark" to select the white logo for dark-background compositions - DESCRIPTION: adds showtext, sysfonts; pins ggplot2 >= 4.0.0 - tests/testthat/test_theme.R: full test suite for colors, palettes, scales, both theme variants, and logo grob variants
This commit is contained in:
@@ -121,12 +121,14 @@ has_caption <- function(gg) {
|
||||
#' @export
|
||||
#'
|
||||
#' @examples
|
||||
#' \dontrun{
|
||||
#' library(ggplot2); library(grid)
|
||||
#' tmp_plot <- ggplot(mtcars) + aes(x = hp, y = disp) + geom_point() + theme_civilytics()
|
||||
#' tmp_logo <- make_logo_grob()
|
||||
#' plot_and_logo <- add_logo(tmp_plot, tmp_logo)
|
||||
#' grid.draw(plot_and_logo)
|
||||
#' dev.off()
|
||||
#' }
|
||||
add_logo_ga <- function(plot_list, logo, nrow = 1, widths = NULL, margin_param = NULL) {
|
||||
# Change position of logo depending on if plot has a caption
|
||||
if (!is.null(margin_param)) {
|
||||
@@ -157,17 +159,28 @@ add_logo_ga <- function(plot_list, logo, nrow = 1, widths = NULL, margin_param =
|
||||
|
||||
#' Get a Civilytics Logo grob
|
||||
#'
|
||||
#' @return a gg object which contains the logo file stored as a Grob suitable for manipulating in
|
||||
#' grid
|
||||
#' Returns a ggplot object containing the Civilytics logo as a rasterGrob,
|
||||
#' ready to compose with plots via [add_logo()] or [add_logo_ga()].
|
||||
#'
|
||||
#' @param variant Character. `"light"` (default) uses the standard dark logo
|
||||
#' suitable for light backgrounds. `"dark"` uses the white logo suitable for
|
||||
#' dark backgrounds (pairs with [theme_civilytics_dark()]).
|
||||
#'
|
||||
#' @return A ggplot object (class `"gg"`) containing the logo grob.
|
||||
#' @export
|
||||
#' @import ggplot2
|
||||
#' @importFrom ggplot2 ggplot theme_void annotation_custom
|
||||
#' @examples
|
||||
#' logo <- make_logo_grob()
|
||||
#' class(logo) # gg
|
||||
make_logo_grob <- function() {
|
||||
ggplot() +
|
||||
theme_void() +
|
||||
annotation_custom(get_png(system.file("img", "civilytics_logo.png",
|
||||
package = "civilytics")), xmin = 0.7, xmax = 1)
|
||||
#' logo <- make_logo_grob() # light background
|
||||
#' logo_dark <- make_logo_grob("dark") # dark background
|
||||
#' class(logo) # "gg" "ggplot"
|
||||
make_logo_grob <- function(variant = c("light", "dark")) {
|
||||
variant <- match.arg(variant)
|
||||
img_file <- if (variant == "dark") "civilytics_logo_white.png" else "civilytics_logo.png"
|
||||
ggplot2::ggplot() +
|
||||
ggplot2::theme_void() +
|
||||
ggplot2::annotation_custom(
|
||||
get_png(system.file("img", img_file, package = "civilytics")),
|
||||
xmin = 0.7, xmax = 1
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user