Skip to contents

A complete theme, built on ggplot2::theme_minimal(), that carries the whole house style: the type scale, the background, defaults for the geoms that draw labels, bars, points and lines, and the default color palettes. Nothing global is changed, so a plot without the theme is unaffected.

Usage

theme_maison(
  base_family = "Hanken Grotesk",
  base_size = 11.5,
  grid = "Y",
  axis = FALSE,
  dark = FALSE,
  void = FALSE,
  legend_position = "top",
  legend_location = "plot",
  background = NULL,
  fallback = TRUE,
  plot_title_size = 18,
  plot_title_face = "bold",
  plot_title_margin = 10,
  subtitle_size = 12,
  subtitle_face = "plain",
  subtitle_margin = 15,
  strip_text_size = 12,
  strip_text_face = "plain",
  axis_text_size = base_size,
  axis_title_size = 9,
  axis_title_face = "plain",
  caption_size = 9,
  caption_face = "italic",
  caption_margin = 10,
  label_size = base_size,
  grid_major_width = 0.2,
  grid_minor_width = 0.15,
  plot_margin = ggplot2::margin(0, 0, 0, 0),
  panel_spacing = grid::unit(2, "lines")
)

Arguments

base_family

The font family for all text, including geom labels. The default is the free Hanken Grotesk; any installed family works, for example "Aktiv Grotesk". See check_maison_fonts().

base_size

Base font size in points; axis text is drawn at this size.

grid

Which grid lines to draw: "X" and "Y" for major lines, "x" and "y" for minor lines, in any combination, or "" for none. TRUE means "XY" and FALSE means none.

axis

Which axis lines to draw: TRUE, FALSE, or "x", "y" or "xy".

dark

TRUE draws on charcoal with warm_white text, for charts on dark slides.

void

TRUE removes the axes, axis text, axis titles and grid lines, for donuts and other axis-free charts. Titles, legend and caption keep the house type scale.

legend_position

Where the legend goes: "top" (the house default), "bottom", "left", "right", "inside" or "none". The legend is set flush left with the plot edge, like the title, and has no title.

legend_location

What a legend above or below the chart lines up with: "plot" (the default) is the plot edge, where the title starts; "panel" is the edge of the panel, where the bars start.

background

The background color. NULL (the default) is warm_white, or charcoal when dark = TRUE. "transparent" makes the plot, panel and legend backgrounds transparent. Any other color is used as given. Text stays ink, or warm_white when dark = TRUE.

fallback

What to do when base_family is not available. TRUE (the default) draws in "sans" instead; FALSE keeps base_family. Either way there is one warning per session.

plot_title_size, plot_title_face, plot_title_margin

Title size, face and the space below it, in points.

subtitle_size, subtitle_face, subtitle_margin

The same for the subtitle.

strip_text_size, strip_text_face

Facet strip text.

axis_text_size

Axis text size.

axis_title_size, axis_title_face

Axis titles.

caption_size, caption_face, caption_margin

Caption size, face and the space above it.

label_size

Size in points of text drawn by geom_text() and geom_label().

grid_major_width, grid_minor_width

Grid line widths.

plot_margin

Margin around the whole plot, from ggplot2::margin(). None by default, so the chart's edges line up with what is beside it; ggplot2::margin(10, 10, 10, 10) gives the usual breathing room.

panel_spacing

Space between facet panels.

Value

A complete ggplot2 theme.

What travels with the theme

  • Geom defaults. geom_text() and geom_label() use the base family and the text color at label_size; bars, points, lines and segments are plum. The chart types below have house defaults too. An explicit argument such as geom_col(fill = ) still wins.

  • Palettes. Discrete fills and colors use the categorical palette, and continuous ones the seq_purple ramp, with no scale_*() call. The categorical palette stops at eight groups. With dark = TRUE it is categorical_dark, the six colors that stay readable on charcoal; see maison_pal().

  • Ordered factors are the exception. ggplot2 does not apply theme palettes to them, so Likert charts need scale_fill_maison_likert().

House defaults by chart type

GeomsDefault
geom_hline(), geom_vline(), geom_abline()reference lines: thin, dashed, mid-gray, quieter than the data
geom_rect(), annotate("rect")shaded periods: a light neutral fill with no outline. Put the layer before the data so it sits behind
geom_boxplot()a light plum fill with a hairline outline in the text color
geom_errorbar(), geom_linerange(), geom_pointrange()thin, in the text color
geom_ribbon(), geom_area(), geom_density()a translucent plum fill with no outline
geom_smooth()a line in the text color over a light band
geom_segment(), geom_curve()plum, like geom_line(), so dumbbells match line charts
geom_tile()plum, like bars, when fill is not mapped

With dark = TRUE, plum becomes mauve and the text color is warm_white.

