Files
civilyticsR/man/theme_civilytics.Rd
T

142 lines
4.6 KiB
R

% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/theme.R
\name{theme_civilytics}
\alias{theme_civilytics}
\title{Civilytics ggplot2 theme}
\usage{
theme_civilytics(
font_size = 14,
font_family = CV_FONT_SANS,
title_family = CV_FONT_DISPLAY,
line_size = 0.5,
rel_small = 12/14,
rel_tiny = 11/14,
rel_large = 20/14,
ink = unname(civilytics_colors["ink"]),
paper = unname(civilytics_colors["paper"]),
accent = unname(civilytics_colors["ember_600"]),
strip_color = unname(civilytics_colors["paper_2"]),
grid = c("y", "x", "both", "none"),
paper_bg = FALSE
)
}
\arguments{
\item{font_size}{Numeric. Base font size in points. Default `14`.}
\item{font_family}{Character. Font family for body/axis text. Default
`"Inter"` (loaded via showtext).}
\item{title_family}{Character. Font family for plot titles and strip labels.
Default `"Libre Franklin"` (loaded via showtext).}
\item{line_size}{Numeric. Base line width. Default `0.5`.}
\item{rel_small}{Numeric. Scale factor for small text relative to
`font_size`. Default `12/14`.}
\item{rel_tiny}{Numeric. Scale factor for tiny text relative to `font_size`.
Default `11/14`.}
\item{rel_large}{Numeric. Scale factor for large text (titles) relative to
`font_size`. Default `20/14` (~1.43x), matching the Civilytics editorial
design system.}
\item{ink}{Character. Hex code for foreground/text color. Defaults to
[civilytics_colors]`["ink"]` (`#0E1A2B`).}
\item{paper}{Character. Hex code for background color. Defaults to
[civilytics_colors]`["paper"]` (`#FAF7F2`).}
\item{accent}{Character. Hex code for accent/highlight color. Defaults to
[civilytics_colors]`["ember_600"]` (`#C25311`).}
\item{strip_color}{Character. Hex code for facet strip background. Defaults
to [civilytics_colors]`["paper_2"]` (`#F2EDE4`).}
\item{grid}{Character. Which major gridlines to draw: `"y"` (default,
horizontal only), `"x"` (vertical only), `"both"`, or `"none"`.}
\item{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.}
}
\value{
A complete ggplot2 [ggplot2::theme()] object.
}
\description{
A complete ggplot2 theme built on [ggplot2::theme_grey()] using the
Civilytics brand color palette and typography. Requires ggplot2 >= 4.0.0
for the `ink`, `paper`, and `accent` base-theme parameters.
}
\details{
Produces an editorial, Pew-style layout: visible x-axis line to ground
the data, light horizontal gridlines for reference, no panel border or
y-axis line. Plot title and caption are left-aligned to the full plot
region.
Brand fonts (Inter for UI text, Libre Franklin for titles) are loaded
automatically via [showtext] when the package is attached. Call
[civilytics_load_fonts()] to reload them if needed.
}
\section{Font size hierarchy}{
All text sizes are derived from `font_size` using relative scale factors.
At the default `font_size = 14`:
| Element | Scale factor | Default size |
|:--------|:-------------|:-------------|
| Plot title | `rel_large` (1.43x) | ~20 pt |
| Subtitle | 1.0x | 14 pt |
| Axis text (tick labels) | `rel_small` (0.86x) | ~12 pt |
| Axis titles | `rel_small` (0.86x) | ~12 pt |
| Legend text | `rel_small` (0.86x) | ~12 pt |
| Caption | `rel_tiny` (0.79x) | ~11 pt |
| Legend title | `rel_tiny` (0.79x) | ~11 pt |
| Strip text (facets) | `rel_small` (0.86x) | ~12 pt |
To uniformly scale all text, change `font_size`. To adjust only the title
prominence, change `rel_large`. When using [civilytics_logo()] to add a
logo below the plot, pass `font_scale` to compensate for viewport
shrinkage.
}
\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:
\if{html}{\out{<div class="sourceCode r">}}
\preformatted{ragg::agg_png("plot.png", background = "transparent")
print(p)
dev.off()}
\if{html}{\out{</div>}}
}
\examples{
\dontrun{
library(ggplot2)
# Default: transparent background
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
theme_civilytics()
# With both gridlines and brand colors
ggplot(mpg, aes(displ, hwy, colour = class)) +
geom_point() +
scale_color_civilytics() +
theme_civilytics(grid = "both")
# Branded cream canvas (opt-in)
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
theme_civilytics(paper_bg = TRUE)
# Larger text for poster or display
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
theme_civilytics(font_size = 18)
}
}