https://github.com/cran/pracma
Tip revision: 63e8a52ae6668e736720c89691352d6dc3bc9eb1 authored by HwB on 17 January 2012, 00:00:00 UTC
version 0.9.6
version 0.9.6
Tip revision: 63e8a52
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)
}