Skip to contents

House styling for ggplot2 and tinytable.

maison is the presentation layer behind a family of reporting tools. It gives every chart and table the same typography, palette and spacing, whether it ends up in a long-form HTML report, a slide deck, or a one-off analysis. Load it once at the top of a document and everything downstream inherits the look.

Status: 0.3.0, the first CRAN release candidate. The interface is frozen for this release. See NEWS.md for what changed since 0.2.0.

Where it fits

Project Role
loom Headless survey workflow: import, codebook, analysis, unstyled charts
maison How charts and tables look
Tweed Quarto HTML report template
Twill Quarto revealjs deck template

Analysis packages such as loom never set a color or a font. maison does, and only maison.

Principles

  • Type first. A strict typographic hierarchy (an 18 pt bold title, 12 pt subtitle, 9 pt axis titles and caption, flush-left headings) and almost no non-data ink. The approach owes a lot to hrbrthemes; maison is built natively on ggplot2 rather than ported.
  • One theme, many arguments. A single theme_maison() with arguments for font, size, grid and margins, not one function per variant.
  • Palettes ship with the theme. Categorical, sequential, diverging and Likert palettes are defined once, so no report hard-codes a hex value.
  • Text on the chart matches the chart. Labels drawn with geom_text() and geom_label() inherit the theme’s font and type scale.
  • Tables follow the same scale. The tinytable theme draws the rules, bold headers and alignment, and tags tables for Tweed and Twill’s stylesheet; typeface and size stay in CSS.
  • Free fonts by default. The defaults are free Google fonts (Hanken Grotesk, Newsreader, IBM Plex Mono), and a licensed face such as Aktiv Grotesk can be swapped in. Fonts are found through systemfonts and drawn with ragg; maison bundles no font files.
  • No global state. Geom defaults and palettes travel inside the theme object. maison never calls update_geom_defaults() or sets ggplot2.* options, so nothing leaks from one document into the next.
  • Light dependencies. ggplot2, scales and tinytable, and little else.

Install

# From CRAN (pending: this works once 0.3.0 is accepted)
install.packages("maison")

# The development version, from GitHub
# install.packages("remotes")
remotes::install_github("LarryVincent/maison")

Usage

library(maison)
library(ggplot2)

set_maison()      # ggplot theme, default palettes and tinytable theme, in one line

ggplot(df, aes(share, item, fill = segment)) +
  geom_col()      # picks up the maison theme and palette, no extra calls

tinytable::tt(summary_tbl)   # styled to match

set_maison() goes in each document’s setup chunk. It sets the default ggplot2 theme and the default tinytable theme, and nothing else.

The pieces also work on their own:

Function Use
theme_maison() The theme. Arguments for font, type scale, grid, axis, dark, void and background
maison_colors, maison_pal() Brand colors by name; palettes as functions of n
scale_fill_maison_d(), _c(), _div() Explicit scales, with colour/color versions, for when the theme default isn’t what the chart needs
scale_fill_maison_likert() Agreement scales of 2 to 11 points, rust to green or palette = "quiet"
maison_highlight() One category in red, the rest in plum or base = "olive"
maison_label_color() Ink or warm_white for a label, whichever reads better on its fill
theme_maison_tt() The table theme: tt(df, theme = theme_maison_tt)
check_maison_fonts() Which house fonts are installed, and how to get the rest

The palettes, all by name through maison_pal() and the scales:

Kind Palettes
Categorical categorical (eight colors), categorical_dark (six that read on charcoal)
Sequential seq_purple (the default), seq_neutral, seq_gray, seq_red, seq_honey, seq_green, seq_rust, seq_cobalt
Diverging diverging (charcoal to red), diverging_green (plum to green), quiet
Quiet ramps quiet_purple, quiet_sage
Likert likert

Six things to know:

  • Likert charts need their scale. ggplot2 doesn’t apply theme palettes to ordered factors, so add scale_fill_maison_likert(). With long statement labels, theme_maison(legend_location = "panel") starts the legend where the bars start.

  • Horizontal bars need grid = "X". The default grid suits vertical bars and time series. When values run along the x axis, including with coord_flip(), use theme_maison(grid = "X").

  • The categorical palette has eight colors, six on dark. One group too many is an error, not a recycled or invented color. Combine groups, use maison_highlight(), or pick a ramped palette.

  • Red is for emphasis. It is not a categorical color; maison_highlight() uses it.

  • Charts have no outer margin, so their edges align on a slide or page. If an axis label is cut off at the edge, add plot_margin = margin(r = 12); set_maison(plot_margin = ) sets a margin for every chart. background = "transparent" drops the background as well.

  • Fonts must be installed. Run check_maison_fonts() once per machine. A missing font gets one warning and charts fall back to the default sans. In Quarto, render figures with ragg_png so the fonts are used:

    knitr:
      opts_chunk:
        dev: ragg_png

vignette("gallery", package = "maison") has fifteen charts with the code that makes each one, all on simulated data: the concept-test boxplot with mean labels, an annotated time series, small multiples with inline statistics, zone bands, a dot timeline, bars with in-bar labels, stacked bars with a shaded period, a bubble scatter with repelled labels, a dumbbell, Likert stacks in both palettes, a highlight chart, a heatmap, a donut, a dark-slide chart and a transparent background.

Roadmap

Phase Scope
0 Done: technical spike in dev/, confirming a ggplot2 theme alone can set geom and palette defaults
1 Done in 0.1.0: theme_maison(), palettes and scales, Likert and highlight palettes, font checks, tinytable theme, set_maison(), visual snapshot tests
2 Done in 0.2.0: eight-color categorical palette and a dark-slide order, hand-tuned sequential ramps, quiet palettes, zero margins, transparent background, quiet fallback for missing fonts
3 Done in 0.3.0: the interface settled for CRAN, house defaults for reference lines, shaded periods, boxplots, intervals, ribbons, smooths and segments, void, maison_label_color(), and the gallery vignette
Later Reading colors and fonts from a shared _brand.yml, palette swatch viewer

License

MIT © Larry Vincent