Add an error bar figure to the chart.
fig_error( g, ..., sync = TRUE, data = NULL, inherit_asp = TRUE, alias = "error" )
g | An object of class |
---|---|
... | Options to pass to the figure, including |
sync | Whether to sync the axis data (align) with that
used in other figures, set to |
data | A dataset ( |
inherit_asp | Whether to inherit the aspects paseed to
|
alias | Name of the range to display on tooltips, labels, etc. |
Requires the ymin
and ymax
aspects, the
width of the error bars can be changed with the size
aspect.
df <- data.frame( x = as.factor(c(1:10, 1:10)), y = runif(20, 10, 15), grp = rep(c("A", "B"), each = 2) ) df$ymin <- df$y - runif(20, 1, 2) df$ymax <- df$y + runif(20, 1, 2) g2(df, asp(x = x, color = grp)) %>% fig_error(asp(ymin = ymin, ymax = ymax), adjust("dodge")) %>% fig_interval( asp(y = y), adjust("dodge"), fillOpacity = .4 )