Learn R Programming

plotfunctions (version 1.4)

plot_error: Utility function

Description

Plot line with confidence intervals.

Usage

plot_error(
  x,
  fit,
  se.fit,
  se.fit2 = NULL,
  shade = FALSE,
  f = 1,
  col = "black",
  ci.lty = NULL,
  ci.lwd = NULL,
  border = FALSE,
  alpha = 0.25,
  ...
)

Arguments

x

Vector with values on x-axis.

fit

Vector with values on y-axis.

se.fit

Vector with standard error; or when se.fit2 is provided, se.fit specifies upper values confidence interval.

se.fit2

Optional: lower values confidence interval.

shade

Logical: whether or not to produce shaded regions as confidence bands.

f

Factor for converting standard error in confidence intervals. Defaults to 1. Use 1.96 for 95% CI, and 2.58 for 99% CI.

col

Color for lines and confindence bands.

ci.lty

Line type to be used for the error lines, see par.

ci.lwd

Line type to be used for the error lines, see par.

border

The color to draw the border for the shaded confidence interval. The default, FALSE, omits borders.

alpha

Transparency of shaded area. Number between 0 (completely transparent) and 1 (not transparent).

...

Optional arguments for the lines and shaded area.

See Also

Other Functions for plotting: addInterval(), add_bars(), add_n_points(), alphaPalette(), alpha(), check_normaldist(), color_contour(), dotplot_error(), drawDevArrows(), emptyPlot(), errorBars(), fill_area(), getCoords(), getFigCoords(), getProps(), gradientLegend(), legend_margin(), marginDensityPlot(), plot_image(), plotsurface(), sortBoxplot()

Examples

Run this code
# NOT RUN {
# generate some data:
x <- -10:20
y <- 0.3*(x - 3)^2 + rnorm(length(x))
s <- 0.2*abs(100-y + rnorm(length(x)))

# Plot line and standard deviation:
emptyPlot(range(x), range(y), h0=0)
plot_error(x, y, s)
# Change layout:
emptyPlot(range(x), range(y), h0=0)
plot_error(x, y, s, shade=TRUE, lty=3, lwd=3)

# Use of se.fit2 for asymmetrical error bars:
cu <- y + .65*s
cl <- y - s
emptyPlot(range(x), range(y), h0=0)
plot_error(x, y, s, shade=TRUE)
plot_error(x, y, se.fit=cu, se.fit2=cl, col='red', shade=TRUE)

# Some layout options:
emptyPlot(range(x), range(y), h0=0)
plot_error(x, y, s, lty=3, lwd=1, ci.lty=1, ci.lwd=3)
emptyPlot(range(x), range(y), h0=0)
plot_error(x, y, s, shade=TRUE, lty=3, lwd=3)
emptyPlot(range(x), range(y), h0=0)
plot_error(x, y, s, shade=TRUE, lty=1, lwd=3, ci.lwd=3, border='red')
emptyPlot(range(x), range(y), h0=0)
plot_error(x, y, s, shade=TRUE, lty=1, lwd=3, density=10, ci.lwd=3)

# }

Run the code above in your browser using DataLab