Description Usage Arguments Details Author(s) See Also Examples
This function fills or shades the area between two curves or under a curve.
1 |
x |
A numeric vector of x-coordinates. |
y1 |
A numeric vector of y-coordinates. |
y2 |
A numeric vector of y-coordiantes. Defaults to zero. |
... |
Arguments passed to |
The function fills or shades the area between two lines as drawn by
lines(x, y1)
and lines(x, y2)
. If y2
is not supplied
the area between the curve and the x-axis is drawn. A seen in the examples,
a neat trick to get the area under the curve is to set
y2 = rep(-Inf, length(x))
.
Anders Ellern Bilgrau <anders.ellern.bilgrau (at) gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | # Random example 1
x <- seq(-2*pi, 2*pi, length.out = 100)
y1 <- cos(x)
y2 <- sin(4*x) - x^2 + 10
plot(x, type = "n", ylim = range(c(y1, y2)), xlim = range(x),
ylab = "y", xlab = "x")
fillLines(x, y1, y2, col = "tomato", border = NA)
fillLines(x, pmin(y1, y2), rep(-Inf, length(x)),
col = "steelblue", border = NA)
lines(x, y1, lty = 2, lwd = 2)
lines(x, y2, lty = 3, lwd = 2)
# Pursuit curve
x <- seq(0.01, 3, by = 0.01)
y <- 2*x^2 - log(x)
plot(x, y, type = "n", ylim = c(0, max(y)))
fillLines(x, y, density = 10, angle = -30, col = "orange")
# The super egg
p <- 5/2
h <- 1
r <- 3/4*h
x <- seq(-r, r, by = 0.001)
y1 <- h^p*(1 - abs(x/r)^p)^(1/p)
y2 <- -y1
plot(1, type = "n", xlim = c(-r,r), ylim = c(-h, h), asp = 1,
xlab = "", ylab = "")
fillLines(x, y1, y2, col = "gold", lwd = 2, border = "orange")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.