plotwitherror: Plot Command For XY Plots With Error Bars

View source: R/plotutils.R

plotwitherrorR Documentation

Plot Command For XY Plots With Error Bars


Plot command for XY scatterplots based on plot and points which provides support for multiple, non-symmetric error bars. Error bars are drawn as vertical or horizontal lines originating from the point with narrow, perpendicular lines at the end of the error bar (end caps). When multiple errors are drawn, the width of the perpendicular line increases from the innermost error bar to the outermost one. Different summation methods for the individual errors are supported.


plotwitherror(x, y, dy, ylim = NULL, dx, xlim = NULL, mdx, mdy,
  errsum.method = "linear.quadrature", rep = FALSE, col = "black", ...)



vector of x coordinates


vector of y coordinates


one of:

  • Vector of errors on y coordinates.

  • Array, matrix or data frame if multiple error bars are to be drawn, such that each column refers to one error. The individual errors should be provided as is, because they are summed internally to draw the final error bars. A given column can also be provided with 0 entries, in which case the error bar will be drawn, but it will have zero length, such that only the end caps for this error will be visible.


limits for y-axis


Same as dy, but for the x coordinate.


limits for x-axis


Support for non-symmetric error bars. Same as dx, but for errors in the negative x-direction. Errors should be provided as positive numbers, the correct sign will be added internally. If not provided, dx is used as a symmetric error.


Same as mdx but for the y coordinate.


Determines how the invidual errors should be summed for display purposes. Valid argument values are:

  • "linear"

    • Individual errors are summed linearly, such that the distance from the point to the i'th error bar, l_i, is

      l_i = ∑_{j=1}^i e_j

      Hence, the third error bar, for example, would be located at

      l_3 = e_1 + e_2 + e_3

      while the second error bar is at

      l_2 = e_1 + e_2

  • "quadrature"

    • Individual errors are summed in quadrature and error bars are drawn at the fractional position according to the following formula:

      l_{max} = √{ ∑_{j=1}^{max} e_j^2 }

      l_i = ∑_{j=1}^i e_j^2 / l_{max}

  • "linear.quadrature"

    • Errors are summed as for "linear", but the total error summed in quadrature is also indicated as an end cap of triple line width


If set to TRUE, operate like "replot" in gnuplot. Allows adding points with error bars to the current plot. Switches the underlying plotting routine from plot to points.


colour of plotted data


any graphic options passed over to plot


a plot with error bars is drawn on the current device

Returns for convenience a list with elements xlim and ylim representing the x- and y-limits chosen by the routine.


Carsten Urbach,
Bartosz Kostrzewa,

See Also

plot, points


# Create some random data, set one error to zero.
x <- 1:50
y <- runif(50, 0, 1)
dy <- runif(50, 0.1, 0.2)
dy[4] <- 0

plotwitherror(x, y, dy)

hadron documentation built on Sept. 9, 2022, 5:06 p.m.