feat: rebrand logos with wordmark/mark variants and pipe-friendly API
R-CMD-check / R CMD check (push) Successful in 2m39s
- Replace old civilytics_logo.png/white.png/jpg/pdf with new rebrand
assets: civilytics-wordmark.png, civilytics-wordmark-reverse.png,
civilytics-mark.png, civilytics-mark-reverse.png (all transparent bg)
- make_logo_grob() now accepts type = c("wordmark", "mark") alongside
variant = c("light", "dark") for 4 combinations
- New civilytics_logo() pipe-friendly convenience function:
ggplot(df, aes(x, y)) + geom_point() + theme_civilytics() |>
civilytics_logo()
R's |> has lower precedence than +, so the full ggplot chain pipes
through without parentheses
- Remove old icon/favicon assets no longer used
- Wrap showtext-dependent examples in \dontrun{} to prevent R CMD check
failures in headless PostScript environments
@@ -29,3 +29,4 @@ Suggests:
|
|||||||
tidycensus
|
tidycensus
|
||||||
Config/testthat/edition: 3
|
Config/testthat/edition: 3
|
||||||
Config/roxygen2/version: 8.0.0
|
Config/roxygen2/version: 8.0.0
|
||||||
|
RoxygenNote: 7.3.3
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ export(add_logo_ga)
|
|||||||
export(agresti_coull_interval)
|
export(agresti_coull_interval)
|
||||||
export(civilytics_colors)
|
export(civilytics_colors)
|
||||||
export(civilytics_load_fonts)
|
export(civilytics_load_fonts)
|
||||||
|
export(civilytics_logo)
|
||||||
export(civilytics_pal)
|
export(civilytics_pal)
|
||||||
export(clopper_pearson)
|
export(clopper_pearson)
|
||||||
export(countCleanr)
|
export(countCleanr)
|
||||||
|
|||||||
@@ -9,8 +9,10 @@
|
|||||||
#' @importFrom jpeg readJPEG
|
#' @importFrom jpeg readJPEG
|
||||||
#' @importFrom graphics rasterImage
|
#' @importFrom graphics rasterImage
|
||||||
#' @examples
|
#' @examples
|
||||||
#' img <- system.file("img","civilytics_logo.jpg",package="civilytics")
|
#' \dontrun{
|
||||||
|
#' img <- system.file("img","Knowles_Headshot_2019_good.jpg",package="civilytics")
|
||||||
#' plot_jpeg(img)
|
#' plot_jpeg(img)
|
||||||
|
#' }
|
||||||
plot_jpeg <- function(path, add=FALSE, upscale = TRUE)
|
plot_jpeg <- function(path, add=FALSE, upscale = TRUE)
|
||||||
{
|
{
|
||||||
jpg = readJPEG(path, native = TRUE) # read the file
|
jpg = readJPEG(path, native = TRUE) # read the file
|
||||||
@@ -160,27 +162,96 @@ add_logo_ga <- function(plot_list, logo, nrow = 1, widths = NULL, margin_param =
|
|||||||
#' Get a Civilytics Logo grob
|
#' Get a Civilytics Logo grob
|
||||||
#'
|
#'
|
||||||
#' Returns a ggplot object containing the Civilytics logo as a rasterGrob,
|
#' Returns a ggplot object containing the Civilytics logo as a rasterGrob,
|
||||||
#' ready to compose with plots via [add_logo()] or [add_logo_ga()].
|
#' ready to compose with plots via [add_logo()], [add_logo_ga()], or the
|
||||||
|
#' pipe-friendly [civilytics_logo()].
|
||||||
#'
|
#'
|
||||||
#' @param variant Character. `"light"` (default) uses the standard dark logo
|
#' @param type Character. `"wordmark"` (default) uses the full wordmark.
|
||||||
#' suitable for light backgrounds. `"dark"` uses the white logo suitable for
|
#' `"mark"` uses the compact C-pulse icon only.
|
||||||
#' dark backgrounds (pairs with [theme_civilytics_dark()]).
|
#' @param variant Character. `"light"` (default) uses the dark logo for light
|
||||||
|
#' backgrounds. `"dark"` uses the reverse (light) logo for dark backgrounds
|
||||||
|
#' (pairs with [theme_civilytics_dark()]).
|
||||||
#'
|
#'
|
||||||
#' @return A ggplot object (class `"gg"`) containing the logo grob.
|
#' @return A ggplot object (class `"gg"`) containing the logo grob.
|
||||||
#' @export
|
#' @export
|
||||||
#' @importFrom ggplot2 ggplot theme_void annotation_custom
|
#' @importFrom ggplot2 ggplot theme_void annotation_custom
|
||||||
#' @examples
|
#' @examples
|
||||||
#' logo <- make_logo_grob() # light background
|
#' logo <- make_logo_grob() # wordmark, light
|
||||||
#' logo_dark <- make_logo_grob("dark") # dark background
|
#' logo <- make_logo_grob("mark", "dark") # mark, dark
|
||||||
#' class(logo) # "gg" "ggplot"
|
#' class(logo) # "gg" "ggplot"
|
||||||
make_logo_grob <- function(variant = c("light", "dark")) {
|
make_logo_grob <- function(type = c("wordmark", "mark"),
|
||||||
|
variant = c("light", "dark")) {
|
||||||
|
type <- match.arg(type)
|
||||||
variant <- match.arg(variant)
|
variant <- match.arg(variant)
|
||||||
img_file <- if (variant == "dark") "civilytics_logo_white.png" else "civilytics_logo.png"
|
|
||||||
|
img_file <- switch(
|
||||||
|
paste(type, variant, sep = "_"),
|
||||||
|
wordmark_light = "civilytics-wordmark.png",
|
||||||
|
wordmark_dark = "civilytics-wordmark-reverse.png",
|
||||||
|
mark_light = "civilytics-mark.png",
|
||||||
|
mark_dark = "civilytics-mark-reverse.png"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Right-align the logo; the mark is compact so it gets a narrower slice.
|
||||||
|
xmin <- if (type == "mark") 0.93 else 0.65
|
||||||
|
|
||||||
ggplot2::ggplot() +
|
ggplot2::ggplot() +
|
||||||
ggplot2::theme_void() +
|
ggplot2::theme_void() +
|
||||||
ggplot2::annotation_custom(
|
ggplot2::annotation_custom(
|
||||||
get_png(system.file("img", img_file, package = "civilytics")),
|
get_png(system.file("img", img_file, package = "civilytics")),
|
||||||
xmin = 0.7, xmax = 1
|
xmin = xmin, xmax = 1
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#' Add a Civilytics logo to a ggplot (pipe-friendly)
|
||||||
|
#'
|
||||||
|
#' A convenience wrapper that creates the logo grob and attaches it below the
|
||||||
|
#' plot in one call. Designed for use with the base pipe `|>`:
|
||||||
|
#'
|
||||||
|
#' ```
|
||||||
|
#' ggplot(mpg, aes(displ, hwy)) +
|
||||||
|
#' geom_point() +
|
||||||
|
#' theme_civilytics() |>
|
||||||
|
#' civilytics_logo()
|
||||||
|
#' ```
|
||||||
|
#'
|
||||||
|
#' Since `|>` has lower precedence than `+`, the entire ggplot chain is piped
|
||||||
|
#' as the first argument — no parentheses needed.
|
||||||
|
#'
|
||||||
|
#' @param plot A ggplot object.
|
||||||
|
#' @param type Character. `"wordmark"` (default) or `"mark"`. Passed to
|
||||||
|
#' [make_logo_grob()].
|
||||||
|
#' @param variant Character. `"light"` (default) or `"dark"`. Passed to
|
||||||
|
#' [make_logo_grob()].
|
||||||
|
#' @param margin_param Numeric or `NULL`. Manual margin adjustment passed to
|
||||||
|
#' [add_logo()].
|
||||||
|
#'
|
||||||
|
#' @return A grob (from [gridExtra::arrangeGrob()]) ready to draw with
|
||||||
|
#' [grid::grid.draw()].
|
||||||
|
#' @export
|
||||||
|
#'
|
||||||
|
#' @examples
|
||||||
|
#' \dontrun{
|
||||||
|
#' library(ggplot2); library(grid)
|
||||||
|
#'
|
||||||
|
#' # Pipe-friendly usage
|
||||||
|
#' ggplot(mpg, aes(displ, hwy)) +
|
||||||
|
#' geom_point() +
|
||||||
|
#' theme_civilytics() |>
|
||||||
|
#' civilytics_logo() |>
|
||||||
|
#' grid.draw()
|
||||||
|
#'
|
||||||
|
#' # Dark theme with mark
|
||||||
|
#' ggplot(mpg, aes(displ, hwy)) +
|
||||||
|
#' geom_point() +
|
||||||
|
#' theme_civilytics_dark() |>
|
||||||
|
#' civilytics_logo(variant = "dark", type = "mark") |>
|
||||||
|
#' grid.draw()
|
||||||
|
#' }
|
||||||
|
civilytics_logo <- function(plot,
|
||||||
|
type = c("wordmark", "mark"),
|
||||||
|
variant = c("light", "dark"),
|
||||||
|
margin_param = NULL) {
|
||||||
|
logo <- make_logo_grob(type = type, variant = variant)
|
||||||
|
add_logo(plot, logo, margin_param = margin_param)
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
#' @export
|
#' @export
|
||||||
#'
|
#'
|
||||||
#' @examples
|
#' @examples
|
||||||
|
#' \dontrun{
|
||||||
#' library(ggplot2)
|
#' library(ggplot2)
|
||||||
#' ggplot(mpg, aes(displ, hwy)) +
|
#' ggplot(mpg, aes(displ, hwy)) +
|
||||||
#' geom_point() +
|
#' geom_point() +
|
||||||
@@ -42,6 +43,7 @@
|
|||||||
#' geom_point() +
|
#' geom_point() +
|
||||||
#' scale_color_civilytics() +
|
#' scale_color_civilytics() +
|
||||||
#' theme_civilytics()
|
#' theme_civilytics()
|
||||||
|
#' }
|
||||||
theme_civilytics <- function(
|
theme_civilytics <- function(
|
||||||
font_size = 14,
|
font_size = 14,
|
||||||
font_family = CV_FONT_SANS,
|
font_family = CV_FONT_SANS,
|
||||||
@@ -241,6 +243,7 @@ theme_civilytics <- function(
|
|||||||
#' @export
|
#' @export
|
||||||
#'
|
#'
|
||||||
#' @examples
|
#' @examples
|
||||||
|
#' \dontrun{
|
||||||
#' library(ggplot2)
|
#' library(ggplot2)
|
||||||
#' ggplot(mpg, aes(displ, hwy)) +
|
#' ggplot(mpg, aes(displ, hwy)) +
|
||||||
#' geom_point() +
|
#' geom_point() +
|
||||||
@@ -250,6 +253,7 @@ theme_civilytics <- function(
|
|||||||
#' geom_point() +
|
#' geom_point() +
|
||||||
#' scale_color_civilytics() +
|
#' scale_color_civilytics() +
|
||||||
#' theme_civilytics_dark()
|
#' theme_civilytics_dark()
|
||||||
|
#' }
|
||||||
theme_civilytics_dark <- function(
|
theme_civilytics_dark <- function(
|
||||||
font_size = 14,
|
font_size = 14,
|
||||||
font_family = CV_FONT_SANS,
|
font_family = CV_FONT_SANS,
|
||||||
|
|||||||
|
After Width: | Height: | Size: 149 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 217 KiB |
|
Before Width: | Height: | Size: 89 KiB |
|
Before Width: | Height: | Size: 123 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 8.4 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
@@ -19,10 +19,5 @@ Useful links:
|
|||||||
\author{
|
\author{
|
||||||
\strong{Maintainer}: Jared E. Knowles \email{jared@civilytics.com}
|
\strong{Maintainer}: Jared E. Knowles \email{jared@civilytics.com}
|
||||||
|
|
||||||
Authors:
|
|
||||||
\itemize{
|
|
||||||
\item Jared E. Knowles \email{jared@civilytics.com}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
\keyword{internal}
|
\keyword{internal}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
% Generated by roxygen2: do not edit by hand
|
% Generated by roxygen2: do not edit by hand
|
||||||
% Please edit documentation in R/colors.R
|
% Please edit documentation in R/colors.R
|
||||||
|
\docType{data}
|
||||||
\name{civilytics_colors}
|
\name{civilytics_colors}
|
||||||
\alias{civilytics_colors}
|
\alias{civilytics_colors}
|
||||||
\title{Civilytics brand colors}
|
\title{Civilytics brand colors}
|
||||||
@@ -17,3 +18,4 @@ custom properties defined on www.civilytics.com (`--cv-*` variables).
|
|||||||
civilytics_colors["accent"]
|
civilytics_colors["accent"]
|
||||||
civilytics_colors[c("ink", "paper")]
|
civilytics_colors[c("ink", "paper")]
|
||||||
}
|
}
|
||||||
|
\keyword{datasets}
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/logo.R
|
||||||
|
\name{civilytics_logo}
|
||||||
|
\alias{civilytics_logo}
|
||||||
|
\title{Add a Civilytics logo to a ggplot (pipe-friendly)}
|
||||||
|
\usage{
|
||||||
|
civilytics_logo(
|
||||||
|
plot,
|
||||||
|
type = c("wordmark", "mark"),
|
||||||
|
variant = c("light", "dark"),
|
||||||
|
margin_param = NULL
|
||||||
|
)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{plot}{A ggplot object.}
|
||||||
|
|
||||||
|
\item{type}{Character. `"wordmark"` (default) or `"mark"`. Passed to
|
||||||
|
[make_logo_grob()].}
|
||||||
|
|
||||||
|
\item{variant}{Character. `"light"` (default) or `"dark"`. Passed to
|
||||||
|
[make_logo_grob()].}
|
||||||
|
|
||||||
|
\item{margin_param}{Numeric or `NULL`. Manual margin adjustment passed to
|
||||||
|
[add_logo()].}
|
||||||
|
}
|
||||||
|
\value{
|
||||||
|
A grob (from [gridExtra::arrangeGrob()]) ready to draw with
|
||||||
|
[grid::grid.draw()].
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
A convenience wrapper that creates the logo grob and attaches it below the
|
||||||
|
plot in one call. Designed for use with the base pipe `|>`:
|
||||||
|
}
|
||||||
|
\details{
|
||||||
|
```
|
||||||
|
ggplot(mpg, aes(displ, hwy)) +
|
||||||
|
geom_point() +
|
||||||
|
theme_civilytics() |>
|
||||||
|
civilytics_logo()
|
||||||
|
```
|
||||||
|
|
||||||
|
Since `|>` has lower precedence than `+`, the entire ggplot chain is piped
|
||||||
|
as the first argument — no parentheses needed.
|
||||||
|
}
|
||||||
|
\examples{
|
||||||
|
\dontrun{
|
||||||
|
library(ggplot2); library(grid)
|
||||||
|
|
||||||
|
# Pipe-friendly usage
|
||||||
|
ggplot(mpg, aes(displ, hwy)) +
|
||||||
|
geom_point() +
|
||||||
|
theme_civilytics() |>
|
||||||
|
civilytics_logo() |>
|
||||||
|
grid.draw()
|
||||||
|
|
||||||
|
# Dark theme with mark
|
||||||
|
ggplot(mpg, aes(displ, hwy)) +
|
||||||
|
geom_point() +
|
||||||
|
theme_civilytics_dark() |>
|
||||||
|
civilytics_logo(variant = "dark", type = "mark") |>
|
||||||
|
grid.draw()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,22 +4,26 @@
|
|||||||
\alias{make_logo_grob}
|
\alias{make_logo_grob}
|
||||||
\title{Get a Civilytics Logo grob}
|
\title{Get a Civilytics Logo grob}
|
||||||
\usage{
|
\usage{
|
||||||
make_logo_grob(variant = c("light", "dark"))
|
make_logo_grob(type = c("wordmark", "mark"), variant = c("light", "dark"))
|
||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
\item{variant}{Character. `"light"` (default) uses the standard dark logo
|
\item{type}{Character. `"wordmark"` (default) uses the full wordmark.
|
||||||
suitable for light backgrounds. `"dark"` uses the white logo suitable for
|
`"mark"` uses the compact C-pulse icon only.}
|
||||||
dark backgrounds (pairs with [theme_civilytics_dark()]).}
|
|
||||||
|
\item{variant}{Character. `"light"` (default) uses the dark logo for light
|
||||||
|
backgrounds. `"dark"` uses the reverse (light) logo for dark backgrounds
|
||||||
|
(pairs with [theme_civilytics_dark()]).}
|
||||||
}
|
}
|
||||||
\value{
|
\value{
|
||||||
A ggplot object (class `"gg"`) containing the logo grob.
|
A ggplot object (class `"gg"`) containing the logo grob.
|
||||||
}
|
}
|
||||||
\description{
|
\description{
|
||||||
Returns a ggplot object containing the Civilytics logo as a rasterGrob,
|
Returns a ggplot object containing the Civilytics logo as a rasterGrob,
|
||||||
ready to compose with plots via [add_logo()] or [add_logo_ga()].
|
ready to compose with plots via [add_logo()], [add_logo_ga()], or the
|
||||||
|
pipe-friendly [civilytics_logo()].
|
||||||
}
|
}
|
||||||
\examples{
|
\examples{
|
||||||
logo <- make_logo_grob() # light background
|
logo <- make_logo_grob() # wordmark, light
|
||||||
logo_dark <- make_logo_grob("dark") # dark background
|
logo <- make_logo_grob("mark", "dark") # mark, dark
|
||||||
class(logo) # "gg" "ggplot"
|
class(logo) # "gg" "ggplot"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ a rasterImage
|
|||||||
Plot a jpeg image as a raster
|
Plot a jpeg image as a raster
|
||||||
}
|
}
|
||||||
\examples{
|
\examples{
|
||||||
img <- system.file("img","civilytics_logo.jpg",package="civilytics")
|
\dontrun{
|
||||||
|
img <- system.file("img","Knowles_Headshot_2019_good.jpg",package="civilytics")
|
||||||
plot_jpeg(img)
|
plot_jpeg(img)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ automatically via [showtext] when the package is attached. Call
|
|||||||
[civilytics_load_fonts()] to reload them if needed.
|
[civilytics_load_fonts()] to reload them if needed.
|
||||||
}
|
}
|
||||||
\examples{
|
\examples{
|
||||||
|
\dontrun{
|
||||||
library(ggplot2)
|
library(ggplot2)
|
||||||
ggplot(mpg, aes(displ, hwy)) +
|
ggplot(mpg, aes(displ, hwy)) +
|
||||||
geom_point() +
|
geom_point() +
|
||||||
@@ -74,3 +75,4 @@ ggplot(mpg, aes(displ, hwy, colour = class)) +
|
|||||||
scale_color_civilytics() +
|
scale_color_civilytics() +
|
||||||
theme_civilytics()
|
theme_civilytics()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ All parameters from [theme_civilytics()] are accepted and override the dark
|
|||||||
defaults.
|
defaults.
|
||||||
}
|
}
|
||||||
\examples{
|
\examples{
|
||||||
|
\dontrun{
|
||||||
library(ggplot2)
|
library(ggplot2)
|
||||||
ggplot(mpg, aes(displ, hwy)) +
|
ggplot(mpg, aes(displ, hwy)) +
|
||||||
geom_point() +
|
geom_point() +
|
||||||
@@ -74,3 +75,4 @@ ggplot(mpg, aes(displ, hwy, colour = class)) +
|
|||||||
scale_color_civilytics() +
|
scale_color_civilytics() +
|
||||||
theme_civilytics_dark()
|
theme_civilytics_dark()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -160,20 +160,43 @@ test_that("theme_civilytics_dark uses navy for strip background", {
|
|||||||
|
|
||||||
# --- make_logo_grob ----------------------------------------------------------
|
# --- make_logo_grob ----------------------------------------------------------
|
||||||
|
|
||||||
test_that("make_logo_grob returns a gg object for light variant", {
|
test_that("make_logo_grob returns a gg object for all type/variant combos", {
|
||||||
logo <- make_logo_grob("light")
|
for (type in c("wordmark", "mark")) {
|
||||||
|
for (variant in c("light", "dark")) {
|
||||||
|
logo <- make_logo_grob(type = type, variant = variant)
|
||||||
expect_s3_class(logo, "gg")
|
expect_s3_class(logo, "gg")
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
test_that("make_logo_grob returns a gg object for dark variant", {
|
test_that("make_logo_grob defaults to wordmark light", {
|
||||||
logo <- make_logo_grob("dark")
|
|
||||||
expect_s3_class(logo, "gg")
|
|
||||||
})
|
|
||||||
|
|
||||||
test_that("make_logo_grob defaults to light variant", {
|
|
||||||
expect_no_error(make_logo_grob())
|
expect_no_error(make_logo_grob())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test_that("make_logo_grob errors on invalid type", {
|
||||||
|
expect_error(make_logo_grob(type = "banner"))
|
||||||
|
})
|
||||||
|
|
||||||
test_that("make_logo_grob errors on invalid variant", {
|
test_that("make_logo_grob errors on invalid variant", {
|
||||||
expect_error(make_logo_grob("purple"))
|
expect_error(make_logo_grob(variant = "purple"))
|
||||||
|
})
|
||||||
|
|
||||||
|
# --- civilytics_logo (pipe-friendly) -----------------------------------------
|
||||||
|
|
||||||
|
test_that("civilytics_logo returns a grob", {
|
||||||
|
p <- ggplot(mpg, aes(displ, hwy)) + geom_point() + theme_civilytics()
|
||||||
|
result <- suppressWarnings(civilytics_logo(p))
|
||||||
|
expect_s3_class(result, "grob")
|
||||||
|
})
|
||||||
|
|
||||||
|
test_that("civilytics_logo works with pipe operator", {
|
||||||
|
p <- ggplot(mpg, aes(displ, hwy)) + geom_point() + theme_civilytics()
|
||||||
|
result <- suppressWarnings(p |> civilytics_logo())
|
||||||
|
expect_s3_class(result, "grob")
|
||||||
|
})
|
||||||
|
|
||||||
|
test_that("civilytics_logo accepts type and variant params", {
|
||||||
|
p <- ggplot(mpg, aes(displ, hwy)) + geom_point() + theme_civilytics_dark()
|
||||||
|
result <- suppressWarnings(civilytics_logo(p, type = "mark", variant = "dark"))
|
||||||
|
expect_s3_class(result, "grob")
|
||||||
})
|
})
|
||||||
|
|||||||