| Title: | Extended Error Geoms for 'ggplot2' |
|---|---|
| Description: | Extends the 'ggplot2' error geoms. geom_error() accepts an error aesthetic with auto-inference of the orientation. It also supports `error_neg` and `error_pos` for asymmetric cases, with full control over aesthetics per side, such as color, width etc... |
| Authors: | Yann Cohen [aut, cre] (ORCID: <https://orcid.org/0009-0009-0509-3609>) |
| Maintainer: | Yann Cohen <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.0 |
| Built: | 2026-05-16 06:04:28 UTC |
| Source: | https://github.com/iamyannc/ggerror |
A thin wrapper around ggplot2::geom_errorbar(),
ggplot2::geom_linerange(), ggplot2::geom_crossbar(), and
ggplot2::geom_pointrange() that accepts a single error aesthetic
and figures out orientation from the data. For asymmetric errors, use
error_neg + error_pos instead of error.
geom_error( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., error_geom = "errorbar", orientation = NA, sign_aware = FALSE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_error_linerange(..., error_geom) geom_error_crossbar(..., error_geom) geom_error_pointrange(..., error_geom)geom_error( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., error_geom = "errorbar", orientation = NA, sign_aware = FALSE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_error_linerange(..., error_geom) geom_error_crossbar(..., error_geom) geom_error_pointrange(..., error_geom)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. |
stat |
The statistical transformation to use on the data. Defaults
to |
position |
Position adjustment. |
... |
Other arguments passed on to |
error_geom |
One of |
orientation |
Either |
sign_aware |
If |
na.rm |
If |
show.legend |
Logical. Should this layer be included in the legends? |
inherit.aes |
If |
Session-level knobs for the 0 -> NA migration. Set via options():
ggerror.silent_zero_warning — TRUE suppresses the soft
deprecation fired when error_neg or error_pos is set to 0 (You are encouraged to set it to NA).
Default FALSE.
ggerror.zero_threshold — Numeric absolute tolerance for zero-value detection.
Values with a magnitude below this threshold are treated as exactly zero,
triggering the warning. Defaults to 1e-8.
geom_error() requires x, y, and one of:
error — symmetric half-width applied along the non-categorical axis.
error_neg and error_pos — asymmetric; the bar extends
error_neg in the negative direction and error_pos in the positive
direction along the non-categorical axis. For a one-sided bar, set
the unused side to NA — the cap, stem, and shared-bound cap on
that side are all suppressed.
Mixing error with error_neg / error_pos is an error, as is
providing only one of the asymmetric pair.
Fixed per-side styling can be supplied through ... with _neg and
_pos suffixes for colour, fill, linewidth, linetype, alpha,
and width.
These are fixed scalar parameters, not mapped aesthetics.
library(ggplot2) ggplot(mtcars, aes(mpg, rownames(mtcars))) + geom_point() + geom_error(aes(error = drat)) ggplot(mtcars, aes(factor(cyl), mpg)) + geom_point() + geom_error(aes(error = drat), error_geom = "pointrange") # Asymmetric: bar extends drat/2 below and drat above each point ggplot(mtcars, aes(mpg, rownames(mtcars))) + geom_point() + geom_error(aes(error_neg = drat / 2, error_pos = drat)) # One-sided: set the unused side to NA (cap + stem auto-suppressed) ggplot(mtcars, aes(mpg, rownames(mtcars))) + geom_point() + geom_error(aes(error_neg = NA, error_pos = drat)) # Summarise raw data: mean +/- SE per group (see also stat_error()) ggplot(mtcars, aes(factor(cyl), mpg)) + geom_error(stat = "error", error_geom = "pointrange") # Signed residual plot: bar extends from fitted toward observed model <- lm(mpg ~ wt, data = mtcars) ggplot(mtcars, aes(fitted(model), mpg)) + geom_point() + geom_error(aes(error = resid(model)), sign_aware = TRUE, orientation = "x") # Style the negative and positive halves separately ggplot(mtcars, aes(mpg, rownames(mtcars))) + geom_point() + geom_error( aes(error_neg = drat / 2, error_pos = drat), colour_neg = "steelblue", colour_pos = "firebrick" )library(ggplot2) ggplot(mtcars, aes(mpg, rownames(mtcars))) + geom_point() + geom_error(aes(error = drat)) ggplot(mtcars, aes(factor(cyl), mpg)) + geom_point() + geom_error(aes(error = drat), error_geom = "pointrange") # Asymmetric: bar extends drat/2 below and drat above each point ggplot(mtcars, aes(mpg, rownames(mtcars))) + geom_point() + geom_error(aes(error_neg = drat / 2, error_pos = drat)) # One-sided: set the unused side to NA (cap + stem auto-suppressed) ggplot(mtcars, aes(mpg, rownames(mtcars))) + geom_point() + geom_error(aes(error_neg = NA, error_pos = drat)) # Summarise raw data: mean +/- SE per group (see also stat_error()) ggplot(mtcars, aes(factor(cyl), mpg)) + geom_error(stat = "error", error_geom = "pointrange") # Signed residual plot: bar extends from fitted toward observed model <- lm(mpg ~ wt, data = mtcars) ggplot(mtcars, aes(fitted(model), mpg)) + geom_point() + geom_error(aes(error = resid(model)), sign_aware = TRUE, orientation = "x") # Style the negative and positive halves separately ggplot(mtcars, aes(mpg, rownames(mtcars))) + geom_point() + geom_error( aes(error_neg = drat / 2, error_pos = drat), colour_neg = "steelblue", colour_pos = "firebrick" )
geom_error()
stat_error() computes the error bounds from raw observation-level data
using ggplot2's fun.data contract. Where geom_error() expects pre-
computed error columns, stat_error() summarises y (or x, when
orientation is horizontal) within each group via the function supplied to
fun.
stat_error( mapping = NULL, data = NULL, geom = NULL, position = "identity", ..., fun = "mean_se", fun.args = list(), error_geom = "errorbar", orientation = NA, na.rm = FALSE, conf.int = 0.95, show.legend = NA, inherit.aes = TRUE )stat_error( mapping = NULL, data = NULL, geom = NULL, position = "identity", ..., fun = "mean_se", fun.args = list(), error_geom = "errorbar", orientation = NA, na.rm = FALSE, conf.int = 0.95, show.legend = NA, inherit.aes = TRUE )
mapping, data, position, show.legend, inherit.aes
|
Standard ggplot2 layer arguments. |
geom |
The geom to render the summary with. Defaults to
GeomErrorStat, which reuses |
... |
Additional parameters. Names that match |
fun |
One of |
fun.args |
Named list of extra arguments to pass to |
error_geom |
One of |
orientation |
|
na.rm |
If |
conf.int |
Confidence level forwarded to |
library(ggplot2) ggplot(mtcars, aes(factor(cyl), mpg)) + stat_error() ggplot(mtcars, aes(factor(cyl), mpg)) + stat_error(fun = "mean_ci", error_geom = "pointrange") # 90% CI with NA-tolerant summarising: ggplot(mtcars, aes(factor(cyl), mpg)) + stat_error(fun = "mean_ci", conf.int = 0.9, na.rm = TRUE)library(ggplot2) ggplot(mtcars, aes(factor(cyl), mpg)) + stat_error() ggplot(mtcars, aes(factor(cyl), mpg)) + stat_error(fun = "mean_ci", error_geom = "pointrange") # 90% CI with NA-tolerant summarising: ggplot(mtcars, aes(factor(cyl), mpg)) + stat_error(fun = "mean_ci", conf.int = 0.9, na.rm = TRUE)