Learn R Programming

itsadug (version 0.8)

plot_error: Utility function

Description

Plot line with confidence intervals.

Usage

plot_error(x, fit, se.fit, shade = FALSE, f = 1, col = "black",
  border = NA, alpha = 0.25, ...)

Arguments

x
Vector with values on x-axis.
fit
Vector with values on y-axis.
se.fit
Vector with standard error.
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.
border
A number, indicating the linewidth of the border around shaded area. No border with value NA (default). Only applies when shade=TRUE.
alpha
Transparency of shaded area. Number between 0 (completely transparent) and 1 (not transparent).
...
Optional arguments for the lines. See par.

See Also

Other Utility functions for plotting: addInterval; alphaPalette; alpha; dotplot_error; emptyPlot; errorBars; fadeRug; fill_area; find_difference; getCoords; gradientLegend; horiz_error

Examples

Run this code
data(simdat)

# Use aggregate to calculate mean and standard deviation per timestamp:
avg <- aggregate(simdat$Y, by=list(Time=simdat$Time),
    function(x){c(mean=mean(x), sd=sd(x))})
head(avg)
# Note that column x has two values in each row:
head(avg$x)
head(avg$x[,1])

# Plot line and standard deviation:
emptyPlot(range(avg$Time), c(-20,20), h0=0)
plot_error(avg$Time, avg$x[,'mean'], avg$x[,'sd'])
# Change layout:
emptyPlot(range(avg$Time), c(-20,20), h0=0)
plot_error(avg$Time, avg$x[,'mean'], avg$x[,'sd'],
   shade=TRUE, lty=3, lwd=3)

# Show difference with 0:
x <- find_difference(avg$x[,'mean'], avg$x[,'sd'], xVals=avg$Time)
# Add arrows:
abline(v=c(x$start, x$end), lty=3, col='red')
arrows(x0=x$start, x1=x$end, y0=-5, y1=-5, code=3, length=.1, col='red')

# see the vignette on visualization,
# section 'Using predictions to customize plots', for an example:
vignette(topic="plotfunctions")

Run the code above in your browser using DataLab