errbar: Add Error Bars to Base or Lattice Plot

View source: R/variance_functions.R

errbarR Documentation

Add Error Bars to Base or Lattice Plot

Description

errbar is a function that allows the rapid addition of error bars to base or Lattice graphics.

Usage

errbar(x, y, error, color = "black", type = 2)

Arguments

x

vector of x values corresponding to x-values of data plotted in a plot. There should be paired y-value data for each of these x values. Must be the same length as y and error.

y

vector of y values corresponding to y-values of data plotted in a plot. There should be paired x-value data for each of these y values. Must be the same length as x and error.

error

vector of "error" (e.g., could represent, standard errors, confidence intervals, etc.) estimates for each of the x and y values provided in x and y. Must be the same length as x and y.

color

A specification for the plotting color of the error bars. See description of Color Specificaiton in the par for more information.

type

Used to specify the type of plot the error bars are to be used in. If type=1, error bars and constructed for use in base graphics plots. If type=2, error bars are constructed for use in lattice graphics plots. Any other specificaiton of type will cause an error.

Value

This function is used to add error bars to an already created graph. The actual way to use this function will depend on the type of plot being created.

Examples

# Generate Data
set.seed(1234)
x <- seq(1, 50, 1)
y <- (2 + 2 * x) * rnorm(50, 1, 0.2)
error <- rnorm(50, 2, 0.5)
# Example - Base Graphics
plot(y ~ x, xlab = "X Variable", ylab = "Y Variable")
errbar(x = x, y = y, error = error, type = 1)
# Example - Lattice Graphics
lattice::xyplot(y ~ x, xlab = "X Variable", ylab = "Y Variable",
 panel = function(x, y) {
   panel.xyplot(x, y)
   errbar(x = x, y = y, error = error, type = 2)
 })

ballengerj/FishyR documentation built on June 17, 2022, 10:33 p.m.