| Title: | Extended Error Geoms for 'ggplot2' |
| Version: | 1.0.0 |
| 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... |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| Config/roxygen2/markdown: | TRUE |
| Config/roxygen2/version: | 8.0.0 |
| Imports: | cli, ggplot2 (≥ 3.4.0), lifecycle, rlang |
| Suggests: | knitr, purrr, rmarkdown, svglite, testthat (≥ 3.0.0), vdiffr (≥ 1.0.0) |
| Config/testthat/edition: | 3 |
| VignetteBuilder: | knitr |
| URL: | https://iamyannc.github.io/ggerror/ |
| BugReports: | https://github.com/iamYannC/ggerror/issues |
| NeedsCompilation: | no |
| Packaged: | 2026-05-11 22:46:27 UTC; 97253 |
| Author: | Yann Cohen |
| Maintainer: | Yann Cohen <yannco5@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-05-12 18:40:36 UTC |
ggerror: 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...
Author(s)
Maintainer: Yann Cohen yannco5@gmail.com (ORCID)
Authors:
Yann Cohen yannco5@gmail.com (ORCID)
See Also
Useful links:
Error bars with automatic orientation
Description
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.
Usage
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)
Arguments
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 |
Package options
Session-level knobs for the 0 -> NA migration. Set via options():
-
ggerror.silent_zero_warning—TRUEsuppresses the soft deprecation fired whenerror_negorerror_posis set to0(You are encouraged to set it toNA). DefaultFALSE. -
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 to1e-8.
Aesthetics
geom_error() requires x, y, and one of:
-
error— symmetric half-width applied along the non-categorical axis. -
error_neganderror_pos— asymmetric; the bar extendserror_negin the negative direction anderror_posin the positive direction along the non-categorical axis. For a one-sided bar, set the unused side toNA— 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.
Examples
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"
)
Summarising stat for geom_error()
Description
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.
Usage
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
)
Arguments
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 |
Examples
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)