plotwitherror: Plot Command For XY Plots With Error Bars

View source: R/plotutils.R

plotwitherrorR Documentation

Plot Command For XY Plots With Error Bars

Description

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.

Usage

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

Arguments

x

vector of x coordinates

y

vector of y coordinates

dy

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.

ylim

limits for y-axis

dx

Same as dy, but for the x coordinate.

xlim

limits for x-axis

mdx

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.

mdy

Same as mdx but for the y coordinate.

errsum.method

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

rep

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.

col

colour of plotted data

...

any graphic options passed over to plot

Value

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.

Author(s)

Carsten Urbach, urbach@hiskp.uni-bonn.de
Bartosz Kostrzewa, bartosz.kostrzewa@desy.de

See Also

plot, points

Examples


# 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.