gg_theme: Build a ggplot2 Theme Object

View source: R/theme.R

gg_themeR Documentation

Build a ggplot2 Theme Object

Description

Constructs a ggplot2 theme by resolving a base theme, then merging colour and font overrides – exactly mirroring what hd_theme() does for the highcharter backend.

Usage

gg_theme(theme = NULL, colors = NULL, font = NULL)

Arguments

theme

Character name string, ggplot2 theme object, or NULL. NULL reads from getOption("highdir.gg_theme").

colors

Character vector, palette name string, or NULL. Resolved colours are stored on the returned object and applied by ggplot_engine() via scale_color_manual / scale_fill_manual. NULL reads from getOption("highdir.colors").

font

Character or NULL. Font family applied to all text elements via theme(text = element_text(family = font)). NULL reads from getOption("highdir.font").

Details

Priority for each argument:

  • theme: explicit argument > getOption("highdir.gg_theme") > "classic"

  • colors: explicit argument > getOption("highdir.colors") > NULL

  • font: explicit argument > getOption("highdir.font") > NULL

Called automatically inside ggplot_engine(); also useful for applying the package theme to a ggplot built outside highdir.

Built-in name strings and their ggplot2 equivalents:

Name ggplot2 function
"classic" (default) theme_classic()
"minimal" theme_minimal()
"bw" theme_bw()
"light" theme_light()
"dark" theme_dark()
"void" theme_void()
"grey" / "gray" theme_grey()

Value

An object of class "hd_gg_theme" - a list with two fields: ⁠$theme⁠ (a ggplot2 theme object with font baked in) and ⁠$colors⁠ (a resolved character vector or NULL). ggplot_engine() unpacks both. The object can also be added directly to a ggplot with + via the +.gg method (only the theme is applied; colors are handled separately by apply_gg_colors()).

Examples

gg_theme()                                    # session defaults
gg_theme("bw")                                # theme_bw(), session colors/font
gg_theme("classic", colors = c("#025169", "#7C145C"))
gg_theme("minimal", font = "Source Sans Pro")
gg_theme(ggplot2::theme_bw(base_size = 14), font = "mono")


highdir documentation built on July 31, 2026, 5:06 p.m.