Configures the global ggplot2 theme, color palette, font, and base R
par() settings in a single call. Two themes are available:
"text2map" (default, white background, Urban Institute-inspired) and
"solaris" (cream background, warm grid lines). Four palettes are
available: "viridis" (default), "inferno", "grayscale",
and "solaris". Theme and palette can be combined independently.
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.
Usage
set_theme(
base_size = 12,
base_line_size = 0.5,
base_rect_size = 0.5,
panel_spacing = 6,
base_family = "Open Sans",
font_method = "showtext",
set_font = FALSE,
palette = c("viridis", "inferno", "grayscale", "solaris"),
theme = c("text2map", "solaris"),
ggraph = FALSE,
medium = c("screen", "print")
)
scale_colour_discrete(
...,
alpha = 1,
begin = 0,
end = 1,
direction = 1,
option = "D",
aesthetics = "color"
)
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"
)Arguments
- base_size
Numeric. Base font size in points (default
12).- base_line_size
Numeric. Base line size for theme elements (only used with
theme = "text2map").- base_rect_size
Numeric. Base rectangle border size for theme elements (only used with
theme = "text2map").- panel_spacing
Numeric. Spacing between facet panels in points (default
6, only used withtheme = "text2map").- base_family
Character. Base font family.
"Open Sans"(default, bundled),"Lato"(bundled), or"Source Sans 3"(bundled). Ignored whenset_font = FALSE(the default), in which case the system"sans"font is used.- font_method
Character. Font rendering backend:
"showtext"(default, recommended) or"extrafont"(legacy). Only used whenset_font = TRUE.- set_font
Logical. If
TRUE, configure fonts viaset_fonts. Default isFALSE.- palette
Character. Color palette for default discrete and continuous scales. One of
"viridis"(default),"inferno","grayscale", or"solaris".- theme
Character. Theme style:
"text2map"(default) for the Urban Institute-inspired white theme, or"solaris"for the cream-background warm theme. Independent ofpalette.- ggraph
Logical. If
TRUE, sets default aesthetics for ggraph network visualizations. Default isFALSE.- medium
Character. Output medium:
"screen"(default) for presentations and PDF viewing, or"print"for physical printing with heavier lines and darker text.- ...
Other arguments passed on to
discrete_scale,continuous_scale, orbinned_scaleto 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. For example,
aesthetics = c("colour", "fill")applies the same palette to both aesthetics simultaneously.- 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
coloursvector. Seerescale()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.
Value
Invisible NULL. Called for its side effects of setting the
global ggplot2 theme, default geom/stat aesthetics, base R
par(), and the text2map.theme.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". Any Google Font can be loaded when an internet
connection is available. Font rendering uses
showtext (default, recommended) or extrafont (legacy).
Examples
if (FALSE) { # \dontrun{
# Default: text2map theme with viridis 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")
} # }
