shadepoly: Add Shaded Polygon to Plot

Description Usage Arguments Details See Also Examples

View source: R/shadepoly.R

Description

Add a spline-smoothed, shaded polygon to a plot, typically to show an interval or range of values (in the y-direction) for a time series of x values.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
shadepoly(
  x,
  ymd,
  ylo,
  yhi,
  subsel = NULL,
  kol = "#000000",
  opq = c(20, 50),
  addline = TRUE,
  smooth = 100
)

Arguments

x

A numeric vector, the metric to plot in the x direction (e.g., time).

ymd

A numeric vector, the metric to plot in the y direction (e.g., a mean or median).

ylo

A numeric vector, the lower interval or range in the y direction (e.g., a lower confidence interval or quartile).

yhi

A numeric vector, the upper interval or range in the y direction (e.g., an upper confidence interval or quartile).

subsel

A logical vector, indicating subset of the data to plot.

kol

A character scalar, the hex color to use for plotting both the shaded polygon and (if requested) the line, default "#000000" (black).

opq

A numeric vector of length 2, opacity for the polygon and the line, default c(20, 50).

addline

A logical scalar, indicating if the x vs ymd line should be added to the plot (on top of the shaded polygon), default TRUE.

smooth

A numeric scalar, indicating the degree of spline smoothing to be applied, default 100. If set to 0, then no smoothing is done. See the n argument of spline, specifying interpolation at equally spaced points.

Details

Missing values are removed prior to plotting, such that there will be no breaks in the shaded polygon nor the line (if requested). The lower and upper intervals of the polygon are spline-smoothed prior to plotting, as is the line (if requested).

See Also

polygon, lines.

Examples

1
2
3
4
5
x <- 1:10
y <- sample(10)
noise <- abs(rnorm(10))
plot(x, y, ylim=range(y-noise, y+noise), type="n")
shadepoly(x, y, y-noise, y+noise)

JVAdams/jvamisc documentation built on Aug. 11, 2021, 6:43 a.m.