Skip to contents

Drop-in replacements for ggplot2's default scale_colour_* and scale_fill_* functions. These scales respect the global palette set by set_theme, dispatching to viridis, inferno, grayscale, or solaris palettes as appropriate. They are registered automatically when the package is loaded and override the ggplot2 defaults.

Configures the global ggplot2 theme, color palette, font, and base R par() settings in a single call. Two themes are available: "solaris" (default, cream background, warm grid lines) and "t2m" (white background, Urban Institute-inspired). Five palettes are available: "solaris" (default), "viridis", "inferno", "grayscale", and "doplar". Theme and palette can be combined independently.

Usage

scale_colour_discrete(
  ...,
  alpha = 1,
  begin = 0,
  end = 1,
  direction = 1,
  option = "D",
  aesthetics = "colour"
)

scale_fill_discrete(
  ...,
  alpha = 1,
  begin = 0,
  end = 1,
  direction = 1,
  option = "D",
  aesthetics = "fill"
)

scale_colour_continuous(
  ...,
  alpha = 1,
  begin = 0,
  end = 1,
  direction = 1,
  option = "D",
  values = NULL,
  space = "Lab",
  na.value = "grey50",
  guide = "colourbar",
  aesthetics = "colour"
)

scale_fill_continuous(
  ...,
  alpha = 1,
  begin = 0,
  end = 1,
  direction = 1,
  option = "D",
  values = NULL,
  space = "Lab",
  na.value = "grey50",
  guide = "colourbar",
  aesthetics = "fill"
)

set_theme(
  base_size = 18,
  base_line_size = NULL,
  base_rect_size = NULL,
  panel_spacing = NULL,
  base_family = "Open Sans",
  set_font = FALSE,
  palette = c("solaris", "viridis", "inferno", "grayscale", "doplar"),
  theme = c("solaris", "t2m"),
  ggraph = FALSE,
  quiet_labels = TRUE,
  medium = c("screen", "print")
)

Arguments

...

Other arguments passed on to discrete_scale, continuous_scale, or binned_scale to control name, limits, breaks, labels, and so forth.

alpha

The alpha transparency, a number in [0,1], see argument alpha in hsv.

begin, end

The (corrected) hue in [0,1] at which the color map begins and ends.

direction

Sets the order of colors in the scale. If 1, the default, colors are ordered from darkest to lightest. If -1, the order of colors is reversed.

option

A character string indicating the color map option to use. Eight options are available:

  • "magma" (or "A")

  • "inferno" (or "B")

  • "plasma" (or "C")

  • "viridis" (or "D")

  • "cividis" (or "E")

  • "rocket" (or "F")

  • "mako" (or "G")

  • "turbo" (or "H")

aesthetics

Character string or vector of character strings listing the name(s) of the aesthetic(s) that this scale works with.

values

if colours should not be evenly positioned along the gradient this vector gives the position (between 0 and 1) for each colour in the colours vector. See rescale() for a convenience function to map an arbitrary range to between 0 and 1.

space

colour space in which to calculate gradient. Must be "Lab" - other values are deprecated.

na.value

Missing values will be replaced with this value.

guide

A function used to create a guide or its name. See guides() for more information.

base_size

Numeric. Base font size in points (default 14).

base_line_size

Deprecated. No longer used; ggplot2 4.0+ computes line sizes from base_size. A warning is issued if supplied.

base_rect_size

Deprecated. No longer used; ggplot2 4.0+ computes rect sizes from base_size. A warning is issued if supplied.

panel_spacing

Deprecated. No longer used as a theme parameter. Use theme(panel.spacing = unit(..., "pt")) directly. A warning is issued if supplied.

base_family

Character. Base font family. "Open Sans" (default, bundled), "Lato" (bundled), or "Source Sans 3" (bundled). Bundled fonts are auto-registered on package load, so set_font = FALSE (the default) still uses the bundled font. Set set_font = TRUE to load a non-bundled Google Font.

set_font

Logical. If TRUE, configure fonts via set_fonts. Default is FALSE, which uses the auto-registered bundled fonts.

palette

Character. Color palette for default discrete and continuous scales. One of "solaris" (default), "viridis", "inferno", "grayscale", or "doplar".

theme

Character. Theme style: "solaris" (default) for the cream-background warm theme, or "t2m" for the Urban Institute-inspired white theme. Independent of palette.

ggraph

Logical. If TRUE, sets default aesthetics for ggraph network visualizations. Default is FALSE.

quiet_labels

Logical. If TRUE (default), configures ggrepel-powered quiet label defaults (themed colors, automatic overlap-hiding) and overrides geom_text() / geom_label() to use ggrepel via geom_qlabel behavior. Set to FALSE to keep ggplot2's original text/label defaults. Use reset_label_defaults() to restore factory settings.

medium

Character. Output medium: "screen" (default) for presentations and PDF viewing, or "print" for physical printing with heavier lines and darker text.

Value

Invisible NULL. Called for its side effects of setting the global ggplot2 theme, default geom/stat aesthetics, base R par(), and the ggastrum.palette option.

Details

Fonts can optionally be configured with set_font = TRUE. Three font families are bundled for offline use: "Open Sans" (default), "Lato", and "Source Sans 3". These bundled fonts are automatically registered when the package is loaded, so plots will use them by default even when set_font = FALSE. Any Google Font can be loaded when an internet connection is available. Font rendering uses showtext.

Author

Dustin Stoltz

Examples

if (FALSE) { # \dontrun{
# Default: solaris theme with solaris palette
set_theme()

# Solaris theme with solaris palette
set_theme(theme = "solaris", palette = "solaris")

# Print-optimized with heavier lines and darker text
set_theme(palette = "grayscale", medium = "print")

# Enable bundled fonts
set_theme(set_font = TRUE, base_family = "Lato")
} # }