Four things a theme cannot set, so they stay arguments:

  • Boxplot outliers are a layer parameter: geom_boxplot(outliers = FALSE) hides them.

  • Error bar caps come from the width aesthetic: geom_errorbar(width = 0) removes them.

  • Translucency of mapped fills. A theme has no alpha, so the translucent fill applies only when fill is not mapped. With aes(fill = ), add alpha = 0.35 to the layer.

  • annotate("segment") is the same geom as geom_segment(), so it takes the plum line default. For a reference segment, pass linetype = "dashed" and a quiet color such as maison_colors[["mauve"]].

A label for a shaded period is an ordinary annotate("text"); make it small and quiet with size = 9 / .pt and colour = maison_colors[["mauve"]].

Horizontal bars

A horizontal chart needs grid = "X". The default, grid = "Y", draws horizontal grid lines, which suit vertical bars and lines over time. When the values run along the x axis, as with geom_col(aes(value, category)) or coord_flip(), the default lines fall between the bars and say nothing: use theme_maison(grid = "X"). With coord_flip() the letters name the axes as drawn, so it is still "X".

Axis-free charts

void = TRUE is for donuts, maps and other charts with no axes. It removes the axis text, axis titles, axis lines and grid lines, whatever grid and axis say, and keeps the title, subtitle, caption, legend and facet strips on the house type scale.

ggrepel

ggrepel::geom_text_repel() and ggrepel::geom_label_repel() do not read theme defaults (as of ggrepel 0.9.8): they draw black text in the device's default font at their own size. Pass the house values to the layer:

ggrepel::geom_text_repel(
  family = "Hanken Grotesk",
  colour = maison_colors[["ink"]],
  size = 11.5 / ggplot2::.pt
)

For geom_label_repel() add fill = maison_colors[["warm_white"]]. On a dark chart swap ink for warm_white and warm_white for charcoal.

patchwork

A patchwork's own title, subtitle and caption, set with patchwork::plot_annotation(), take their style from the session's default theme, not from the themes of the plots inside. After set_maison() they match with no further code. Otherwise pass the theme to the annotation, and to every panel with &:

(p1 | p2) +
  patchwork::plot_annotation(title = "One title for both") &
  theme_maison()

The zero plot margin means side-by-side panels touch. patchwork has no gap setting of its own, so give each panel some room with & theme(plot.margin = ggplot2::margin(r = 12)), or put patchwork::plot_spacer() between them.

Type scale

The scale is hrbrthemes' theme_ipsum(): an 18 pt bold title flush with the plot edge, a 12 pt subtitle, 11.5 pt axis text, 9 pt axis titles set at the axis ends, and a 9 pt italic caption at the right. Every value is an argument.

Legend

The legend sits above the chart, flush left with the plot edge, and has no title: the chart's title or subtitle says what the colors mean. Move it with legend_position; to bring a title back, add theme(legend.title = element_text()).

When a chart has long labels on the y axis, as a Likert stack with one row per statement does, the plot edge is a long way left of the bars. legend_location = "panel" starts the legend at the panel's left edge. Bars start exactly there when the x scale has no expansion: scale_x_continuous(expand = c(0, 0)). A legend wider than the panel is centered on it. The title and subtitle stay flush with the plot edge.

Margins and background

The plot has no outer margin, so a chart's edges line up with whatever it is placed beside on a slide or page. Text that reaches past the panel can then be cut off at the plot edge. The usual case is the last x-axis label when it sits on or near the end of the axis, as with expand = c(0, 0), wide labels such as "100%", or a narrow chart. Give that chart some room: theme_maison(plot_margin = ggplot2::margin(r = 12)).

The background is warm_white, or charcoal with dark = TRUE. background = "transparent" removes it, so the chart sits on any slide color; the device must support transparency, as ragg::agg_png() does with background = "transparent" (in knitr, dev.args = list(bg = "transparent")).

Missing fonts

When base_family is not available in the session, the theme warns once per session, with install guidance, and falls back to "sans". Without the fallback, grid warns about the missing family for every piece of text it draws. fallback = FALSE keeps the requested family regardless.

See also

set_maison() to make this the default for a document.

Examples

library(ggplot2)
p <- ggplot(mpg, aes(class, fill = drv)) +
  geom_bar() +
  labs(title = "Cars by class", subtitle = "Colored by drive train")

# base_family = "sans" keeps the examples independent of installed fonts
p + theme_maison(base_family = "sans")

p + theme_maison(base_family = "sans", dark = TRUE, grid = "XY")

p + theme_maison(base_family = "sans", background = "transparent")


# horizontal bars need grid = "X"
ggplot(mpg, aes(y = class)) +
  geom_bar() +
  theme_maison(base_family = "sans", grid = "X")


# an axis-free chart: a donut
ggplot(mpg, aes(x = 2, fill = drv)) +
  geom_bar(width = 1) +
  coord_polar(theta = "y") +
  xlim(0.5, 2.5) +
  theme_maison(base_family = "sans", void = TRUE)