| Title: | A Next-Generation Grammar of Graphics |
|---|---|
| Description: | An implementation of the Grammar of Graphics described by Wilkinson (2005, ISBN:978-0-387-24544-7), built on 'S7' classes. The familiar grammar vocabulary of aesthetics, geometries, statistics, scales, coordinates, facets and themes composed with '+' is preserved; every constructor that takes an argument also accepts a plot as the first argument of a native pipe ('|>') stage, so the two styles are interchangeable. The package is extended with built-in interactivity, animation, an exact-data export, a plot linter that flags common statistical-graphics mistakes before a figure ships, and a catalogue covering layout diagrams (Sankey, treemap, network, radar), machine-learning diagnostics (SHAP, receiver operating characteristic, calibration, partial dependence) and clinical reporting (Kaplan-Meier, forest, swimmer, CONSORT). Static output is written to Scalable Vector Graphics; interactive output is a self-contained 'HTML' document using a canvas element and vanilla 'JavaScript'. Both render targets consume the same computed-geometry buffer, giving a single source of truth for layer geometry. Layout and estimation algorithms follow their published descriptions, including Bruls, Huizing and van Wijk (2000) <doi:10.1007/978-3-7091-6783-0_4> for squarified treemaps, Fruchterman and Reingold (1991) <doi:10.1002/spe.4380211102> for force-directed graphs, and Kaplan and Meier (1958) <doi:10.1080/01621459.1958.10501452> for survival curves. |
| Authors: | Mahesh Divakaran [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-3488-0857>, affiliation: Senior Technical Lead - R Developer, Ephicacy LifeScience Analytics Pvt Ltd), Dr. Rasin R S [ctb] (ORCID: <https://orcid.org/0000-0002-8393-5869>, affiliation: Assistant Professor, St. Thomas' College (Autonomous), Thrissur, Kerala, India), Rakesh Poduval [ctb] (affiliation: Data Science Manager, IMMO Information Technology Private Limited) |
| Maintainer: | Mahesh Divakaran <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-09-27 06:57:16 UTC |
| Source: | https://github.com/itsmdivakaran/ggnext |
aes() captures unevaluated expressions that describe how columns of the
data map onto visual properties. The first two unnamed arguments are taken
as x and y. Expressions are evaluated later, against the layer data,
in the environment where aes() was called.
aes(...)aes(...)
... |
Name-value pairs of aesthetics and expressions, e.g.
|
An object of class ggnext_aes.
aes(speed, dist) aes(x = speed, y = dist, color = gear)aes(speed, dist) aes(x = speed, y = dist, color = gear)
Animation is a property of the plot, not a separate verb chain: the same
geometry pipeline runs once per level of by, and the interactive target
plays the resulting frames with a scrubber and play/pause control.
Because frames are ordinary geometry buffers, positions are interpolated
by the player rather than recomputed.
animate(by, duration = 800, easing = "cubic-in-out", loop = TRUE)animate(by, duration = 800, easing = "cubic-in-out", loop = TRUE)
by |
Transition variable: an unquoted column name or a string. |
duration |
Milliseconds per frame. |
easing |
|
loop |
Restart automatically after the last frame. |
Animated plots render to the interactive target (like interact()).
render(p, target = "static") still produces a static SVG of the whole
data, so animation never blocks a static export.
An Animation spec to add to a plot with +.
d <- data.frame( x = rep(1:5, 3), y = c(1:5, (1:5)^1.5, (1:5)^2), step = rep(c(1, 2, 3), each = 5) ) p <- ggnext(d, aes(x, y)) + geom_point(size = 5) + animate(step) html <- render(p)d <- data.frame( x = rep(1:5, 3), y = c(1:5, (1:5)^1.5, (1:5)^2), step = rep(c(1, 2, 3), each = 5) ) p <- ggnext(d, aes(x, y)) + geom_point(size = 5) + animate(step) html <- render(p)
Created by animate(). Frames are computed from the same geometry
pipeline as static output — one buffer per frame value — and the
interactive target plays them with a scrubber.
Animation( var = character(0), duration = integer(0), easing = character(0), loop = logical(0) )Animation( var = character(0), duration = integer(0), easing = character(0), loop = logical(0) )
var |
Name of the transition variable. |
duration |
Milliseconds per frame. |
easing |
Easing curve: |
loop |
Restart automatically at the end. |
An S7 object of class Animation; usually built by animate().
The single seam between the grammar and the renderers. Each geom method
returns a list of marks; a mark is a plain named list with a type field
(currently "circle"; the full catalog will add "rect", "line",
"path", "polygon", "text") plus type-specific fields in normalized
panel coordinates (x/y in [0, 1], y pointing up). Because both render
targets consume marks, adding a geom never touches renderer code, and
adding a renderer never touches geom code.
build_marks(geom, ...)build_marks(geom, ...)
geom |
A Geom subclass instance. |
... |
Method arguments; all methods take |
List of marks.
Renders every gallery example with the package itself and writes a self-contained static site. No external site generator, no CDN assets.
build_site(dir, quiet = FALSE, gallery = TRUE, cookbook = TRUE)build_site(dir, quiet = FALSE, gallery = TRUE, cookbook = TRUE)
dir |
Output directory (created if needed). There is no default — CRAN policy prohibits writing to the user's home filespace by default, so a path must always be supplied explicitly. |
quiet |
Suppress progress messages. |
gallery |
Render the gallery figures. Every example is drawn with
ggnext itself at build time, which is the bulk of the build cost.
Pass |
cookbook |
Also build the Cookbook page by knitting the worked
reference shipped in |
The output directory, invisibly.
# The figures and the cookbook are the slow parts of a real build; this # writes the pages only. For the full site, pass a directory of your # choosing, e.g. build_site("docs"). out <- file.path(tempdir(), "ggnext-site") build_site(out, quiet = TRUE, gallery = FALSE, cookbook = FALSE) list.files(out)# The figures and the cookbook are the slow parts of a real build; this # writes the pages only. For the full site, pass a directory of your # choosing, e.g. build_site("docs"). out <- file.path(tempdir(), "ggnext-site") build_site(out, quiet = TRUE, gallery = FALSE, cookbook = FALSE) list.files(out)
Created by scale_color_manual() / scale_color_gradient().
ColorScale(palette = character(0), name = NULL, type = character(0))ColorScale(palette = character(0), name = NULL, type = character(0))
palette |
Character vector of hex colors (two, for a gradient). |
name |
Optional legend title. |
type |
|
An S7 object of class ColorScale; usually built by scale_color_manual() or scale_color_gradient().
Methods receive values, a named list of evaluated aesthetic vectors,
and return a named list of (possibly transformed) aesthetic vectors.
compute_stat(stat, ...)compute_stat(stat, ...)
stat |
A Stat subclass instance. |
... |
Method arguments; all methods take |
Named list of (possibly transformed) aesthetic vectors.
Base class for coordinate systems. A coord receives positions already normalized to [0, 1] by the scales and returns (possibly transformed) normalized positions. Cartesian is the identity; polar / flipped / 3D coords will override this seam without touching scales or geoms.
Coord(name = character(0))Coord(name = character(0))
name |
Human-readable coord name. |
An S7 object of class Coord, the base class for coordinate systems.
The identity coordinate system.
coord_cartesian(flip = FALSE)coord_cartesian(flip = FALSE)
flip |
Swap the x and y axes (horizontal bars, forest plots). |
A CoordCartesian object to add with +.
Draws the plot with x and y swapped — the usual way to get horizontal bars or a readable categorical axis with long labels.
coord_flip()coord_flip()
A CoordCartesian object to add with +.
d <- data.frame(g = c("alpha", "beta", "gamma"), v = c(3, 7, 5)) ggnext(d, aes(g, v)) + geom_col() + coord_flip()d <- data.frame(g = c("alpha", "beta", "gamma"), v = c(3, 7, 5)) ggnext(d, aes(g, v)) + geom_col() + coord_flip()
Bends the panel into a circle: the theta axis becomes the angle and
the other axis becomes the radius. This is the engine behind radar
charts (geom_radar()), pie/donut wedges, and circular bar charts.
coord_polar(theta = "x", start = 0, direction = 1, inner = 0)coord_polar(theta = "x", start = 0, direction = 1, inner = 0)
theta |
Which axis maps to angle: |
start |
Angle in radians for the first position; |
direction |
|
inner |
Inner radius as a fraction of the outer radius — use e.g.
|
A CoordPolar object to add to a plot with +.
d <- data.frame(g = c("A", "B", "C", "D"), v = c(4, 7, 3, 6)) ggnext(d, aes(g, v)) + geom_col() + coord_polar()d <- data.frame(g = c("A", "B", "C", "D"), v = c(4, 7, 3, 6)) ggnext(d, aes(g, v)) + geom_col() + coord_polar()
Transform normalized positions through a coordinate system
coord_transform(coord, ...)coord_transform(coord, ...)
coord |
A Coord subclass instance. |
... |
Method arguments; all methods take |
List with transformed x and y.
CoordCartesian: the identity coordinate system
CoordCartesian(flip = FALSE)CoordCartesian(flip = FALSE)
flip |
Swap x and y (see |
An S7 object of class CoordCartesian; usually built by coord_cartesian() or coord_flip().
Maps the normalized x axis onto angle and the normalized y axis onto radius, so lines, areas, and points become circular. This is the engine behind radar/spider charts, pie-like wedges, and circular bar charts.
CoordPolar(theta = "x", start = 0, direction = 1, inner = 0)CoordPolar(theta = "x", start = 0, direction = 1, inner = 0)
theta |
Which axis becomes the angle: |
start |
Angle in radians for normalized position 0 (default: 12 o'clock). |
direction |
|
inner |
Inner radius as a fraction of the outer radius (a donut
hole); |
An S7 object of class CoordPolar; usually built by coord_polar().
Base class for faceting. Created by facet_wrap() / facet_grid().
Facet( vars = character(0), ncol = NULL, nrow = NULL, scales = character(0), type = character(0) )Facet( vars = character(0), ncol = NULL, nrow = NULL, scales = character(0), type = character(0) )
vars |
Character vector of faceting variable names. |
ncol, nrow
|
Panel grid shape ( |
scales |
|
type |
|
An S7 object of class Facet; usually built by facet_wrap() or facet_grid().
facet_grid(rows, cols) builds a two-way panel matrix: one row per level
of rows, one column per level of cols.
facet_grid(rows, cols = NULL, scales = "fixed")facet_grid(rows, cols = NULL, scales = "fixed")
rows |
Variable defining the panel rows (unquoted name or string). |
cols |
Variable defining the panel columns; |
scales |
As in |
A Facet object to add to a plot with +.
d <- transform(mtcars, cyl = factor(cyl), am = factor(am)) ggnext(d, aes(disp, mpg)) + geom_point() + facet_grid(am, cyl)d <- transform(mtcars, cyl = factor(cyl), am = factor(am)) ggnext(d, aes(disp, mpg)) + geom_point() + facet_grid(am, cyl)
Splits the data by one or more variables and lays the resulting panels out in a rectangular grid, wrapping to a new row as needed.
facet_wrap(vars, ncol = NULL, nrow = NULL, scales = "fixed")facet_wrap(vars, ncol = NULL, nrow = NULL, scales = "fixed")
vars |
Faceting variables: unquoted names ( |
ncol, nrow
|
Force a panel-grid shape; |
scales |
|
A Facet object to add to a plot with +.
ggnext(iris, aes(Sepal.Length, Sepal.Width)) + geom_point() + facet_wrap(Species)ggnext(iris, aes(Sepal.Length, Sepal.Width)) + geom_point() + facet_wrap(Species)
Base class for geoms. A geom turns scaled (normalized-to-[0, 1])
aesthetic values into a list of render-target-agnostic drawing primitives
("marks"); see build_marks().
Geom(name = character(0), default_params = list(), required_aes = c("x", "y"))Geom(name = character(0), default_params = list(), required_aes = c("x", "y"))
name |
Human-readable geom name. |
default_params |
Named list of default visual parameters, used when neither an aesthetic mapping nor a literal layer parameter supplies a value. |
required_aes |
Aesthetics that must be present (post-stat) for this
geom to draw; defaults to |
An S7 object of class Geom, the base class for geometric layers.
Draws y = intercept + slope * x across the panel. Like geom_hline()
and geom_vline() it ignores the plot's aes(), so it never disturbs
the data mapping.
geom_abline( intercept = 0, slope = 1, color = NULL, linewidth = NULL, alpha = NULL, dash = NULL )geom_abline( intercept = 0, slope = 1, color = NULL, linewidth = NULL, alpha = NULL, dash = NULL )
intercept, slope
|
Line parameters. |
color, linewidth, alpha, dash
|
Appearance. |
A Layer to add with +.
ggnext(cars, aes(speed, dist)) + geom_point() + geom_abline(intercept = 0, slope = 3, dash = "5,4")ggnext(cars, aes(speed, dist)) + geom_point() + geom_abline(intercept = 0, slope = 3, dash = "5,4")
Incidence by preferred term and treatment arm (or severity grade), shaded by rate and annotated with counts.
geom_ae_heatmap(mapping = NULL, data = NULL, label = TRUE, label_size = NULL)geom_ae_heatmap(mapping = NULL, data = NULL, label = TRUE, label_size = NULL)
mapping, data
|
Standard layer overrides. Map the arm/grade to |
label |
Annotate each cell with its value. |
label_size |
Annotation size in px. |
A Layer to add with +.
d <- expand.grid(arm = c("Placebo", "Low", "High"), ae = c("Nausea", "Fatigue", "Headache")) d$pct <- c(5, 12, 22, 8, 15, 26, 3, 6, 11) ggnext(d, aes(arm, ae, size = pct)) + geom_ae_heatmap()d <- expand.grid(arm = c("Placebo", "Low", "High"), ae = c("Nausea", "Fatigue", "Headache")) d$pct <- c(5, 12, 22, 8, 15, 26, 3, 6, 11) ggnext(d, aes(arm, ae, size = pct)) + geom_ae_heatmap()
Tracks the same subjects through an ordered sequence of stages (e.g.
visit 1 category -> visit 2 category -> visit 3 category), unlike
geom_sankey(), which draws a general directed flow graph from an
edge list. Internally it tallies every consecutive-stage transition
and reuses geom_sankey()'s node-stacking and ribbon-path layout.
geom_alluvial( mapping = NULL, data = NULL, alpha = NULL, node_width = NULL, label = TRUE )geom_alluvial( mapping = NULL, data = NULL, alpha = NULL, node_width = NULL, label = TRUE )
mapping, data
|
Standard layer overrides. Map the stage to |
alpha |
Ribbon opacity. |
node_width |
Node bar width as a fraction of the panel. |
label |
Draw node labels. |
A Layer to add with +.
d <- data.frame( subject = rep(1:8, each = 3), visit = rep(c("Baseline", "Week 4", "Week 8"), 8), response = c( "SD", "SD", "PR", "SD", "PR", "PR", "SD", "SD", "SD", "PR", "PR", "CR", "SD", "PR", "PR", "SD", "SD", "PD", "PR", "CR", "CR", "SD", "PD", "PD" ) ) d$visit <- factor(d$visit, levels = c("Baseline", "Week 4", "Week 8")) ggnext(d, aes(x = visit, y = response, group = subject)) + geom_alluvial() + theme_void()d <- data.frame( subject = rep(1:8, each = 3), visit = rep(c("Baseline", "Week 4", "Week 8"), 8), response = c( "SD", "SD", "PR", "SD", "PR", "PR", "SD", "SD", "SD", "PR", "PR", "CR", "SD", "PR", "PR", "SD", "SD", "PD", "PR", "CR", "CR", "SD", "PD", "PD" ) ) d$visit <- factor(d$visit, levels = c("Baseline", "Week 4", "Week 8")) ggnext(d, aes(x = visit, y = response, group = subject)) + geom_alluvial() + theme_void()
Area layer (filled to the zero baseline)
geom_area(mapping = NULL, data = NULL, color = NULL, alpha = NULL)geom_area(mapping = NULL, data = NULL, color = NULL, alpha = NULL)
mapping, data, color, alpha
|
As in |
A Layer.
Counts rows at each x. For pre-computed heights use geom_col().
geom_bar( mapping = NULL, data = NULL, color = NULL, alpha = NULL, width = 0.8, position = "stack" )geom_bar( mapping = NULL, data = NULL, color = NULL, alpha = NULL, width = 0.8, position = "stack" )
mapping, data, color, alpha
|
As in |
width |
Bar width as a fraction of the slot. |
position |
|
A Layer.
Difference against mean for two measurement methods, with the mean bias and 95% limits of agreement drawn as reference lines — the standard method-comparison plot.
geom_bland_altman( mapping = NULL, data = NULL, color = NULL, size = NULL, alpha = NULL )geom_bland_altman( mapping = NULL, data = NULL, color = NULL, size = NULL, alpha = NULL )
mapping, data
|
Standard layer overrides. Map the two methods'
measurements to |
color |
Point color. |
size |
Point radius. |
alpha |
Point opacity. |
A Layer to add with +.
set.seed(1) a <- rnorm(60, 100, 12) d <- data.frame(method_a = a, method_b = a + rnorm(60, 2, 5)) ggnext(d, aes(method_a, method_b)) + geom_bland_altman()set.seed(1) a <- rnorm(60, 100, 12) d <- data.frame(method_a = a, method_b = a + rnorm(60, 2, 5)) ggnext(d, aes(method_a, method_b)) + geom_bland_altman()
Draws nothing. Useful to establish scales without showing data, or as a placeholder in code that conditionally adds a layer.
geom_blank(mapping = NULL, data = NULL)geom_blank(mapping = NULL, data = NULL)
mapping, data
|
Standard layer overrides. |
A Layer to add with +.
ggnext(cars, aes(speed, dist)) + geom_blank()ggnext(cars, aes(speed, dist)) + geom_blank()
Boxplot layer
geom_boxplot( mapping = NULL, data = NULL, color = NULL, alpha = NULL, width = 0.6, coef = 1.5 )geom_boxplot( mapping = NULL, data = NULL, color = NULL, alpha = NULL, width = 0.6, coef = 1.5 )
mapping, data, color, alpha
|
As in |
width |
Box width in x slot units. |
coef |
Whisker length multiplier (Tukey's 1.5 by default). |
A Layer.
Rank trajectories drawn with sigmoid interpolation between periods, so crossings read cleanly instead of as sharp zigzags.
geom_bump( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL, points = TRUE )geom_bump( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL, points = TRUE )
mapping, data
|
Standard layer overrides. Map time to |
color, alpha, linewidth
|
Appearance. |
points |
Draw a marker at each period. |
A Layer to add with +.
d <- data.frame( year = rep(2021:2023, 3), rank = c(1, 2, 3, 2, 1, 1, 3, 3, 2), team = rep(c("A", "B", "C"), each = 3) ) ggnext(d, aes(year, rank, color = team)) + geom_bump() + scale_y_reverse()d <- data.frame( year = rep(2021:2023, 3), rank = c(1, 2, 3, 2, 1, 1, 3, 3, 2), team = rep(c("A", "B", "C"), each = 3) ) ggnext(d, aes(year, rank, color = team)) + geom_bump() + scale_y_reverse()
Bins predicted probabilities and plots the observed event rate in each bin against the mean prediction, with the diagonal marking perfect calibration. Points off the diagonal show over- or under-confidence.
geom_calibration( mapping = NULL, data = NULL, bins = 10, color = NULL, diagonal = TRUE )geom_calibration( mapping = NULL, data = NULL, bins = 10, color = NULL, diagonal = TRUE )
mapping, data
|
Standard layer overrides. Map the predicted
probability to |
bins |
Number of probability bins. |
color |
Curve color. |
diagonal |
Draw the perfect-calibration reference line. |
A Layer to add with +.
set.seed(1) p <- runif(300) d <- data.frame(pred = p, obs = rbinom(300, 1, p^1.3)) ggnext(d, aes(pred, obs)) + geom_calibration()set.seed(1) p <- runif(300) d <- data.frame(pred = p, obs = rbinom(300, 1, p^1.3)) ggnext(d, aes(pred, obs)) + geom_calibration()
Entities sit on a circle; each relationship is a ribbon whose ends are arcs proportional to the flow. Ribbon interiors are quadratic curves pulled toward the circle center.
geom_chord( mapping = NULL, data = NULL, alpha = NULL, label = TRUE, label_size = NULL )geom_chord( mapping = NULL, data = NULL, alpha = NULL, label = TRUE, label_size = NULL )
mapping, data
|
Standard layer overrides. Requires |
alpha |
Ribbon opacity. |
label, label_size
|
Entity labels around the rim. |
A Layer to add with +.
d <- data.frame( from = c("A", "A", "B", "C"), to = c("B", "C", "C", "A"), n = c(5, 3, 7, 2) ) ggnext(d, aes(x = from, xend = to, y = n)) + geom_chord() + theme_void()d <- data.frame( from = c("A", "A", "B", "C"), to = c("B", "C", "C", "A"), n = c(5, 3, 7, 2) ) ggnext(d, aes(x = from, xend = to, y = n)) + geom_chord() + theme_void()
Column chart layer (bar heights from the data)
geom_col( mapping = NULL, data = NULL, color = NULL, alpha = NULL, width = 0.8, position = "stack" )geom_col( mapping = NULL, data = NULL, color = NULL, alpha = NULL, width = 0.8, position = "stack" )
mapping, data, color, alpha
|
As in |
width |
Bar width as a fraction of the slot. |
position |
|
A Layer.
Scatter of two methods' measurements against the identity line, with
Lin's concordance correlation coefficient (CCC) annotated in the
corner. Unlike geom_bland_altman() (difference vs. mean, for spotting
systematic bias), this reads agreement directly off how close the
cloud sits to y = x.
geom_concordance( mapping = NULL, data = NULL, color = NULL, size = NULL, alpha = NULL )geom_concordance( mapping = NULL, data = NULL, color = NULL, size = NULL, alpha = NULL )
mapping, data
|
Standard layer overrides. Map the two methods'
measurements to |
color |
Point color. |
size |
Point radius. |
alpha |
Point opacity. |
A Layer to add with +.
set.seed(1) a <- rnorm(50, 10, 2) d <- data.frame(method1 = a, method2 = a * 0.95 + rnorm(50, 0, 0.5)) ggnext(d, aes(method1, method2)) + geom_concordance()set.seed(1) a <- rnorm(50, 10, 2) d <- data.frame(method1 = a, method2 = a * 0.95 + rnorm(50, 0, 0.5)) ggnext(d, aes(method1, method2)) + geom_concordance()
A tile heatmap of predicted vs actual classes, shaded by row-normalized rate and annotated with counts, so class imbalance does not hide errors.
geom_confusion_matrix( mapping = NULL, data = NULL, normalize = "row", label_size = NULL )geom_confusion_matrix( mapping = NULL, data = NULL, normalize = "row", label_size = NULL )
mapping, data
|
Standard layer overrides. Map the predicted class to
|
normalize |
|
label_size |
Annotation size in px. |
A Layer to add with +.
d <- data.frame( predicted = c("cat", "cat", "dog", "dog", "dog", "cat"), actual = c("cat", "dog", "dog", "dog", "cat", "cat") ) ggnext(d, aes(predicted, actual)) + geom_confusion_matrix()d <- data.frame( predicted = c("cat", "cat", "dog", "dog", "dog", "cat"), actual = c("cat", "dog", "dog", "dog", "cat", "cat") ) ggnext(d, aes(predicted, actual)) + geom_confusion_matrix()
Boxes and arrows tracing participants from screening through analysis, laid out automatically from a stage/count table.
geom_consort(mapping = NULL, data = NULL, box_fill = NULL, label_size = NULL)geom_consort(mapping = NULL, data = NULL, box_fill = NULL, label_size = NULL)
mapping, data
|
Standard layer overrides. Map the stage label to
|
box_fill |
Box fill color. |
label_size |
Text size in px. |
A Layer to add with +.
d <- data.frame( stage = c("Assessed for eligibility", "Randomised", "Received allocation", "Analysed"), n = c(420, 300, 291, 285) ) ggnext(d, aes(label = stage, size = n)) + geom_consort()d <- data.frame( stage = c("Assessed for eligibility", "Randomised", "Received allocation", "Analysed"), n = c(420, 300, 291, 285) ) ggnext(d, aes(label = stage, size = n)) + geom_consort()
All pairwise Pearson correlations among the numeric columns of data,
shaded on a diverging scale (negative to positive) and annotated with
the coefficient. Takes the raw wide data frame directly rather than
through aes(), since the stat needs the whole numeric block at once
to compute pairwise correlations, not row-wise aesthetic vectors — the
same pattern geom_dendrogram() uses.
geom_cor( data, vars = NULL, label = TRUE, label_size = NULL, low = "#C1462F", mid = "#F2F0EA", high = "#12A594" )geom_cor( data, vars = NULL, label = TRUE, label_size = NULL, low = "#C1462F", mid = "#F2F0EA", high = "#12A594" )
data |
A data frame; correlations are computed over its numeric columns. |
vars |
Character vector of numeric columns to include; default all
numeric columns in |
label |
Annotate each cell with its correlation coefficient. |
label_size |
Annotation text size in px. |
low, mid, high
|
Diverging fill colors for correlation -1, 0, +1. |
A Layer to add with +.
ggnext() + geom_cor(mtcars, vars = c("mpg", "cyl", "disp", "hp", "wt")) + labs(title = "Correlation matrix")ggnext() + geom_cor(mtcars, vars = c("mpg", "cyl", "disp", "hp", "wt")) + labs(title = "Correlation matrix")
A scatter where the point area encodes how many observations share that position — the fix for a scatter of rounded or discrete values where overplotting hides the mass.
geom_count(mapping = NULL, data = NULL, color = NULL, alpha = NULL)geom_count(mapping = NULL, data = NULL, color = NULL, alpha = NULL)
mapping, data
|
Standard layer overrides. |
color, alpha
|
Appearance. |
A Layer to add with +.
d <- data.frame(x = c(1, 1, 1, 2, 2, 3), y = c(1, 1, 2, 2, 2, 3)) ggnext(d, aes(x, y)) + geom_count()d <- data.frame(x = c(1, 1, 1, 2, 2, 3), y = c(1, 1, 2, 2, 2, 3)) ggnext(d, aes(x, y)) + geom_count()
A hollow box spanning ymin to ymax with a heavier line at y — the
compact summary used in dose-response and subgroup tables.
geom_crossbar( mapping = NULL, data = NULL, color = NULL, linewidth = NULL, alpha = NULL, width = NULL )geom_crossbar( mapping = NULL, data = NULL, color = NULL, linewidth = NULL, alpha = NULL, width = NULL )
mapping, data
|
Standard layer overrides. Requires |
color, linewidth, alpha
|
Appearance. |
width |
Box width in x-axis units. |
A Layer to add with +.
d <- data.frame(g = c("a", "b"), m = c(2, 3), lo = c(1, 2), hi = c(4, 5)) ggnext(d, aes(g, m, ymin = lo, ymax = hi)) + geom_crossbar()d <- data.frame(g = c("a", "b"), m = c(2, 3), lo = c(1, 2), hi = c(4, 5)) ggnext(d, aes(g, m, ymin = lo, ymax = hi)) + geom_crossbar()
Aalen-Johansen cumulative incidence curves by event type, the correct estimator when competing events make 1 - Kaplan-Meier biased upward.
geom_cuminc(mapping = NULL, data = NULL, linewidth = NULL)geom_cuminc(mapping = NULL, data = NULL, linewidth = NULL)
mapping, data
|
Standard layer overrides. Map follow-up time to
|
linewidth |
Line width. |
A Layer to add with +.
set.seed(1) d <- data.frame( t = rexp(120, 0.1), ev = sample(0:2, 120, replace = TRUE, prob = c(.4, .35, .25)) ) ggnext(d, aes(time = t, status = ev)) + geom_cuminc()set.seed(1) d <- data.frame( t = rexp(120, 0.1), ev = sample(0:2, 120, replace = TRUE, prob = c(.4, .35, .25)) ) ggnext(d, aes(time = t, status = ev)) + geom_cuminc()
A quadratic curve between two points, for annotation leaders and relationship diagrams where a straight segment would overlap the data.
geom_curve( mapping = NULL, data = NULL, curvature = NULL, color = NULL, linewidth = NULL, alpha = NULL )geom_curve( mapping = NULL, data = NULL, curvature = NULL, color = NULL, linewidth = NULL, alpha = NULL )
mapping, data
|
Standard layer overrides. Requires |
curvature |
How far the curve bows; negative bows the other way. |
color, linewidth, alpha
|
Appearance. |
A Layer to add with +.
d <- data.frame(x = 1, y = 1, xe = 3, ye = 3) ggnext(d, aes(x, y, xend = xe, yend = ye)) + geom_curve()d <- data.frame(x = 1, y = 1, xe = 3, ye = 3) ggnext(d, aes(x, y, xend = xe, yend = ye)) + geom_curve()
Shades a grid of predictions to show a two-dimensional classifier's
decision regions; overlay geom_point() for the training data.
geom_decision_boundary(mapping = NULL, data = NULL, alpha = NULL)geom_decision_boundary(mapping = NULL, data = NULL, alpha = NULL)
mapping, data
|
Standard layer overrides. Map the grid coordinates to
|
alpha |
Region opacity. |
A Layer to add with +.
g <- expand.grid(x = seq(0, 1, 0.05), y = seq(0, 1, 0.05)) g$cls <- ifelse(g$x + g$y > 1, "a", "b") ggnext(g, aes(x, y, color = cls)) + geom_decision_boundary()g <- expand.grid(x = seq(0, 1, 0.05), y = seq(0, 1, 0.05)) g$cls <- ifelse(g$x + g$y > 1, "a", "b") ggnext(g, aes(x, y, color = cls)) + geom_decision_boundary()
Runs stats::hclust() (base R, not an added dependency) on the
Euclidean distances between rows of data and draws the merge tree as
the classic bracket shape: two vertical drops joined by one horizontal
bar at the merge height. Takes the raw wide data frame directly (like
geom_cor()), since the layout needs the whole numeric block at once,
not row-wise aesthetics.
geom_dendrogram( data, vars = NULL, method = "complete", color = NULL, linewidth = NULL )geom_dendrogram( data, vars = NULL, method = "complete", color = NULL, linewidth = NULL )
data |
A data frame with one row per observation to cluster. |
vars |
Character vector of numeric columns to cluster on; default
all numeric columns in |
method |
Linkage method, passed to |
color, linewidth
|
Line appearance. |
A Layer to add with +.
ggnext() + geom_dendrogram(mtcars[1:10, c("mpg", "hp", "wt", "qsec")]) + theme_void()ggnext() + geom_dendrogram(mtcars[1:10, c("mpg", "hp", "wt", "qsec")]) + theme_void()
Density curve layer
geom_density( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL, adjust = 1 )geom_density( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL, adjust = 1 )
mapping, data, color, alpha
|
As in |
linewidth |
Curve stroke width. |
adjust |
Bandwidth multiplier. |
A Layer.
A four-parameter log-logistic curve fitted to dose-response data, with a confidence band and the fitted EC50 marked.
geom_dose_response( mapping = NULL, data = NULL, color = NULL, points = TRUE, ec50 = TRUE )geom_dose_response( mapping = NULL, data = NULL, color = NULL, points = TRUE, ec50 = TRUE )
mapping, data
|
Standard layer overrides. Map dose to |
color |
Curve color. |
points |
Draw the observed points. |
ec50 |
Mark the fitted EC50 with a vertical line. |
A Layer to add with +.
d <- data.frame( dose = rep(c(0.1, 1, 10, 100, 1000), each = 3), resp = c(5, 7, 6, 18, 22, 20, 52, 48, 55, 82, 79, 85, 95, 97, 93) ) ggnext(d, aes(dose, resp)) + geom_dose_response() + scale_x_log10()d <- data.frame( dose = rep(c(0.1, 1, 10, 100, 1000), each = 3), resp = c(5, 7, 6, 18, 22, 20, 52, 48, 55, 82, 79, 85, 95, 97, 93) ) ggnext(d, aes(dose, resp)) + geom_dose_response() + scale_x_log10()
A histogram built from one dot per observation, stacked within its bin. Better than bars for small samples, where it shows every data point.
geom_dotplot( mapping = NULL, data = NULL, binwidth = NULL, color = NULL, size = NULL, alpha = NULL )geom_dotplot( mapping = NULL, data = NULL, binwidth = NULL, color = NULL, size = NULL, alpha = NULL )
mapping, data
|
Standard layer overrides. Map the values to |
binwidth |
Bin width in data units. |
color, size, alpha
|
Appearance. |
A Layer to add with +.
ggnext(cars, aes(speed)) + geom_dotplot(binwidth = 2)ggnext(cars, aes(speed)) + geom_dotplot(binwidth = 2)
Map x (start value), xend (end value), and y (category).
geom_dumbbell( mapping = NULL, data = NULL, color = NULL, size = NULL, alpha = NULL, linewidth = NULL, color_start = NULL, color_end = NULL )geom_dumbbell( mapping = NULL, data = NULL, color = NULL, size = NULL, alpha = NULL, linewidth = NULL, color_start = NULL, color_end = NULL )
mapping, data, color, size, alpha
|
As in |
linewidth |
Connector width. |
color_start, color_end
|
Endpoint dot colors. |
A Layer.
A two-dimensional embedding scatter with optional cluster hulls, so cluster shape is visible rather than inferred from point color alone.
geom_embedding( mapping = NULL, data = NULL, hull = TRUE, size = NULL, alpha = NULL )geom_embedding( mapping = NULL, data = NULL, hull = TRUE, size = NULL, alpha = NULL )
mapping, data
|
Standard layer overrides. Map the two embedding
dimensions to |
hull |
Draw a convex hull around each cluster. |
size |
Point radius. |
alpha |
Point opacity. |
A Layer to add with +.
set.seed(1) d <- data.frame( d1 = c(rnorm(30), rnorm(30, 4)), d2 = c(rnorm(30), rnorm(30, 3)), cl = rep(c("a", "b"), each = 30) ) ggnext(d, aes(d1, d2, color = cl)) + geom_embedding()set.seed(1) d <- data.frame( d1 = c(rnorm(30), rnorm(30, 4)), d2 = c(rnorm(30), rnorm(30, 3)), cl = rep(c("a", "b"), each = 30) ) ggnext(d, aes(d1, d2, color = cl)) + geom_embedding()
ymin to ymax with caps)Error bar layer (ymin to ymax with caps)
geom_errorbar( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL, width = NULL )geom_errorbar( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL, width = NULL )
mapping, data, color, alpha
|
As in |
linewidth |
Stroke width. |
width |
Cap width in x data/slot units. |
A Layer.
The horizontal counterpart of geom_errorbar(), for intervals that run
along x — forest plots and tornado charts.
geom_errorbarh( mapping = NULL, data = NULL, color = NULL, linewidth = NULL, alpha = NULL, height = NULL )geom_errorbarh( mapping = NULL, data = NULL, color = NULL, linewidth = NULL, alpha = NULL, height = NULL )
mapping, data
|
Standard layer overrides. Requires |
color, linewidth, alpha
|
Appearance. |
height |
Cap height in y-axis units. |
A Layer to add with +.
d <- data.frame(g = c("a", "b"), lo = c(1, 2), hi = c(4, 5)) ggnext(d, aes(y = g, xmin = lo, xmax = hi)) + geom_errorbarh()d <- data.frame(g = c("a", "b"), lo = c(1, 2), hi = c(4, 5)) ggnext(d, aes(y = g, xmin = lo, xmax = hi)) + geom_errorbarh()
Historical actuals as a solid line, the forecast dashed, and one or two nested confidence ribbons.
geom_forecast_band(mapping = NULL, data = NULL, color = NULL, linewidth = NULL)geom_forecast_band(mapping = NULL, data = NULL, color = NULL, linewidth = NULL)
mapping, data
|
Standard layer overrides. Map time to |
color |
Line color. |
linewidth |
Line width. |
A Layer to add with +.
d <- data.frame( t = 1:10, v = c(1:6, 7, 8, 9, 10), lo = c(rep(NA, 6), 6, 6.5, 7, 7.5), hi = c(rep(NA, 6), 8, 9.5, 11, 12.5), part = rep(c("actual", "forecast"), c(6, 4)) ) ggnext(d, aes(t, v, ymin = lo, ymax = hi, group = part)) + geom_forecast_band()d <- data.frame( t = 1:10, v = c(1:6, 7, 8, 9, 10), lo = c(rep(NA, 6), 6, 6.5, 7, 7.5), hi = c(rep(NA, 6), 8, 9.5, 11, 12.5), part = rep(c("actual", "forecast"), c(6, 4)) ) ggnext(d, aes(t, v, ymin = lo, ymax = hi, group = part)) + geom_forecast_band()
Point estimates with confidence intervals down a category axis, with a
dashed no-effect reference line — the standard display for hazard/odds
ratios, subgroup analyses, and meta-analyses. Marker area encodes study
weight when size is mapped.
geom_forest( mapping = NULL, data = NULL, ref = 1, color = NULL, linewidth = NULL )geom_forest( mapping = NULL, data = NULL, ref = 1, color = NULL, linewidth = NULL )
mapping, data
|
Standard layer overrides. Map the estimate to |
ref |
Reference line position: |
color |
Marker and whisker color. |
linewidth |
Whisker width. |
A Layer to add with +.
d <- data.frame( study = c("Trial A", "Trial B", "Trial C", "Pooled"), hr = c(0.82, 0.71, 0.95, 0.83), lo = c(0.65, 0.52, 0.78, 0.74), hi = c(1.03, 0.97, 1.16, 0.93), weight = c(30, 22, 28, 100) ) ggnext(d, aes(hr, study, ymin = lo, ymax = hi, size = weight)) + geom_forest() + labs(title = "Hazard ratio by trial", x = "Hazard ratio (95% CI)", y = NULL)d <- data.frame( study = c("Trial A", "Trial B", "Trial C", "Pooled"), hr = c(0.82, 0.71, 0.95, 0.83), lo = c(0.65, 0.52, 0.78, 0.74), hi = c(1.03, 0.97, 1.16, 0.93), weight = c(30, 22, 28, 100) ) ggnext(d, aes(hr, study, ymin = lo, ymax = hi, size = weight)) + geom_forest() + labs(title = "Hazard ratio by trial", x = "Hazard ratio (95% CI)", y = NULL)
The same binning as geom_histogram(), drawn as a line through the bin
centres. Easier to overlay across groups than filled bars.
geom_freqpoly( mapping = NULL, data = NULL, bins = 30, binwidth = NULL, color = NULL, linewidth = NULL, alpha = NULL )geom_freqpoly( mapping = NULL, data = NULL, bins = 30, binwidth = NULL, color = NULL, linewidth = NULL, alpha = NULL )
mapping, data
|
Standard layer overrides. |
bins, binwidth
|
Binning, as in |
color, linewidth, alpha
|
Appearance. |
A Layer to add with +.
ggnext(cars, aes(speed)) + geom_freqpoly(bins = 8)ggnext(cars, aes(speed)) + geom_freqpoly(bins = 8)
Evaluates fn over the panel's x range and draws the result. Handy for
overlaying a theoretical density or a reference curve on data.
geom_function( fn, xlim = c(0, 1), n = 101, color = NULL, linewidth = NULL, alpha = NULL )geom_function( fn, xlim = c(0, 1), n = 101, color = NULL, linewidth = NULL, alpha = NULL )
fn |
A function of one numeric argument. |
xlim |
Length-2 range to evaluate over. |
n |
Number of evaluation points. |
color, linewidth, alpha
|
Appearance. |
A Layer to add with +.
ggnext(data.frame(x = c(-3, 3)), aes(x)) + geom_function(dnorm, xlim = c(-3, 3))ggnext(data.frame(x = c(-3, 3)), aes(x)) + geom_function(dnorm, xlim = c(-3, 3))
Horizontally centered bars, one per stage, whose widths are proportional to the value — the standard conversion/drop-off view.
geom_funnel( mapping = NULL, data = NULL, alpha = NULL, label = TRUE, label_size = NULL )geom_funnel( mapping = NULL, data = NULL, alpha = NULL, label = TRUE, label_size = NULL )
mapping, data
|
Standard layer overrides. Map the stage to |
alpha |
Bar opacity. |
label |
Draw the stage label and value inside each bar. |
label_size |
Label size in px. |
A Layer to add with +.
d <- data.frame( stage = factor(c("Visits", "Signups", "Trials", "Paid"), levels = c("Visits", "Signups", "Trials", "Paid")), n = c(10000, 3200, 1100, 420) ) ggnext(d, aes(stage, n, color = stage)) + geom_funnel() + theme_void()d <- data.frame( stage = factor(c("Visits", "Signups", "Trials", "Paid"), levels = c("Visits", "Signups", "Trials", "Paid")), n = c(10000, 3200, 1100, 420) ) ggnext(d, aes(stage, n, color = stage)) + geom_funnel() + theme_void()
Histogram layer
geom_histogram( mapping = NULL, data = NULL, color = NULL, alpha = NULL, bins = 30, binwidth = NULL, position = "stack" )geom_histogram( mapping = NULL, data = NULL, color = NULL, alpha = NULL, bins = 30, binwidth = NULL, position = "stack" )
mapping, data, color, alpha
|
As in |
bins |
Number of bins (ignored when |
binwidth |
Bin width in data units. |
position |
|
A Layer.
Horizontal reference line
geom_hline( yintercept, color = NULL, linewidth = NULL, alpha = NULL, dash = NULL )geom_hline( yintercept, color = NULL, linewidth = NULL, alpha = NULL, dash = NULL )
yintercept |
Numeric vector of y positions. |
color, linewidth, alpha
|
Styling. |
dash |
Dash pattern; defaults to |
A Layer.
Fits a Cox proportional-hazards model from scratch (Newton-Raphson on
the Breslow partial likelihood; see stat_coxph()) and plots the
resulting hazard ratio and Wald 95% CI per group, down a category axis
with a no-effect reference line at HR = 1 — geom_forest() paired with
the Cox engine so the whole model-to-plot pipeline is one call.
geom_hr( mapping = NULL, data = NULL, ref_level = NULL, color = NULL, linewidth = NULL )geom_hr( mapping = NULL, data = NULL, ref_level = NULL, color = NULL, linewidth = NULL )
mapping, data
|
Standard layer overrides. Map |
ref_level |
Reference level for the hazard ratio; |
color |
Marker and whisker color. |
linewidth |
Whisker width. |
A Layer to add with +.
set.seed(1) d <- data.frame( time = c(rexp(60, 0.08), rexp(60, 0.05)), status = rbinom(120, 1, 0.8), arm = rep(c("placebo", "treatment"), each = 60) ) ggnext(d, aes(time = time, status = status, group = arm)) + geom_hr(ref_level = "placebo") + labs(title = "Hazard ratio (Cox model)", x = "Hazard ratio (95% CI)", y = NULL)set.seed(1) d <- data.frame( time = c(rexp(60, 0.08), rexp(60, 0.05)), status = rbinom(120, 1, 0.8), arm = rep(c("placebo", "treatment"), each = 60) ) ggnext(d, aes(time = time, status = status, group = arm)) + geom_hr(ref_level = "placebo") + labs(title = "Hazard ratio (Cox model)", x = "Hazard ratio (95% CI)", y = NULL)
A ranked point-and-whisker plot of feature importance, with optional
whiskers from ymin/ymax (e.g. permutation-importance standard
errors) and a reference line at zero importance. Built on the same
point+whisker rendering as geom_forest().
geom_importance(mapping = NULL, data = NULL, color = NULL, linewidth = NULL)geom_importance(mapping = NULL, data = NULL, color = NULL, linewidth = NULL)
mapping, data
|
Standard layer overrides. Map the importance value
to |
color |
Marker and whisker color. |
linewidth |
Whisker width. |
A discrete axis otherwise sorts alphabetically; pass y as a factor
already ordered by importance (ascending, since the first level sits
at the panel's bottom) to get the classic "most important at the top"
layout — the same convention geom_waterfall() uses for category
order.
A Layer to add with +.
d <- data.frame( feature = c("age", "income", "tenure", "region"), imp = c(0.42, 0.31, 0.18, 0.05), se = c(0.05, 0.04, 0.03, 0.02) ) d$feature <- factor(d$feature, levels = d$feature[order(d$imp)]) ggnext(d, aes(imp, feature, ymin = imp - se, ymax = imp + se)) + geom_importance() + labs(title = "Permutation importance", x = "Importance", y = NULL)d <- data.frame( feature = c("age", "income", "tenure", "region"), imp = c(0.42, 0.31, 0.18, 0.05), se = c(0.05, 0.04, 0.03, 0.02) ) d$feature <- factor(d$feature, levels = d$feature[order(d$imp)]) ggnext(d, aes(imp, feature, ymin = imp - se, ymax = imp + se)) + geom_importance() + labs(title = "Permutation importance", x = "Importance", y = NULL)
geom_point() with uniform positional noise; deterministic per seed.
geom_jitter( mapping = NULL, data = NULL, color = NULL, size = NULL, alpha = NULL, width = NULL, height = NULL, seed = 42 )geom_jitter( mapping = NULL, data = NULL, color = NULL, size = NULL, alpha = NULL, width = NULL, height = NULL, seed = 42 )
mapping, data, color, size, alpha
|
As in |
width, height
|
Jitter half-ranges in data units. |
seed |
RNG seed. |
A Layer.
Map time and status (1/TRUE = event, 0/FALSE = censored); map
color to compare groups. Pair with geom_km_risktable() for the
classic number-at-risk strip.
geom_km( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL, conf_int = FALSE )geom_km( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL, conf_int = FALSE )
mapping, data, color, alpha
|
As in |
linewidth |
Curve width. |
conf_int |
Draw a 95% confidence band (Greenwood's formula, with a log-log transform that keeps the bounds inside [0, 1]). |
A Layer.
set.seed(1) d <- data.frame( t = c(rexp(40, 0.1), rexp(40, 0.07)), ev = rbinom(80, 1, 0.7), arm = rep(c("placebo", "drug"), each = 40) ) ggnext(d, aes(time = t, status = ev, color = arm)) + geom_km(conf_int = TRUE)set.seed(1) d <- data.frame( t = c(rexp(40, 0.1), rexp(40, 0.07)), ev = rbinom(80, 1, 0.7), arm = rep(c("placebo", "drug"), each = 40) ) ggnext(d, aes(time = t, status = ev, color = arm)) + geom_km(conf_int = TRUE)
Draws the classic "number at risk" strip beneath a survival curve: for
each group, the count of subjects still at risk (time >= tick) at a
handful of tick times, laid out as an overlay in the bottom ~18% of the
panel. It is a single layer, not a separate sub-panel — add it
alongside geom_km() on the same plot.
geom_km_risktable( mapping = NULL, data = NULL, breaks = NULL, label_size = NULL )geom_km_risktable( mapping = NULL, data = NULL, breaks = NULL, label_size = NULL )
mapping, data
|
Standard layer overrides. Map |
breaks |
Tick times to report counts at; |
label_size |
Text size in px. |
This layer must share the same time/status/grouping mapping and
data as the geom_km() layer it accompanies, so the two are trained on
the same time domain and its tick columns line up with the curve above
them.
A Layer to add with +.
set.seed(1) d <- data.frame( t = c(rexp(40, 0.1), rexp(40, 0.07)), ev = rbinom(80, 1, 0.7), arm = rep(c("placebo", "drug"), each = 40) ) ggnext(d, aes(time = t, status = ev, color = arm)) + geom_km() + geom_km_risktable()set.seed(1) d <- data.frame( t = c(rexp(40, 0.1), rexp(40, 0.07)), ev = rbinom(80, 1, 0.7), arm = rep(c("placebo", "drug"), each = 40) ) ggnext(d, aes(time = t, status = ev, color = arm)) + geom_km() + geom_km_risktable()
Like geom_text(), but each label sits on an opaque rounded box, so it
stays readable over dense data.
geom_label( mapping = NULL, data = NULL, color = NULL, fill = NULL, size = NULL, alpha = NULL, padding = NULL )geom_label( mapping = NULL, data = NULL, color = NULL, fill = NULL, size = NULL, alpha = NULL, padding = NULL )
mapping, data
|
Standard layer overrides. Requires |
color |
Text and border colour. |
fill |
Plate fill colour. |
size |
Text size in px. |
alpha |
Plate opacity. |
padding |
Plate padding as a fraction of the text size. |
A Layer to add with +.
d <- data.frame(x = c(1, 2), y = c(2, 1), l = c("alpha", "beta")) ggnext(d, aes(x, y, label = l)) + geom_label()d <- data.frame(x = c(1, 2), y = c(2, 1), l = c("alpha", "beta")) ggnext(d, aes(x, y, label = l)) + geom_label()
Training and validation score against training-set size or epoch, the standard read on whether a model is data-limited or over-fitting.
geom_learning_curve( mapping = NULL, data = NULL, band = TRUE, linewidth = NULL, points = TRUE )geom_learning_curve( mapping = NULL, data = NULL, band = TRUE, linewidth = NULL, points = TRUE )
mapping, data
|
Standard layer overrides. Map size/epoch to |
band |
Draw a ribbon between |
linewidth |
Line width. |
points |
Draw markers at each measured point. |
A Layer to add with +.
d <- data.frame( n = rep(c(50, 100, 200, 400), 2), score = c(.75, .82, .86, .88, .70, .78, .83, .86), split = rep(c("train", "validation"), each = 4) ) ggnext(d, aes(n, score, color = split)) + geom_learning_curve()d <- data.frame( n = rep(c(50, 100, 200, 400), 2), score = c(.75, .82, .86, .88, .70, .78, .83, .86), split = rep(c("train", "validation"), each = 4) ) ggnext(d, aes(n, score, color = split)) + geom_learning_curve()
Standardized residual against leverage (hat value), the companion to
geom_residual() for spotting influential observations. Map size to
Cook's distance for the classic three-way read (leverage, residual
size, influence) in one scatter.
geom_leverage( mapping = NULL, data = NULL, color = NULL, size = NULL, alpha = NULL )geom_leverage( mapping = NULL, data = NULL, color = NULL, size = NULL, alpha = NULL )
mapping, data
|
Standard layer overrides. Map leverage to |
color |
Point color. |
size |
Point radius (used when |
alpha |
Point opacity. |
A Layer to add with +.
m <- lm(dist ~ speed, cars) d <- data.frame( hat = hatvalues(m), rstd = rstandard(m), cooksd = cooks.distance(m) ) ggnext(d, aes(hat, rstd, size = cooksd)) + geom_leverage() + labs(title = "Leverage vs standardized residual", x = "Leverage (hat value)", y = "Standardized residual")m <- lm(dist ~ speed, cars) d <- data.frame( hat = hatvalues(m), rstd = rstandard(m), cooksd = cooks.distance(m) ) ggnext(d, aes(hat, rstd, size = cooksd)) + geom_leverage() + labs(title = "Leverage vs standardized residual", x = "Leverage (hat value)", y = "Standardized residual")
Sorts observations by predicted score and plots the cumulative share of positives captured against the share of the population targeted — the standard way to size a marketing or triage cutoff.
geom_lift_gain( mapping = NULL, data = NULL, type = "gain", color = NULL, baseline = TRUE )geom_lift_gain( mapping = NULL, data = NULL, type = "gain", color = NULL, baseline = TRUE )
mapping, data
|
Standard layer overrides. Map the score to |
type |
|
color |
Curve color. |
baseline |
Draw the random-targeting reference. |
A Layer to add with +.
set.seed(1) s <- runif(200) d <- data.frame(score = s, y = rbinom(200, 1, s)) ggnext(d, aes(score = score, truth = y)) + geom_lift_gain()set.seed(1) s <- runif(200) d <- data.frame(score = s, y = rbinom(200, 1, s)) ggnext(d, aes(score = score, truth = y)) + geom_lift_gain()
Line layer (points connected in x order)
geom_line( mapping = NULL, data = NULL, color = NULL, linewidth = NULL, alpha = NULL, dash = NULL )geom_line( mapping = NULL, data = NULL, color = NULL, linewidth = NULL, alpha = NULL, dash = NULL )
mapping, data, color, alpha
|
As in |
linewidth |
Stroke width in px. |
dash |
SVG dash pattern (e.g. |
A Layer.
The interval alone; add geom_point() for an estimate marker, or use
geom_pointrange() which draws both.
geom_linerange( mapping = NULL, data = NULL, color = NULL, linewidth = NULL, alpha = NULL )geom_linerange( mapping = NULL, data = NULL, color = NULL, linewidth = NULL, alpha = NULL )
mapping, data
|
Standard layer overrides. Requires |
color, linewidth, alpha
|
Appearance. |
A Layer to add with +.
d <- data.frame(g = c("a", "b"), lo = c(1, 2), hi = c(4, 5)) ggnext(d, aes(g, ymin = lo, ymax = hi)) + geom_linerange()d <- data.frame(g = c("a", "b"), lo = c(1, 2), hi = c(4, 5)) ggnext(d, aes(g, ymin = lo, ymax = hi)) + geom_linerange()
A tile grid of which variables are observed vs. missing, one row per distinct missingness pattern (most frequent at the top, annotated with how many observations share it) rather than one row per observation — the standard compact view for spotting structured missingness (e.g. a block of variables always missing together).
geom_missing_pattern( data, vars = NULL, label = TRUE, label_size = NULL, observed = "#D8DCE6", missing = "#C1462F" )geom_missing_pattern( data, vars = NULL, label = TRUE, label_size = NULL, observed = "#D8DCE6", missing = "#C1462F" )
data |
A data frame to check for missing values. |
vars |
Character vector of columns to include; default all columns
in |
label |
Annotate missing cells. |
label_size |
Annotation text size in px. |
observed, missing
|
Tile fill colors for observed vs. missing cells. |
A Layer to add with +.
d <- data.frame( age = c(25, NA, 30, 40, NA, 33), bmi = c(22, 24, NA, NA, 27, 23), sbp = c(120, 118, 130, NA, 125, 121) ) ggnext() + geom_missing_pattern(d) + labs(title = "Missing-data patterns")d <- data.frame( age = c(25, NA, 30, 40, NA, 33), bmi = c(22, 24, NA, NA, 27, 23), sbp = c(120, 118, 130, NA, 125, 121) ) ggnext() + geom_missing_pattern(d) + labs(title = "Missing-data patterns")
Map time and status (1/TRUE = event, 0/FALSE = censored) exactly as
for geom_km(); map color to compare groups. The cumulative hazard
H(t) is the additive counterpart of the Kaplan-Meier survival curve —
useful when the rate of events, not the surviving fraction, is what
matters.
geom_nelson_aalen( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL )geom_nelson_aalen( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL )
mapping, data, color, alpha
|
As in |
linewidth |
Curve width. |
A Layer to add with +.
set.seed(1) d <- data.frame(t = rexp(80, 0.08), ev = rbinom(80, 1, 0.75)) ggnext(d, aes(time = t, status = ev)) + geom_nelson_aalen() + labs(title = "Cumulative hazard", x = "Time", y = "H(t)")set.seed(1) d <- data.frame(t = rexp(80, 0.08), ev = rbinom(80, 1, 0.75)) ggnext(d, aes(time = t, status = ev)) + geom_nelson_aalen() + labs(title = "Cumulative hazard", x = "Time", y = "H(t)")
Lays out a graph with a from-scratch Fruchterman-Reingold force
simulation (repulsion between all nodes, attraction along edges, with a
cooling schedule) and draws nodes and edges in one unified grammar —
node and edge aesthetics come from the same aes().
geom_network( mapping = NULL, data = NULL, node_size = NULL, edge_color = NULL, edge_width = NULL, label = TRUE, label_size = NULL, alpha = NULL, iterations = 200, seed = 1 )geom_network( mapping = NULL, data = NULL, node_size = NULL, edge_color = NULL, edge_width = NULL, label = TRUE, label_size = NULL, alpha = NULL, iterations = 200, seed = 1 )
mapping, data
|
Standard layer overrides. Requires |
node_size |
Node radius in px. |
edge_color, edge_width
|
Edge appearance. |
label, label_size
|
Node labels. |
alpha |
Node opacity. |
iterations |
Force-simulation steps; more is slower but tidier. |
seed |
Random seed for the initial layout, so plots reproduce. |
A Layer to add with +.
d <- data.frame( from = c("A", "A", "B", "C", "D", "E"), to = c("B", "C", "C", "D", "E", "A") ) ggnext(d, aes(x = from, xend = to)) + geom_network() + theme_void()d <- data.frame( from = c("A", "A", "B", "C", "D", "E"), to = c("B", "C", "C", "D", "E", "A") ) ggnext(d, aes(x = from, xend = to)) + geom_network() + theme_void()
Each observation is a line crossing one vertical axis per variable — the standard way to eyeball high-dimensional structure and clusters. Each axis is independently rescaled to [0, 1] by the stat, so variables in different units are comparable.
geom_parallel( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL )geom_parallel( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL )
mapping, data
|
Standard layer overrides. Map the variable to |
color, alpha, linewidth
|
Appearance. |
A Layer to add with +.
d <- data.frame( id = rep(1:3, each = 3), var = rep(c("a", "b", "c"), 3), val = c(1, 9, 4, 3, 5, 8, 7, 2, 6) ) ggnext(d, aes(var, val, group = id, color = factor(id))) + geom_parallel()d <- data.frame( id = rep(1:3, each = 3), var = rep(c("a", "b", "c"), 3), val = c(1, 9, 4, 3, 5, 8, 7, 2, 6) ) ggnext(d, aes(var, val, group = id, color = factor(id))) + geom_parallel()
A thick average partial-dependence line over thin per-observation ICE
curves. Map group to the observation id to draw the ICE spaghetti.
geom_partial_dependence( mapping = NULL, data = NULL, color = NULL, ice = TRUE, ice_alpha = 0.25, linewidth = NULL )geom_partial_dependence( mapping = NULL, data = NULL, color = NULL, ice = TRUE, ice_alpha = 0.25, linewidth = NULL )
mapping, data
|
Standard layer overrides. Map the feature to |
color |
Curve color. |
ice |
Draw the individual ICE curves under the average. |
ice_alpha |
Opacity of the ICE curves. |
linewidth |
Width of the average line. |
A Layer to add with +.
d <- data.frame( x = rep(1:10, 5), id = rep(1:5, each = 10), pred = as.vector(sapply(1:5, function(i) (1:10) * 0.1 * i + rnorm(10, 0, .1))) ) ggnext(d, aes(x, pred, group = id)) + geom_partial_dependence()d <- data.frame( x = rep(1:10, 5), id = rep(1:5, each = 10), pred = as.vector(sapply(1:5, function(i) (1:10) * 0.1 * i + rnorm(10, 0, .1))) ) ggnext(d, aes(x, pred, group = id)) + geom_partial_dependence()
Path layer (points connected in data order)
geom_path( mapping = NULL, data = NULL, color = NULL, linewidth = NULL, alpha = NULL, dash = NULL )geom_path( mapping = NULL, data = NULL, color = NULL, linewidth = NULL, alpha = NULL, dash = NULL )
mapping, data, color, alpha
|
As in |
linewidth |
Stroke width in px. |
dash |
SVG dash pattern (e.g. |
A Layer.
Draws a circle mark for each row of the layer data - the default view of a relationship between two continuous variables.
geom_point( mapping = NULL, data = NULL, stat = stat_identity(), color = NULL, size = NULL, alpha = NULL )geom_point( mapping = NULL, data = NULL, stat = stat_identity(), color = NULL, size = NULL, alpha = NULL )
mapping |
Layer-specific aesthetic mapping (optional; merged over the plot-level mapping, layer winning on conflicts). |
data |
Layer-specific data frame (optional). |
stat |
A Stat instance; defaults to |
color |
Literal point color (any R color spec) when |
size |
Literal point radius in pixels when |
alpha |
Point opacity in [0, 1]. |
A Layer object to add to a plot with +.
ggnext(cars, aes(speed, dist)) + geom_point(color = "steelblue", size = 4)ggnext(cars, aes(speed, dist)) + geom_point(color = "steelblue", size = 4)
A horizontal forest plot is this geom with the categorical variable on x
— a dedicated geom_forest() with flipped coordinates is a milestone.
geom_pointrange( mapping = NULL, data = NULL, color = NULL, size = NULL, alpha = NULL, linewidth = NULL )geom_pointrange( mapping = NULL, data = NULL, color = NULL, size = NULL, alpha = NULL, linewidth = NULL )
mapping, data, color, size, alpha
|
As in |
linewidth |
Stroke width. |
A Layer.
Joins the points of each group into a closed shape, in data order. Map
group when the data holds several polygons.
geom_polygon( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL, border = NULL )geom_polygon( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL, border = NULL )
mapping, data
|
Standard layer overrides. |
color |
Fill colour when |
alpha |
Fill opacity. |
linewidth |
Outline width in px; |
border |
Outline colour when |
A Layer to add with +.
d <- data.frame(x = c(1, 3, 2), y = c(1, 1, 3)) ggnext(d, aes(x, y)) + geom_polygon()d <- data.frame(x = c(1, 3, 2), y = c(1, 1, 3)) ggnext(d, aes(x, y)) + geom_polygon()
Sweeps the classification threshold and plots recall (x) against
precision (y), with a horizontal baseline at the class prevalence
(instead of the diagonal geom_roc() uses) — the more informative
curve when positives are rare.
geom_pr( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL )geom_pr( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL )
mapping, data
|
Standard layer overrides. Map |
color, alpha
|
As in |
linewidth |
Curve width. |
A Layer to add with +.
set.seed(1) s <- runif(200) d <- data.frame(truth = rbinom(200, 1, s * 0.3), score = s) ggnext(d, aes(truth = truth, score = score)) + geom_pr()set.seed(1) s <- runif(200) d <- data.frame(truth = rbinom(200, 1, s * 0.3), score = s) ggnext(d, aes(truth = truth, score = score)) + geom_pr()
Sample quantiles against the quantiles of a reference distribution;
points on a straight line mean the sample follows it. Add
geom_qq_line() for the reference.
geom_qq( mapping = NULL, data = NULL, distribution = stats::qnorm, color = NULL, size = NULL, alpha = NULL ) geom_qq_line( mapping = NULL, data = NULL, distribution = stats::qnorm, color = NULL, linewidth = NULL, alpha = NULL )geom_qq( mapping = NULL, data = NULL, distribution = stats::qnorm, color = NULL, size = NULL, alpha = NULL ) geom_qq_line( mapping = NULL, data = NULL, distribution = stats::qnorm, color = NULL, linewidth = NULL, alpha = NULL )
mapping, data
|
Standard layer overrides. Map the values to |
distribution |
Quantile function of the reference distribution (default stats::qnorm). |
color, size, alpha
|
Appearance. |
linewidth |
Line width for the reference line. |
A Layer to add with +.
set.seed(1) d <- data.frame(v = rnorm(100)) ggnext(d, aes(v)) + geom_qq() + geom_qq_line()set.seed(1) d <- data.frame(v = rnorm(100)) ggnext(d, aes(v)) + geom_qq() + geom_qq_line()
Fits a linear model to chosen conditional quantiles, showing how the
spread of y changes with x — not just its mean, as geom_smooth()
does.
geom_quantile( mapping = NULL, data = NULL, quantiles = c(0.25, 0.5, 0.75), linewidth = NULL, alpha = NULL )geom_quantile( mapping = NULL, data = NULL, quantiles = c(0.25, 0.5, 0.75), linewidth = NULL, alpha = NULL )
mapping, data
|
Standard layer overrides. |
quantiles |
Quantiles to fit (default the quartiles). |
linewidth, alpha
|
Appearance. |
A Layer to add with +.
ggnext(cars, aes(speed, dist)) + geom_point(alpha = 0.5) + geom_quantile()ggnext(cars, aes(speed, dist)) + geom_point(alpha = 0.5) + geom_quantile()
Draws one closed polygon per group across a set of categorical axes.
Pair with coord_polar() for the familiar circular form; without it the
same layer reads as a parallel-coordinates profile.
geom_radar( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL, points = TRUE )geom_radar( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL, points = TRUE )
mapping, data
|
Standard layer overrides. Map the axes to |
color |
Line/fill color when |
alpha |
Fill opacity of the polygon interior. |
linewidth |
Outline width in px. |
points |
Draw a marker at each vertex. |
A Layer to add with +.
d <- data.frame( axis = rep(c("Speed", "Power", "Range", "Cost", "Safety"), 2), value = c(8, 6, 7, 4, 9, 5, 9, 4, 8, 6), model = rep(c("A", "B"), each = 5) ) ggnext(d, aes(axis, value, color = model)) + geom_radar() + coord_polar() + theme_minimal()d <- data.frame( axis = rep(c("Speed", "Power", "Range", "Cost", "Safety"), 2), value = c(8, 6, 7, 4, 9, 5, 9, 4, 8, 6), model = rep(c("A", "B"), each = 5) ) ggnext(d, aes(axis, value, color = model)) + geom_radar() + coord_polar() + theme_minimal()
A tile grid drawn without cell borders — the right choice for a dense heatmap or an image, where borders would swamp the data.
geom_raster(mapping = NULL, data = NULL, color = NULL, alpha = NULL)geom_raster(mapping = NULL, data = NULL, color = NULL, alpha = NULL)
mapping, data, color, alpha
|
As in |
A Layer to add with +.
g <- expand.grid(x = 1:20, y = 1:20) g$z <- as.vector(outer(1:20, 1:20, function(a, b) sin(a / 3) * cos(b / 3))) ggnext(g, aes(x, y, color = z)) + geom_raster()g <- expand.grid(x = 1:20, y = 1:20) g$z <- as.vector(outer(1:20, 1:20, function(a, b) sin(a / 3) * cos(b / 3))) ggnext(g, aes(x, y, color = z)) + geom_raster()
Draws an axis-aligned rectangle per row from explicit corners. Use it for
highlight bands, annotation boxes, and any hand-placed block; for a
regular grid shaded by value use geom_tile().
geom_rect( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL, border = NULL )geom_rect( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL, border = NULL )
mapping, data
|
Standard layer overrides. Requires |
color |
Fill colour when |
alpha |
Fill opacity. |
linewidth |
Border width in px; |
border |
Border colour when |
A Layer to add with +.
d <- data.frame(x1 = c(1, 3), x2 = c(2, 5), y1 = c(1, 2), y2 = c(4, 3)) ggnext(d, aes(xmin = x1, xmax = x2, ymin = y1, ymax = y2)) + geom_rect()d <- data.frame(x1 = c(1, 3), x2 = c(2, 5), y1 = c(1, 2), y2 = c(4, 3)) ggnext(d, aes(xmin = x1, xmax = x2, ymin = y1, ymax = y2)) + geom_rect()
Residuals against fitted values with a zero reference line and a loess trend, the first plot to look at when checking a linear model.
geom_residual( mapping = NULL, data = NULL, color = NULL, smooth = TRUE, size = NULL, alpha = NULL )geom_residual( mapping = NULL, data = NULL, color = NULL, smooth = TRUE, size = NULL, alpha = NULL )
mapping, data
|
Standard layer overrides. Map fitted values to |
color |
Point color. |
smooth |
Overlay a loess trend through the residuals. |
size |
Point radius. |
alpha |
Point opacity. |
A Layer to add with +.
m <- lm(dist ~ speed, cars) d <- data.frame(fitted = fitted(m), resid = resid(m)) ggnext(d, aes(fitted, resid)) + geom_residual()m <- lm(dist ~ speed, cars) d <- data.frame(fitted = fitted(m), resid = resid(m)) ggnext(d, aes(fitted, resid)) + geom_residual()
ymin and ymax)Ribbon layer (band between ymin and ymax)
geom_ribbon(mapping = NULL, data = NULL, color = NULL, alpha = NULL)geom_ribbon(mapping = NULL, data = NULL, color = NULL, alpha = NULL)
mapping, data, color, alpha
|
As in |
A Layer.
One density curve per group, offset vertically so distributions can be compared at a glance. Groups are ordered by their factor levels, first level at the bottom.
geom_ridgeline( mapping = NULL, data = NULL, scale = 1.6, color = NULL, alpha = NULL, linewidth = NULL, bw = NULL )geom_ridgeline( mapping = NULL, data = NULL, scale = 1.6, color = NULL, alpha = NULL, linewidth = NULL, bw = NULL )
mapping, data
|
Standard layer overrides. Map the value to |
scale |
Height of each ridge as a multiple of the row spacing; values above 1 make ridges overlap. |
color, alpha, linewidth
|
Appearance. |
bw |
Density bandwidth; |
A Layer to add with +.
ggnext(iris, aes(Sepal.Length, Species)) + geom_ridgeline()ggnext(iris, aes(Sepal.Length, Species)) + geom_ridgeline()
Map truth (actual class; for factors the second level is the positive
class) and score (predicted score); map color to compare models.
geom_roc( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL )geom_roc( mapping = NULL, data = NULL, color = NULL, alpha = NULL, linewidth = NULL )
mapping, data, color, alpha
|
As in |
linewidth |
Curve width. |
A Layer.
A short tick per observation along the panel edges, showing the raw values behind a density, smooth, or scatter.
geom_rug( mapping = NULL, data = NULL, sides = NULL, length = NULL, color = NULL, linewidth = NULL, alpha = NULL )geom_rug( mapping = NULL, data = NULL, sides = NULL, length = NULL, color = NULL, linewidth = NULL, alpha = NULL )
mapping, data
|
Standard layer overrides. |
sides |
Which edges to draw on, as a string of |
length |
Tick length as a fraction of the panel. |
color, linewidth, alpha
|
Appearance. |
A Layer to add with +.
ggnext(cars, aes(speed, dist)) + geom_point() + geom_rug()ggnext(cars, aes(speed, dist)) + geom_point() + geom_rug()
Shows how quantities move between stages. Nodes are drawn as bars at each stage and flows as curved ribbons whose thickness is the value.
geom_sankey( mapping = NULL, data = NULL, alpha = NULL, node_width = NULL, label = TRUE )geom_sankey( mapping = NULL, data = NULL, alpha = NULL, node_width = NULL, label = TRUE )
mapping, data
|
Standard layer overrides. Requires |
alpha |
Ribbon opacity. |
node_width |
Node bar width as a fraction of the panel. |
label |
Draw node labels. |
The layout (node positions, ribbon paths) is computed from scratch: nodes are stacked within their stage in decreasing size, and ribbons leave and enter nodes in the same order, which is what keeps the crossings readable.
A Layer to add with +.
d <- data.frame( from = c("Visited", "Visited", "Signed up", "Signed up"), to = c("Signed up", "Left", "Purchased", "Churned"), n = c(400, 600, 150, 250) ) ggnext(d, aes(x = from, xend = to, y = n)) + geom_sankey() + theme_void()d <- data.frame( from = c("Visited", "Visited", "Signed up", "Signed up"), to = c("Signed up", "Left", "Purchased", "Churned"), n = c(400, 600, 150, 250) ) ggnext(d, aes(x = from, xend = to, y = n)) + geom_sankey() + theme_void()
x,y) to (xend,yend)Segment layer (x,y) to (xend,yend)
geom_segment( mapping = NULL, data = NULL, color = NULL, linewidth = NULL, alpha = NULL )geom_segment( mapping = NULL, data = NULL, color = NULL, linewidth = NULL, alpha = NULL )
mapping, data, color, alpha
|
As in |
linewidth |
Stroke width in px. |
A Layer.
One horizontal swarm per feature showing every observation's SHAP value, with points nudged vertically so overlapping values stay countable. Color the points by the feature value to read the direction of effect.
geom_shap(mapping = NULL, data = NULL, size = NULL, alpha = NULL)geom_shap(mapping = NULL, data = NULL, size = NULL, alpha = NULL)
mapping, data
|
Standard layer overrides. Map the SHAP value to |
size |
Point radius in px. |
alpha |
Point opacity. |
A Layer to add with +.
set.seed(1) d <- data.frame( feature = rep(c("age", "income", "tenure"), each = 40), shap = c(rnorm(40, 0.3, 0.2), rnorm(40, -0.1, 0.3), rnorm(40, 0, 0.15)), value = runif(120) ) ggnext(d, aes(shap, feature, color = value)) + geom_shap() + geom_vline(0, dash = "3,3") + labs(title = "SHAP value by feature", x = "SHAP value", y = NULL)set.seed(1) d <- data.frame( feature = rep(c("age", "income", "tenure"), each = 40), shap = c(rnorm(40, 0.3, 0.2), rnorm(40, -0.1, 0.3), rnorm(40, 0, 0.15)), value = runif(120) ) ggnext(d, aes(shap, feature, color = value)) + geom_shap() + geom_vline(0, dash = "3,3") + labs(title = "SHAP value by feature", x = "SHAP value", y = NULL)
How subjects move between categories from baseline to follow-up (lab grade shifts, response categories), drawn as a counted tile grid.
geom_shift(mapping = NULL, data = NULL, label = TRUE)geom_shift(mapping = NULL, data = NULL, label = TRUE)
mapping, data
|
Standard layer overrides. Map the baseline category
to |
label |
Annotate cells with counts. |
A Layer to add with +.
d <- data.frame( baseline = c("G0", "G0", "G1", "G1", "G2", "G0"), followup = c("G0", "G1", "G1", "G2", "G2", "G0") ) ggnext(d, aes(baseline, followup)) + geom_shift()d <- data.frame( baseline = c("G0", "G0", "G1", "G1", "G2", "G0"), followup = c("G0", "G1", "G1", "G2", "G2", "G0") ) ggnext(d, aes(baseline, followup)) + geom_shift()
Sorted silhouette widths grouped by cluster, with the mean marked — the standard visual check on how well-separated a clustering is.
geom_silhouette(mapping = NULL, data = NULL, alpha = NULL)geom_silhouette(mapping = NULL, data = NULL, alpha = NULL)
mapping, data
|
Standard layer overrides. Map the silhouette width
to |
alpha |
Bar opacity. |
A Layer to add with +.
set.seed(1) d <- data.frame( cluster = rep(c("1", "2", "3"), each = 20), width = c(runif(20, .3, .9), runif(20, .1, .7), runif(20, -.1, .6)) ) ggnext(d, aes(width, cluster, color = cluster)) + geom_silhouette()set.seed(1) d <- data.frame( cluster = rep(c("1", "2", "3"), each = 20), width = c(runif(20, .3, .9), runif(20, .1, .7), runif(20, -.1, .6)) ) ggnext(d, aes(width, cluster, color = cluster)) + geom_silhouette()
The standardized mean difference (Cohen's d) between two groups for each covariate, down a category axis with a reference line at SMD = 0 and a dashed line at the conventional 0.1 "acceptable imbalance" threshold — the standard baseline balance check for a randomized or propensity-matched comparison.
geom_smd(data, group, vars = NULL, threshold = 0.1, color = NULL)geom_smd(data, group, vars = NULL, threshold = 0.1, color = NULL)
data |
A data frame with one row per subject: a two-level |
group |
Name of the two-level grouping column (treatment arm). |
vars |
Character vector of covariate columns; default all numeric
columns other than |
threshold |
Dashed-line threshold in SMD units; |
color |
Marker and whisker color. |
A Layer to add with +.
set.seed(1) d <- data.frame( arm = rep(c("treatment", "control"), each = 50), age = c(rnorm(50, 55, 8), rnorm(50, 58, 9)), bmi = c(rnorm(50, 27, 4), rnorm(50, 27.5, 4)), sbp = c(rnorm(50, 130, 12), rnorm(50, 129, 11)) ) ggnext() + geom_smd(d, group = "arm") + labs(title = "Baseline balance", x = "Standardized mean difference", y = NULL)set.seed(1) d <- data.frame( arm = rep(c("treatment", "control"), each = 50), age = c(rnorm(50, 55, 8), rnorm(50, 58, 9)), bmi = c(rnorm(50, 27, 4), rnorm(50, 27.5, 4)), sbp = c(rnorm(50, 130, 12), rnorm(50, 129, 11)) ) ggnext() + geom_smd(d, group = "arm") + labs(title = "Baseline balance", x = "Standardized mean difference", y = NULL)
Smoothed trend layer
geom_smooth( mapping = NULL, data = NULL, color = NULL, alpha = NULL, method = "loess", se = TRUE, linewidth = NULL, level = 0.95 )geom_smooth( mapping = NULL, data = NULL, color = NULL, alpha = NULL, method = "loess", se = TRUE, linewidth = NULL, level = 0.95 )
mapping, data, color, alpha
|
As in |
method |
|
se |
Draw the confidence band. |
linewidth |
Trend line width. |
level |
Confidence level. |
A Layer.
One thin line per subject with an optional bold group mean overlaid — the standard way to show within-subject change without hiding spread.
geom_spaghetti( mapping = NULL, data = NULL, mean_line = TRUE, alpha = NULL, linewidth = NULL )geom_spaghetti( mapping = NULL, data = NULL, mean_line = TRUE, alpha = NULL, linewidth = NULL )
mapping, data
|
Standard layer overrides. Map time to |
mean_line |
Overlay the group mean trajectory. |
alpha |
Opacity of the individual lines. |
linewidth |
Width of the individual lines. |
A Layer to add with +.
set.seed(1) d <- data.frame( week = rep(0:4, 8), id = rep(1:8, each = 5), score = as.vector(sapply(1:8, function(i) 50 + i + (0:4) * 2 + rnorm(5, 0, 3))) ) ggnext(d, aes(week, score, group = id)) + geom_spaghetti()set.seed(1) d <- data.frame( week = rep(0:4, 8), id = rep(1:8, each = 5), score = as.vector(sapply(1:8, function(i) 50 + i + (0:4) * 2 + rnorm(5, 0, 3))) ) ggnext(d, aes(week, score, group = id)) + geom_spaghetti()
Percent change from baseline over time, one trajectory per subject, with
the +20% (progression) and -30% (response) RECIST thresholds marked.
Distinct from geom_radar(), which is a multivariate star chart.
geom_spider_response( mapping = NULL, data = NULL, thresholds = TRUE, linewidth = NULL, points = TRUE )geom_spider_response( mapping = NULL, data = NULL, thresholds = TRUE, linewidth = NULL, points = TRUE )
mapping, data
|
Standard layer overrides. Map time to |
thresholds |
Draw the RECIST +20% / -30% reference lines. |
linewidth |
Line width. |
points |
Draw a marker at each visit. |
A Layer to add with +.
d <- data.frame( month = rep(c(0, 2, 4, 6), 3), pct = c(0, -20, -35, -40, 0, 10, 25, 40, 0, -5, -10, -8), subject = rep(c("S1", "S2", "S3"), each = 4) ) ggnext(d, aes(month, pct, color = subject)) + geom_spider_response()d <- data.frame( month = rep(c(0, 2, 4, 6), 3), pct = c(0, -20, -35, -40, 0, 10, 25, 40, 0, -5, -10, -8), subject = rep(c("S1", "S2", "S3"), each = 4) ) ggnext(d, aes(month, pct, color = subject)) + geom_spider_response()
A segment from each point at a given angle and radius — the usual way to draw a vector or wind field.
geom_spoke( mapping = NULL, data = NULL, color = NULL, linewidth = NULL, alpha = NULL )geom_spoke( mapping = NULL, data = NULL, color = NULL, linewidth = NULL, alpha = NULL )
mapping, data
|
Standard layer overrides. Requires |
color, linewidth, alpha
|
Appearance. |
A Layer to add with +.
g <- expand.grid(x = 1:5, y = 1:5) g$angle <- atan2(g$y - 3, g$x - 3) g$radius <- 0.4 ggnext(g, aes(x, y, xend = angle, yend = radius)) + geom_spoke()g <- expand.grid(x = 1:5, y = 1:5) g$angle <- atan2(g$y - 3, g$x - 3) g$radius <- 0.4 ggnext(g, aes(x, y, xend = angle, yend = radius)) + geom_spoke()
Step layer (staircase line)
geom_step( mapping = NULL, data = NULL, color = NULL, linewidth = NULL, alpha = NULL, dash = NULL )geom_step( mapping = NULL, data = NULL, color = NULL, linewidth = NULL, alpha = NULL, dash = NULL )
mapping, data, color, alpha
|
As in |
linewidth |
Stroke width in px. |
dash |
SVG dash pattern (e.g. |
A Layer.
Stacked areas centered on a wiggle baseline rather than zero, which keeps every band's thickness readable as it changes over time.
geom_stream(mapping = NULL, data = NULL, alpha = NULL)geom_stream(mapping = NULL, data = NULL, alpha = NULL)
mapping, data
|
Standard layer overrides. Map time to |
alpha |
Band opacity. |
A Layer to add with +.
d <- data.frame( t = rep(1:6, 3), v = c(2, 4, 6, 5, 3, 2, 1, 3, 5, 8, 6, 4, 5, 4, 3, 4, 6, 7), grp = rep(c("a", "b", "c"), each = 6) ) ggnext(d, aes(t, v, color = grp)) + geom_stream() + theme_minimal()d <- data.frame( t = rep(1:6, 3), v = c(2, 4, 6, 5, 3, 2, 1, 3, 5, 8, 6, 4, 5, 4, 3, 4, 6, 7), grp = rep(c("a", "b", "c"), each = 6) ) ggnext(d, aes(t, v, color = grp)) + geom_stream() + theme_minimal()
One horizontal bar per subject showing time on treatment, with optional arrowheads for subjects still ongoing at the data cutoff — the standard patient-level timeline in oncology reporting.
geom_swimmer( mapping = NULL, data = NULL, bar_height = 0.6, arrow = TRUE, alpha = NULL )geom_swimmer( mapping = NULL, data = NULL, bar_height = 0.6, arrow = TRUE, alpha = NULL )
mapping, data
|
Standard layer overrides. Map duration to |
bar_height |
Bar thickness in category-slot units. |
arrow |
Draw arrowheads for ongoing subjects. |
alpha |
Bar opacity. |
A Layer to add with +.
d <- data.frame( subject = paste0("S", 1:6), months = c(4, 9, 14, 6, 20, 11), response = c("PR", "CR", "CR", "SD", "PR", "SD"), ongoing = c(FALSE, FALSE, TRUE, FALSE, TRUE, FALSE) ) ggnext(d, aes(months, subject, color = response, label = ongoing)) + geom_swimmer() + labs(title = "Time on treatment", x = "Months", y = NULL)d <- data.frame( subject = paste0("S", 1:6), months = c(4, 9, 14, 6, 20, 11), response = c("PR", "CR", "CR", "SD", "PR", "SD"), ongoing = c(FALSE, FALSE, TRUE, FALSE, TRUE, FALSE) ) ggnext(d, aes(months, subject, color = response, label = ongoing)) + geom_swimmer() + labs(title = "Time on treatment", x = "Months", y = NULL)
Text label layer
geom_text( mapping = NULL, data = NULL, color = NULL, fontsize = NULL, alpha = NULL, anchor = NULL )geom_text( mapping = NULL, data = NULL, color = NULL, fontsize = NULL, alpha = NULL, anchor = NULL )
mapping, data, color, alpha
|
As in |
fontsize |
Font size in px. |
anchor |
|
A Layer.
Map a continuous color for the classic heatmap look.
geom_tile( mapping = NULL, data = NULL, color = NULL, alpha = NULL, width = NULL, height = NULL )geom_tile( mapping = NULL, data = NULL, color = NULL, alpha = NULL, width = NULL, height = NULL )
mapping, data, color, alpha
|
As in |
width, height
|
Tile size in data units (default: data resolution). |
A Layer.
Area-proportional nested rectangles, laid out with the squarified algorithm (Bruls, Huizing & van Wijk 2000) so tiles stay close to square and stay comparable by area.
geom_treemap( mapping = NULL, data = NULL, alpha = NULL, label = TRUE, label_size = NULL )geom_treemap( mapping = NULL, data = NULL, alpha = NULL, label = TRUE, label_size = NULL )
mapping, data
|
Standard layer overrides. Requires |
alpha |
Tile opacity. |
label |
Draw tile labels where they fit. |
label_size |
Label size in px. |
A Layer to add with +.
d <- data.frame( region = c("North", "South", "East", "West", "Central"), revenue = c(52, 38, 27, 19, 11) ) ggnext(d, aes(size = revenue, label = region, color = region)) + geom_treemap() + theme_void()d <- data.frame( region = c("North", "South", "East", "West", "Central"), revenue = c(52, 38, 27, 19, 11) ) ggnext(d, aes(size = revenue, label = region, color = region)) + geom_treemap() + theme_void()
Replaces unreadable 4+ way Venn diagrams: a bar chart of intersection sizes above a dot matrix showing which sets each bar belongs to.
geom_upset(mapping = NULL, data = NULL, alpha = NULL, dot_size = NULL)geom_upset(mapping = NULL, data = NULL, alpha = NULL, dot_size = NULL)
mapping, data
|
Standard layer overrides. Requires |
alpha |
Bar opacity. |
dot_size |
Membership-dot radius in px. |
A Layer to add with +.
d <- data.frame(sets = c("A", "A&B", "B", "A&B&C", "C", "A&B", "A")) ggnext(d, aes(label = sets)) + geom_upset() + theme_void()d <- data.frame(sets = c("A", "A&B", "B", "A&B&C", "C", "A&B", "A")) ggnext(d, aes(label = sets)) + geom_upset() + theme_void()
Violin layer
geom_violin( mapping = NULL, data = NULL, color = NULL, alpha = NULL, width = 0.9 )geom_violin( mapping = NULL, data = NULL, color = NULL, alpha = NULL, width = 0.9 )
mapping, data, color, alpha
|
As in |
width |
Maximum violin width in x slot units. |
A Layer.
Vertical reference line
geom_vline( xintercept, color = NULL, linewidth = NULL, alpha = NULL, dash = NULL )geom_vline( xintercept, color = NULL, linewidth = NULL, alpha = NULL, dash = NULL )
xintercept |
Numeric vector of x positions. |
color, linewidth, alpha
|
Styling. |
dash |
Dash pattern; defaults to |
A Layer.
Categories plot in level order; pass
x = factor(x, levels = unique(x)) to keep them in data order.
geom_waterfall( mapping = NULL, data = NULL, alpha = NULL, width = 0.8, color_pos = NULL, color_neg = NULL )geom_waterfall( mapping = NULL, data = NULL, alpha = NULL, width = 0.8, color_pos = NULL, color_neg = NULL )
mapping, data, alpha
|
As in |
width |
Bar width in x slot units. |
color_pos, color_neg
|
Bar colors for increases/decreases. |
A Layer.
Subjects ordered by best percent change from baseline, one bar each,
with the +20% / -30% RECIST thresholds marked. Distinct from
geom_waterfall(), which shows a running total.
geom_waterfall_response( mapping = NULL, data = NULL, thresholds = TRUE, alpha = NULL )geom_waterfall_response( mapping = NULL, data = NULL, thresholds = TRUE, alpha = NULL )
mapping, data
|
Standard layer overrides. Map the subject to |
thresholds |
Draw the RECIST reference lines. |
alpha |
Bar opacity. |
A Layer to add with +.
set.seed(1) d <- data.frame( subject = paste0("S", 1:20), pct = sort(runif(20, -75, 45), decreasing = TRUE) ) ggnext(d, aes(subject, pct)) + geom_waterfall_response() + labs(title = "Best response", y = "% change from baseline", x = NULL)set.seed(1) d <- data.frame( subject = paste0("S", 1:20), pct = sort(runif(20, -75, 45), decreasing = TRUE) ) ggnext(d, aes(subject, pct)) + geom_waterfall_response() + labs(title = "Best response", y = "% change from baseline", x = NULL)
The entry point of the grammar: bind a default data frame and a default
aesthetic mapping, then add layers, scales, and coordinate systems with
+.
ggnext(data = NULL, mapping = NULL, width = 640, height = 480)ggnext(data = NULL, mapping = NULL, width = 640, height = 480)
data |
A data frame used by all layers unless a layer overrides it. |
mapping |
Default aesthetic mapping created with |
width, height
|
Device size in pixels (default 640 x 480). |
A GgnextPlot object.
p <- ggnext(cars, aes(speed, dist)) + geom_point() svg <- render(p)p <- ggnext(cars, aes(speed, dist)) + geom_point() svg <- render(p)
Generates the package logo as an SVG: a hexagon containing a small scatter with a fitted trend, drawn with the same coordinate and color machinery the package uses for real plots.
ggnext_logo( file = NULL, width = 520, dark = FALSE, style = c("wordmark", "monogram"), tagline = c("NEXT-GENERATION", "GRAMMAR OF GRAPHICS") )ggnext_logo( file = NULL, width = 520, dark = FALSE, style = c("wordmark", "monogram"), tagline = c("NEXT-GENERATION", "GRAMMAR OF GRAPHICS") )
file |
Output path; |
width |
Sticker width in pixels (height follows the hex ratio). |
dark |
Use the dark palette variant. |
style |
|
tagline |
Text under the wordmark, as one string or a character
vector of lines (two read better than one long line). |
Two styles are available. "wordmark" (the default) spells out
ggnext under the artwork with a tagline; "monogram" sets a large
GG in the middle, which stays legible at favicon and app-icon sizes
where a seven-character wordmark turns to mush.
The SVG document as a length-1 character vector, invisibly when
file is supplied.
svg <- ggnext_logo() substr(svg, 1, 30) # App-icon variant. icon <- ggnext_logo(style = "monogram", width = 256)svg <- ggnext_logo() substr(svg, 1, 30) # App-icon variant. icon <- ggnext_logo(style = "monogram", width = 256)
Built by ggnext() and grown with +. Holds everything needed to
compute geometry; rendering never reaches back past the computed buffer.
GgnextPlot( data = NULL, mapping = NULL, layers = list(), scales = list(), coord = Coord(), interaction = NULL, theme = NULL, labels = NULL, color_scale = NULL, facet = NULL, animation = NULL, size = NULL )GgnextPlot( data = NULL, mapping = NULL, layers = list(), scales = list(), coord = Coord(), interaction = NULL, theme = NULL, labels = NULL, color_scale = NULL, facet = NULL, animation = NULL, size = NULL )
data |
Default data frame for all layers. |
mapping |
Default aesthetic mapping from |
layers |
List of Layer objects. |
scales |
Named list of Scale objects, keyed by aesthetic. |
coord |
A Coord subclass instance. |
interaction |
An Interact spec, or |
theme |
A |
labels |
A |
color_scale |
A ColorScale palette override, or |
facet |
A Facet spec, or |
animation |
An Animation spec, or |
size |
Device size in pixels, |
An S7 object of class GgnextPlot, as returned by ggnext().
Set the plot title (and optionally the subtitle)
ggtitle(label, subtitle = NULL)ggtitle(label, subtitle = NULL)
label |
Title text. |
subtitle |
Optional subtitle text. |
A Labels object to add to a plot with +.
Plots are static-first: render(p) and printing produce a static SVG
image. Adding interact() with + opts the plot into the interactive
HTML/canvas target — render(p) then produces the interactive page
instead (an explicit render(p, target = ) always wins).
Interact(tooltip = NULL, zoom = logical(0), brush = logical(0)) interact(tooltip = TRUE, zoom = TRUE, brush = TRUE)Interact(tooltip = NULL, zoom = logical(0), brush = logical(0)) interact(tooltip = TRUE, zoom = TRUE, brush = TRUE)
tooltip |
|
zoom |
Enable scroll-to-zoom and double-click-to-reset. |
brush |
Enable brush-to-zoom: drag a rectangle on the plot to zoom to it (double-click still resets). |
An Interact spec to add to a plot with +.
p <- ggnext(cars, aes(speed, dist)) + geom_point() render(p) # static SVG pi <- p + interact() # same plot, interactive by default html <- render(pi) # HTML/canvas with tooltip + zoom + brushp <- ggnext(cars, aes(speed, dist)) + geom_point() render(p) # static SVG pi <- p + interact() # same plot, interactive by default html <- render(pi) # HTML/canvas with tooltip + zoom + brush
Created by labs(), ggtitle(), xlab(), ylab(); added with +.
Any field left NULL falls back to the default (for axes, the deparsed
aesthetic mapping).
Labels( title = NULL, subtitle = NULL, caption = NULL, tag = NULL, x = NULL, y = NULL, color = NULL, size = NULL, fill = NULL )Labels( title = NULL, subtitle = NULL, caption = NULL, tag = NULL, x = NULL, y = NULL, color = NULL, size = NULL, fill = NULL )
title, subtitle, caption, tag
|
Plot title block text. |
x, y
|
Axis titles. |
color, size, fill
|
Legend titles. |
An S7 object of class Labels; usually built by labs().
Every argument is optional; only the ones you supply are changed, so
labs() can be added repeatedly to build up a title block.
labs( title = NULL, subtitle = NULL, caption = NULL, tag = NULL, x = NULL, y = NULL, color = NULL, size = NULL, fill = NULL )labs( title = NULL, subtitle = NULL, caption = NULL, tag = NULL, x = NULL, y = NULL, color = NULL, size = NULL, fill = NULL )
title |
Plot title, drawn above the panel. |
subtitle |
Subtitle, drawn under the title in a lighter style. |
caption |
Caption, drawn bottom-right (source notes, methods). |
tag |
Panel tag (e.g. |
x, y
|
Axis titles; override the deparsed |
color, size, fill
|
Legend titles for the matching aesthetic. |
A Labels object to add to a plot with +.
ggnext(cars, aes(speed, dist)) + geom_point() + labs( title = "Stopping distance rises with speed", subtitle = "1920s road tests, 50 observations", x = "Speed (mph)", y = "Stopping distance (ft)", caption = "Source: datasets::cars" )ggnext(cars, aes(speed, dist)) + geom_point() + labs( title = "Stopping distance rises with speed", subtitle = "1920s road tests, 50 observations", x = "Speed (mph)", y = "Stopping distance (ft)", caption = "Source: datasets::cars" )
Layer: one geom + stat + data/mapping overrides
Layer( geom = Geom(), stat = Stat(), mapping = NULL, data = NULL, params = list(), inherit = TRUE )Layer( geom = Geom(), stat = Stat(), mapping = NULL, data = NULL, params = list(), inherit = TRUE )
geom |
A Geom subclass instance. |
stat |
A Stat subclass instance. |
mapping |
Layer-level aesthetic mapping (or |
data |
Layer-level data (or |
params |
Named list of literal visual parameters (e.g. |
inherit |
Whether the layer merges the plot-level mapping into its
own ( |
An S7 object of class Layer, as returned by the geom_*() constructors.
Set both axis limits at once
lims(x = NULL, y = NULL)lims(x = NULL, y = NULL)
x |
Length-2 numeric vector for the x axis, or |
y |
Length-2 numeric vector for the y axis, or |
A list of scales, which + adds one at a time.
A pipe-friendly wrapper around validate_plot(): prints the report as a
side effect and returns plot invisibly, so it can sit inside a pipeline
without interrupting it.
plot_check(plot)plot_check(plot)
plot |
A GgnextPlot object. |
plot, invisibly.
ggnext(cars, aes(speed, dist)) |> geom_point() |> plot_check() |> invisible()ggnext(cars, aes(speed, dist)) |> geom_point() |> plot_check() |> invisible()
Returns the computed values behind each layer — post-stat, post-position,
post-facet — in data units (never normalized coordinates). For a
geom_point() layer that is the x/y you supplied; for geom_histogram()
it is the bin centers, counts, and bin edges actually drawn; for
geom_boxplot() the quartiles and whisker ends.
plot_data(plot, layer = NULL, panel = NULL)plot_data(plot, layer = NULL, panel = NULL)
plot |
A GgnextPlot. |
layer |
Which layer to return: an integer index, or |
panel |
Which facet panel to return: an integer index, |
Only columns the layer genuinely uses are returned. Constant grouping
columns are dropped, so a plot with no group aesthetic has no group
column.
A data frame, or a list of data frames.
p <- ggnext(cars, aes(speed, dist)) + geom_point() head(plot_data(p)) # Stats: what geom_histogram() actually drew. h <- ggnext(cars, aes(speed)) + geom_histogram(bins = 5) plot_data(h) # Facets keep a panel column. f <- ggnext(iris, aes(Sepal.Length, Sepal.Width)) + geom_point() + facet_wrap(Species) head(plot_data(f))p <- ggnext(cars, aes(speed, dist)) + geom_point() head(plot_data(p)) # Stats: what geom_histogram() actually drew. h <- ggnext(cars, aes(speed)) + geom_histogram(bins = 5) plot_data(h) # Facets keep a panel column. f <- ggnext(iris, aes(Sepal.Length, Sepal.Width)) + geom_point() + facet_wrap(Species) head(plot_data(f))
Set the output size
plot_size(width, height)plot_size(width, height)
width, height
|
Device size in pixels. |
A ggnext_size object to add to a plot with +.
ggnext(cars, aes(speed, dist)) + geom_point() + plot_size(900, 600)ggnext(cars, aes(speed, dist)) + geom_point() + plot_size(900, 600)
Computes the plot geometry once and serializes it to the chosen render
target: a standalone SVG document ("static") or a self-contained
interactive HTML page with a <canvas> element, hover tooltips, and
scroll-to-zoom ("interactive").
render(plot, ...)render(plot, ...)
plot |
A GgnextPlot object. |
... |
Method arguments. The GgnextPlot method takes |
The rendered document as a length-1 character vector of class
ggnext_render (printed as a short summary, not the full source),
invisibly when file is given.
p <- ggnext(cars, aes(speed, dist)) + geom_point() svg <- render(p) # static SVG (the default) html <- render(p + interact()) # interactive HTML/canvasp <- ggnext(cars, aes(speed, dist)) + geom_point() svg <- render(p) # static SVG (the default) html <- render(p + interact()) # interactive HTML/canvas
Base class for scales. A scale owns one positional aesthetic, learns its domain from data ("training"), and maps data values onto [0, 1].
Scale(aesthetic = character(0), name = NULL, breaks = NULL, labels = NULL)Scale(aesthetic = character(0), name = NULL, breaks = NULL, labels = NULL)
aesthetic |
Which aesthetic this scale governs ( |
name |
Axis title; |
breaks |
Explicit tick positions, or |
labels |
Explicit tick labels (same length as |
An S7 object of class Scale, the base class for scales.
Compute tick breaks for a trained scale
scale_breaks(scale, ...)scale_breaks(scale, ...)
scale |
A trained Scale subclass instance. |
... |
Method arguments; all methods take |
Numeric vector of tick values in data units.
Set the continuous color gradient
scale_color_gradient(low = "#1A2E59", high = "#5FD0A5", name = NULL)scale_color_gradient(low = "#1A2E59", high = "#5FD0A5", name = NULL)
low, high
|
Gradient endpoint colors. |
name |
Optional legend title. |
A ColorScale object to add with +.
ggnext(iris, aes(Sepal.Length, Sepal.Width, color = Petal.Length)) + geom_point() + scale_color_gradient(low = "#FFF3B0", high = "#9E2A2B")ggnext(iris, aes(Sepal.Length, Sepal.Width, color = Petal.Length)) + geom_point() + scale_color_gradient(low = "#FFF3B0", high = "#9E2A2B")
Overrides the default colorblind-safe palette for discrete color mappings. Levels take colors in order.
scale_color_manual(values, name = NULL)scale_color_manual(values, name = NULL)
values |
Character vector of colors (names or hex). |
name |
Optional legend title. |
A ColorScale object to add with +.
ggnext(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + geom_point() + scale_color_manual(c("#D55E00", "#0072B2", "#009E73"))ggnext(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + geom_point() + scale_color_manual(c("#D55E00", "#0072B2", "#009E73"))
Map data values through a trained scale onto [0, 1]
scale_map(scale, ...)scale_map(scale, ...)
scale |
A trained Scale subclass instance. |
... |
Method arguments; all methods take |
Numeric vector of normalized positions.
Learns the scale's domain (its trained data range). User-supplied
limits win over the data range. Returns an updated scale — S7 objects
are values, so training is a functional update, not a mutation.
scale_train(scale, ...)scale_train(scale, ...)
scale |
A Scale subclass instance. |
... |
Method arguments; all methods take |
The scale, with domain filled in.
Controls the axis title, limits, tick positions, tick labels, the padding around the data, and the axis transform.
scale_x_continuous( name = NULL, limits = NULL, breaks = NULL, labels = NULL, expand = 0.05, trans = "identity" ) scale_y_continuous( name = NULL, limits = NULL, breaks = NULL, labels = NULL, expand = 0.05, trans = "identity" )scale_x_continuous( name = NULL, limits = NULL, breaks = NULL, labels = NULL, expand = 0.05, trans = "identity" ) scale_y_continuous( name = NULL, limits = NULL, breaks = NULL, labels = NULL, expand = 0.05, trans = "identity" )
name |
Axis title (defaults to the mapped expression). |
limits |
Optional numeric length-2 domain; |
breaks |
Explicit tick positions in data units, or |
labels |
Tick labels: a character vector the same length as
|
expand |
Fraction of the data span to pad onto each end of the axis
(default 5%). Use |
trans |
Axis transform: |
A ScaleContinuous object to add with +.
ggnext(cars, aes(speed, dist)) + geom_point() + scale_x_continuous( name = "Speed (mph)", breaks = c(5, 10, 15, 20, 25), expand = 0 ) + scale_y_continuous(labels = function(v) paste0(v, " ft"))ggnext(cars, aes(speed, dist)) + geom_point() + scale_x_continuous( name = "Speed (mph)", breaks = c(5, 10, 15, 20, 25), expand = 0 ) + scale_y_continuous(labels = function(v) paste0(v, " ft"))
Discrete positional scale for the x axis
scale_x_discrete(limits = NULL, name = NULL)scale_x_discrete(limits = NULL, name = NULL)
limits |
Optional character vector fixing the levels and their order. |
name |
Optional axis title. |
A ScaleDiscrete object to add with +.
Shorthand for scale_*_continuous(trans = "log10") / "sqrt".
scale_x_log10( name = NULL, limits = NULL, breaks = NULL, labels = NULL, expand = 0.05 ) scale_y_log10( name = NULL, limits = NULL, breaks = NULL, labels = NULL, expand = 0.05 ) scale_x_sqrt( name = NULL, limits = NULL, breaks = NULL, labels = NULL, expand = 0.05 ) scale_y_sqrt( name = NULL, limits = NULL, breaks = NULL, labels = NULL, expand = 0.05 ) scale_x_reverse( name = NULL, limits = NULL, breaks = NULL, labels = NULL, expand = 0.05 ) scale_y_reverse( name = NULL, limits = NULL, breaks = NULL, labels = NULL, expand = 0.05 )scale_x_log10( name = NULL, limits = NULL, breaks = NULL, labels = NULL, expand = 0.05 ) scale_y_log10( name = NULL, limits = NULL, breaks = NULL, labels = NULL, expand = 0.05 ) scale_x_sqrt( name = NULL, limits = NULL, breaks = NULL, labels = NULL, expand = 0.05 ) scale_y_sqrt( name = NULL, limits = NULL, breaks = NULL, labels = NULL, expand = 0.05 ) scale_x_reverse( name = NULL, limits = NULL, breaks = NULL, labels = NULL, expand = 0.05 ) scale_y_reverse( name = NULL, limits = NULL, breaks = NULL, labels = NULL, expand = 0.05 )
name |
Axis title (defaults to the mapped expression). |
limits |
Optional numeric length-2 domain; |
breaks |
Explicit tick positions in data units, or |
labels |
Tick labels: a character vector the same length as
|
expand |
Fraction of the data span to pad onto each end of the axis
(default 5%). Use |
A ScaleContinuous object to add with +.
d <- data.frame(x = 10^(1:5), y = 1:5) ggnext(d, aes(x, y)) + geom_point() + scale_x_log10()d <- data.frame(x = 10^(1:5), y = 1:5) ggnext(d, aes(x, y)) + geom_point() + scale_x_log10()
Discrete positional scale for the y axis
scale_y_discrete(limits = NULL, name = NULL)scale_y_discrete(limits = NULL, name = NULL)
limits |
Optional character vector fixing the levels and their order. |
name |
Optional axis title. |
A ScaleDiscrete object to add with +.
ScaleContinuous: linear continuous positional scale
ScaleContinuous( aesthetic = "x", limits = NULL, name = NULL, breaks = NULL, labels = NULL, trans = "identity", expand = 0.05 )ScaleContinuous( aesthetic = "x", limits = NULL, name = NULL, breaks = NULL, labels = NULL, trans = "identity", expand = 0.05 )
aesthetic |
|
limits |
Optional numeric length-2 vector fixing the domain; |
name |
Optional axis title. |
breaks |
Explicit tick positions in data units, or |
labels |
Tick labels: a character vector, a function applied to the
break values, or |
trans |
Axis transform: |
expand |
Fraction of the data span padded onto each end of the axis. The |
An S7 object of class ScaleContinuous; usually built by scale_x_continuous() rather than called directly.
Automatically selected when a positional aesthetic maps to character,
factor, or logical data; construct explicitly via scale_x_discrete() /
scale_y_discrete() to fix the level order.
ScaleDiscrete(aesthetic = "x", limits = NULL, name = NULL)ScaleDiscrete(aesthetic = "x", limits = NULL, name = NULL)
aesthetic |
|
limits |
Optional character vector fixing the levels (and their
order); |
name |
Optional axis title. The |
An S7 object of class ScaleDiscrete; usually built by scale_x_discrete() rather than called directly.
Base class for statistical transformations. A stat receives the evaluated aesthetic values and returns (possibly new) values for the geom to draw.
Stat( name = character(0), provides = character(0), discrete_provides = character(0) )Stat( name = character(0), provides = character(0), discrete_provides = character(0) )
name |
Human-readable stat name. |
provides |
Aesthetics this stat computes itself. A geom's required
aesthetics are validated against the user's mapping plus these, so
e.g. |
discrete_provides |
Positional aesthetics ( |
An S7 object of class Stat, the base class for statistical transformations.
Bin observations (histogram counts)
stat_bin(bins = 30, binwidth = NULL)stat_bin(bins = 30, binwidth = NULL)
bins |
Number of bins (ignored when |
binwidth |
Bin width in data units. |
A StatBin object, to pass as a layer's stat.
Five-number summary for boxplots
stat_boxplot(width = 0.6, coef = 1.5)stat_boxplot(width = 0.6, coef = 1.5)
width |
Box width in x slot units. |
coef |
Whisker length multiplier. |
A StatBoxplot object, to pass as a layer's stat.
Count observations at each x
stat_count(width = 0.8)stat_count(width = 0.8)
width |
Bar width as a fraction of the x resolution. |
A StatCount object, to pass as a layer's stat.
Hazard ratios from a Cox proportional-hazards model
stat_coxph(ref_level = NULL)stat_coxph(ref_level = NULL)
ref_level |
Reference level; |
A StatCoxph object, to pass as a layer's stat.
Kernel density estimate
stat_density(n = 256, adjust = 1)stat_density(n = 256, adjust = 1)
n |
Number of evaluation points. |
adjust |
Bandwidth multiplier. |
A StatDensity object, to pass as a layer's stat.
Passes layer data through untransformed. This is the default stat for
geoms that draw the data as given, such as geom_point() and
geom_line().
stat_identity()stat_identity()
A StatIdentity object, to pass as a layer's stat.
Jitter positions for strip charts
stat_jitter(width = NULL, height = NULL, seed = 42)stat_jitter(width = NULL, height = NULL, seed = 42)
width |
Horizontal jitter half-range in data units. |
height |
Vertical jitter half-range. |
seed |
RNG seed (fixed for reproducible renders). |
A StatJitter object, to pass as a layer's stat.
Kaplan-Meier survival estimate
stat_km(conf_int = FALSE)stat_km(conf_int = FALSE)
conf_int |
Compute a 95% confidence band (Greenwood's formula). |
A StatKM object, to pass as a layer's stat.
Number-at-risk table for a Kaplan-Meier curve
stat_km_risktable(breaks = NULL)stat_km_risktable(breaks = NULL)
breaks |
Explicit tick times; |
A StatKMRiskTable object, to pass as a layer's stat.
Nelson-Aalen cumulative hazard estimate
stat_nelson_aalen()stat_nelson_aalen()
A StatNelsonAalen object, to pass as a layer's stat.
Empirical precision-recall curve
stat_pr()stat_pr()
A StatPR object, to pass as a layer's stat.
Empirical ROC curve
stat_roc()stat_roc()
A StatROC object, to pass as a layer's stat.
Fitted trend line with confidence band
stat_smooth(method = "loess", se = TRUE, n = 80, level = 0.95)stat_smooth(method = "loess", se = TRUE, n = 80, level = 0.95)
method |
|
se |
Include the confidence band. |
n |
Number of grid points. |
level |
Confidence level. |
A StatSmooth object, to pass as a layer's stat.
Running totals for waterfall charts
stat_waterfall(width = 0.8)stat_waterfall(width = 0.8)
width |
Bar width in x slot units. |
A StatWaterfall object, to pass as a layer's stat.
Mirrored y-density for violins
stat_ydensity(width = 0.9, n = 101)stat_ydensity(width = 0.9, n = 101)
width |
Maximum violin width in x slot units. |
n |
Number of density evaluation points. |
A StatYdensity object, to pass as a layer's stat.
Overrides individual theme settings. By default the overrides apply to
theme_ggnext(); pass base to restyle a different preset.
Theme( name = character(0), background = character(0), panel_fill = character(0), grid_color = character(0), grid_color_minor = character(0), axis_color = character(0), label_color = character(0), title_color = character(0), subtitle_color = character(0), strip_fill = character(0), strip_color = character(0), legend_text_color = character(0), panel_border = character(0), font = character(0), title_font = character(0), tick_font_size = integer(0), title_font_size = integer(0), plot_title_size = integer(0), plot_subtitle_size = integer(0), caption_size = integer(0), strip_font_size = integer(0), legend_font_size = integer(0), title_face = character(0), tick_len = integer(0), grid_major_x = logical(0), grid_major_y = logical(0), axis_line_x = logical(0), axis_line_y = logical(0), ticks_x = logical(0), ticks_y = logical(0), axis_text_x = logical(0), axis_text_y = logical(0), axis_title_x = logical(0), axis_title_y = logical(0), legend_position = character(0), point_palette = character(0), gradient_low = character(0), gradient_high = character(0) ) theme(..., base = NULL)Theme( name = character(0), background = character(0), panel_fill = character(0), grid_color = character(0), grid_color_minor = character(0), axis_color = character(0), label_color = character(0), title_color = character(0), subtitle_color = character(0), strip_fill = character(0), strip_color = character(0), legend_text_color = character(0), panel_border = character(0), font = character(0), title_font = character(0), tick_font_size = integer(0), title_font_size = integer(0), plot_title_size = integer(0), plot_subtitle_size = integer(0), caption_size = integer(0), strip_font_size = integer(0), legend_font_size = integer(0), title_face = character(0), tick_len = integer(0), grid_major_x = logical(0), grid_major_y = logical(0), axis_line_x = logical(0), axis_line_y = logical(0), ticks_x = logical(0), ticks_y = logical(0), axis_text_x = logical(0), axis_text_y = logical(0), axis_title_x = logical(0), axis_title_y = logical(0), legend_position = character(0), point_palette = character(0), gradient_low = character(0), gradient_high = character(0) ) theme(..., base = NULL)
name |
Preset name (informational). |
background |
Plot background color. |
panel_fill |
Panel (data area) background color. |
grid_color |
Major gridline color; |
grid_color_minor |
Minor gridline color; |
axis_color |
Axis line and tick color. |
label_color |
Tick label and axis title color. |
title_color |
Plot title color. |
subtitle_color |
Subtitle and caption color. |
strip_fill, strip_color
|
Facet strip background and text colors. |
legend_text_color |
Legend label color. |
panel_border |
Panel border color; |
font |
CSS font-family stack used for all text. |
title_font |
Font stack for the plot title; |
tick_font_size |
Tick label size (px). |
title_font_size |
Axis title size (px). |
plot_title_size, plot_subtitle_size, caption_size
|
Title block sizes (px). |
strip_font_size |
Facet strip label size (px). |
legend_font_size |
Legend label size (px). |
title_face |
Plot title weight: |
tick_len |
Tick mark length (px). |
grid_major_x, grid_major_y
|
Draw major gridlines per axis. |
axis_line_x, axis_line_y
|
Draw the axis lines. |
ticks_x, ticks_y
|
Draw tick marks. |
axis_text_x, axis_text_y
|
Draw tick labels. |
axis_title_x, axis_title_y
|
Draw axis titles. |
legend_position |
|
point_palette |
Optional character vector overriding the discrete color palette for this plot. |
gradient_low, gradient_high
|
Optional continuous-gradient endpoints. |
... |
Named Theme properties to override, e.g.
|
base |
A Theme to start from; defaults to |
A Theme to add to a plot with +.
ggnext(cars, aes(speed, dist)) + geom_point() + theme(panel_fill = "#FFF8F0", grid_major_x = FALSE) # Restyle a preset rather than the default. ggnext(cars, aes(speed, dist)) + geom_point() + theme(base = theme_dark(), plot_title_size = 22)ggnext(cars, aes(speed, dist)) + geom_point() + theme(panel_fill = "#FFF8F0", grid_major_x = FALSE) # Restyle a preset rather than the default. ggnext(cars, aes(speed, dist)) + geom_point() + theme(base = theme_dark(), plot_title_size = 22)
The traditional statistical-journal look — axis lines and ticks only.
theme_classic()theme_classic()
A Theme to add to a plot with +.
Dark theme
theme_dark()theme_dark()
A Theme to add to a plot with +.
Light background with a softly tinted panel and white gridlines.
theme_ggnext()theme_ggnext()
A Theme to add to a plot with +.
p <- ggnext(cars, aes(speed, dist)) + geom_point() + theme_dark()p <- ggnext(cars, aes(speed, dist)) + geom_point() + theme_dark()
Minimal theme: no panel fill, light grey gridlines
theme_minimal()theme_minimal()
A Theme to add to a plot with +.
Editorial styling — a large title, hairline horizontal gridlines, no vertical grid or axis lines.
theme_modern()theme_modern()
A Theme to add to a plot with +.
Useful for treemaps, network graphs, and sparkline-style output.
theme_void()theme_void()
A Theme to add to a plot with +.
Runs a small set of rules over a plot's layers and scales - an empty
plot, a continuous geom (geom_point(), geom_line(), ...) mapped to a
categorical y, a mapped aesthetic that is mostly missing, a discrete
color/fill scale with more levels than a legend can usefully show, and a
sqrt-transformed scale fed negative values. Each is a heuristic, not a
guarantee - validate_plot() reports what commonly goes wrong, not what
is definitely wrong with this particular plot.
validate_plot(plot)validate_plot(plot)
plot |
A GgnextPlot object. |
An object of class ggnext_check: a list of findings, each with
rule, status (currently always "warn"), and message. Prints as
a short report; empty when nothing was found.
p <- ggnext(mtcars, aes(mpg, as.character(cyl))) + geom_point() validate_plot(p)p <- ggnext(mtcars, aes(mpg, as.character(cyl))) + geom_point() validate_plot(p)
Convenience wrapper around plot_data() and utils::write.csv() for
publishing the numbers behind a figure next to the figure itself.
write_plot_data(plot, file, layer = NULL)write_plot_data(plot, file, layer = NULL)
plot |
A GgnextPlot. |
file |
Output path. With multiple layers and no |
layer |
Optional layer index (see |
The file path(s) written, invisibly.
p <- ggnext(cars, aes(speed, dist)) + geom_point() out <- file.path(tempdir(), "cars.csv") write_plot_data(p, out)p <- ggnext(cars, aes(speed, dist)) + geom_point() out <- file.path(tempdir(), "cars.csv") write_plot_data(p, out)
Set the x axis title
xlab(label)xlab(label)
label |
Axis title text. |
A Labels object to add to a plot with +.
A shorthand for scale_x_continuous(limits = ). Data outside the limits
is still computed by stats but clipped to the panel when drawn.
xlim(...) ylim(...)xlim(...) ylim(...)
... |
Two numbers giving the lower and upper limit, or one length-2 numeric vector. |
A scale object to add to a plot with +.
ggnext(cars, aes(speed, dist)) + geom_point() + xlim(0, 30) + ylim(0, 150)ggnext(cars, aes(speed, dist)) + geom_point() + xlim(0, 30) + ylim(0, 150)
Set the y axis title
ylab(label)ylab(label)
label |
Axis title text. |
A Labels object to add to a plot with +.