Learn R Programming

inlmisc (version 0.5.5)

AddIntervals: Add Interval Symbols to Plot

Description

Add interval symbols (also known as error bars) to plots.

Usage

AddIntervals(
  x,
  y0,
  y1,
  hin = NULL,
  col = "black",
  lty = 1,
  lwd = 0.7,
  cex = 1,
  xpd = FALSE,
  ...,
  nondetects = NULL
)

Arguments

x

'numeric' or 'Date' vector. x coordinate of interval symbols.

y0

'numeric' vector. y coordinate of points from which to draw.

y1

'numeric' vector. y coordinate of points to which to draw.

hin

'numeric' number. Horizontal length of an interval head, in inches.

col, lty, lwd, cex, xpd

graphical parameters; see par for details. NA values in col cause the interval to be omitted.

...

Additional graphical parameters to the points function.

nondetects

'list'. Overrides graphical parameters used for left- and right-censored data. Passed arguments include col, lty, and lwd.

Value

Invisible NULL

Details

For each observation i, the data type is identified using (y0[i], Inf) for right-censored, y0[i] = y1[i] for exact, and (-Inf, y1[i]) for left-censored, and (y0[i], y1[i]) for interval-censored. Where infinity may be represented with either Inf or NA.

Examples

Run this code
# NOT RUN {
set.seed(1)
x <- stats::runif(12)
y <- stats::rnorm(12)
plot(x, y)
dy <- sort.int(y) / 5
AddIntervals(x, y - dy, y + dy, col = "red", xpd = TRUE)

n <- 50
x <- sort.int(stats::runif(n, max = 100))
y1 <- y0 <- stats::runif(n, max = 100)
y1[sample.int(n, 5)] <- stats::runif(5, max = 100)
y0[sample.int(n, 5)] <- -Inf
y1[sample.int(n, 5)] <-  Inf
ylim <- range(pretty(c(y0, y1)))
plot(NA, xlim = range(x), ylim = ylim, xlab = "x", ylab = "y")
AddIntervals(x, y0, y1, col = "blue", xpd = TRUE,
             nondetects = list("col" = "red", "lty" = 2))
print(cbind(x, y0, y1))

# }

Run the code above in your browser using DataLab