polyShade: Polygon shading

Description Usage Arguments See Also Examples

View source: R/plot_extra.R

Description

Color or shade the area under a curve.

Usage

1
2
polyShade(x, y, from = -Inf, to = Inf, n = 1000, miny = min(y, na.rm =
  TRUE), horiz = FALSE, ...)

Arguments

x, y

x- and y-values from the curve

from

a vector of x-coordinates from which to color

to

a vector of x-coordinates to which to color (same length) as from

n

tuning parameter for fitting the shading region to the curve; a lower value will result in a worse fit around the curve

miny

by default, shading will extend from the curve to min(y)

horiz

logical; if TRUE, the y-axis is assumed to be the horizontal

...

additional parameters passed to polygon; common uses are density for shading lines, col for shading color(s), border for border color, or lty for line type

See Also

http://www.fromthebottomoftheheap.net/2013/01/11/shading-regions-under-a-curve/

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
set.seed(1)
x <- density(c(rnorm(75), rnorm(25, 5)))

plot(x)
polyShade(x$x, x$y, -1, 2, col = 'red', border = NA)
polyShade(x$x, x$y, from = c(-Inf, 6), to = c(-2, Inf),
          col = adjustcolor('red', .3), border = NA)
polyShade(x$x, x$y, 0, 4, col = 'blue', density = 20, lty = 4,
          miny = par('usr')[1], border = NA)

## horizontal
plot(x$y, x$x, type = 'l')
polyShade(x$x, x$y, horiz = TRUE, col = 'blue')

raredd/plotr documentation built on Nov. 13, 2018, 7:05 a.m.