Control the non-data look of a plot. theme_gray() is the default (grey panel,
white gridlines); theme_minimal() drops the panel fill for light gridlines on
the page; theme_bw() is a white panel with light grey gridlines;
theme_classic() has axis lines and no gridlines; theme_void() strips
everything but the marks, legend, and titles, with no plot margin (as in
ggplot2); theme_cyberpunk() is a dark
neon theme (see Details).
Usage
theme_gray(plot, base_size = 11, base_family = "")
theme_minimal(plot, base_size = 11, base_family = "")
theme_bw(plot, base_size = 11, base_family = "")
theme_classic(plot, base_size = 11, base_family = "")
theme_void(plot, base_size = 11, base_family = "")
theme_light(plot, base_size = 11, base_family = "")
theme_dark(plot, base_size = 11, base_family = "")
theme_linedraw(plot, base_size = 11, base_family = "")
theme_cyberpunk(plot, base_size = 11, base_family = "")
theme(plot, ...)
set_theme(
plot,
panel_bg = NULL,
grid_col = NULL,
label_col = NULL,
strip_bg = NULL
)Arguments
- plot
A PlotSpec.
theme()also accepts aPlotComposition, setting the figure-level chrome (title bands, collected legend, panel spacing, tags).- base_size
Base text size in points (default 11). Every text element is sized relative to it, so
theme_gray(base_size = 14)scales titles, axis text, legend text and strips together.- base_family
Base font family for all text;
""(default) keeps the system default.- ...
Named theme elements, e.g.
plot.title = element_text(size = 16),panel.grid.minor = element_blank(), or settings likelegend.position, one of"right"(default),"left","top","bottom","none", or"inside". An inside legend sits over the panels atlegend.position.inside = c(x, y)(fractions of the panel area; the olderlegend.position = c(x, y)works too), itslegend.justificationpoint (c(x, y)or words such asc("right", "top"), defaulting to the position) on that spot. Legends drawn beside each facet panel (guide_legend(position = "panel")) sit on the sidelegend.positionnames, justified along the panel edge bylegend.justification(e.g."top"aligns a legend right of a panel with the panel's top).geom = element_geom(ink, paper, accent)sets the default colours of unmapped marks (seeelement_geom()). Legend geometry is tunable vialegend.key.size(key/swatch side, mm),legend.key.point.min(the smallest radius, mm, a point key of a layer with a constantsizeis drawn at, default 1 – an unsized point's radius – so tiny points keep readable keys; a size legend keeps its mapped sizes),legend.spacing(gap between stacked guides, mm), andlegend.margin(inset around the legend block, one or four millimetres,t, r, b, l).- panel_bg, grid_col, label_col, strip_bg
Colours (or
NAto draw nothing) for the panel background, gridlines, axis-label/legend text, and facet strip background.
Value
The modified PlotSpec.
Details
theme() overrides individual elements on top of the current theme using
element_text() / element_line() / element_rect() / element_blank().
set_theme() is a small back-compatible shortcut for the most common colours.
theme_cyberpunk() sets a dark canvas with dim neon gridlines and a bright
neon default palette (both discrete and continuous), in the spirit of
mplcyberpunk. It pairs with the
glow() layer effect and linear_gradient() fills for the full neon look;
the palette is only a default, so scale_* overrides still win. Unmapped
marks draw in the light foreground colour (element_geom(ink = "#c7d0f0")),
with smooths and contours in neon cyan.
Examples
vplot(mtcars) |> mark_point(x = wt, y = mpg) |> theme_minimal()
vplot(mtcars) |>
mark_point(x = wt, y = mpg) |>
theme(panel.grid.minor = element_blank(), legend.position = "none")
# a legend tucked into the top-right corner of the panel
vplot(mtcars) |>
mark_point(x = wt, y = mpg, color = factor(cyl)) |>
theme(legend.position = "inside", legend.justification = c(1, 1))
