Skip to contents

Adds native 'Microsoft Office' error bars to one or more series of a bar, line or scatter chart. The error bars are rendered by the host application (PowerPoint, Word or Excel) and remain editable.

This exposes the native c:errBars chart element and supports fixed value, percentage, standard deviation, standard error and fully custom (per-point) error amounts, in the plus, minus or both directions.

Usage

chart_error_bars(
  x,
  series = NULL,
  type = c("fixedVal", "percentage", "stdDev", "stdErr", "cust"),
  value = NULL,
  plus = NULL,
  minus = NULL,
  direction = c("both", "plus", "minus"),
  errdir = c("y", "x"),
  end_cap = TRUE,
  line = NULL
)

Arguments

x

an ms_chart object created with ms_barchart(), ms_linechart() or ms_scatterchart().

series

character vector of series names the error bars should be added to. When NULL (default), error bars are added to every series.

type

the error amount type, one of "fixedVal" (a fixed amount), "percentage" (a percentage of each value), "stdDev" (a multiple of the standard deviation), "stdErr" (the standard error) or "cust" (custom per-point amounts supplied via plus / minus).

value

a single numeric amount used when type is "fixedVal", "percentage" or "stdDev". Ignored for "stdErr" and "cust".

plus, minus

numeric vectors of custom error amounts (one per data point) used when type = "cust". plus is the positive error and minus the negative error. Recycled to the number of points if length 1.

direction

the error bar direction, one of "both", "plus" or "minus".

errdir

the axis the error bars apply to, "y" (default) or "x". "x" is only valid for ms_scatterchart().

end_cap

if TRUE (default), draw the T-shaped end cap.

line

an officer::fp_border() describing the error bar colour, width and dash style. When NULL, Office uses its default styling.

Value

An updated ms_chart object.

Examples

library(officer)

dat <- data.frame(
  cat = c("A", "B", "C", "D"),
  val = c(4, 7, 5, 9)
)

bc <- ms_barchart(data = dat, x = "cat", y = "val")
bc <- chart_error_bars(bc, type = "percentage", value = 10)