View source: R/variance_functions.R
errbar | R Documentation |
errbar
is a function that allows the rapid addition of error bars to
base or Lattice graphics.
errbar(x, y, error, color = "black", type = 2)
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 |
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. |
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.
# 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) })
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.