https://github.com/cran/pracma
Tip revision: a7001ff1805634d18a10fa371b38dbe3e48f8c9e authored by HwB on 30 October 2011, 00:00:00 UTC
version 0.8.1
version 0.8.1
Tip revision: a7001ff
ezplot.R
##
## e z p l o t . R
##
ezplot <- function(f, a, b, n = 101, col = "blue",
grid = TRUE, gridcol = "gray",
fill = FALSE, fillcol = "lightgray",
xlab = "x", ylab = "f (x)", main = "Function Plot", ...) {
fun <- match.fun(f)
f <- function(x) fun(x)
stopifnot(is.numeric(a), is.numeric(b),
length(a) == 1, length(b) == 1, a < b)
x <- seq(a, b, length.out = n)
y <- f(x)
plot(x, y, type = "n", xlab = xlab, ylab = ylab, main = main, ...)
if (grid)
grid(col = gridcol)
if (fill) {
xx <- c(x, rev(x))
yy <- c(rep(0, length(x)), rev(y))
polygon(xx, yy, col = fillcol, border = "darkgray")
}
lines(x, y, col = col)
invisible(NULL)
}