\HeaderA{plot.stepfun}{Plot Step Functions}{plot.stepfun}
\aliasA{lines.stepfun}{plot.stepfun}{lines.stepfun}
\keyword{hplot}{plot.stepfun}
\begin{Description}\relax
Method of the generic \code{\LinkA{plot}{plot}} for \code{\LinkA{stepfun}{stepfun}}
objects and utility for plotting piecewise constant functions.
\end{Description}
\begin{Usage}
\begin{verbatim}
## S3 method for class 'stepfun':
plot(x, xval, xlim, ylim,
     xlab = "x", ylab = "f(x)", main = NULL,
     add = FALSE, verticals = TRUE, do.points = TRUE,
     pch = par("pch"),
     col.points = par("col"), cex.points = par("cex"),
     col.hor = par("col"), col.vert = par("col"),
     lty = par("lty"), lwd = par("lwd"), ...)

## S3 method for class 'stepfun':
lines(x, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] an \R{} object inheriting from \code{"stepfun"}.
\item[\code{xval}] numeric vector of abscissa values at which to evaluate
\code{x}.  Defaults to \code{\LinkA{knots}{knots}(x)} restricted to \code{xlim}.
\item[\code{xlim,ylim}] numeric(2) each; range of \code{x} or \code{y} values
to use.  Both have sensible defaults.
\item[\code{xlab,ylab}] labels of x and y axis.
\item[\code{main}] main title.
\item[\code{add}] logical; if \code{TRUE} only \emph{add} to an existing plot.
\item[\code{verticals}] logical;  if \code{TRUE}, draw vertical lines at steps.
\item[\code{do.points}] logical;  if \code{true}, also draw points at the
(\code{xlim} restricted) knot locations.
\item[\code{pch}] character; point character if \code{do.points}.
\item[\code{col.points}] character or integer code; color of points if
\code{do.points}.
\item[\code{cex.points}] numeric; character expansion factor if \code{do.points}.
\item[\code{col.hor}] color of horizontal lines.
\item[\code{col.vert}] color of vertical lines.
\item[\code{lty, lwd}] line type and thickness for all lines.
\item[\code{...}] further arguments of \code{\LinkA{plot}{plot}(.)}, or if\code{(add)}
\code{\LinkA{segments}{segments}(.)}.
\end{ldescription}
\end{Arguments}
\begin{Value}
A list with two components
\begin{ldescription}
\item[\code{t}] abscissa (x) values, including the two outermost ones.
\item[\code{y}] y values \sQuote{in between} the \code{t[]}.
\end{ldescription}
\end{Value}
\begin{Author}\relax
Martin Maechler \email{maechler@stat.math.ethz.ch}, 1990,
1993; ported to \R, 1997.
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{ecdf}{ecdf}} for empirical distribution functions as
special step functions,
\code{\LinkA{approxfun}{approxfun}} and \code{\LinkA{splinefun}{splinefun}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
y0 <- c(1,2,4,3)
sfun0  <- stepfun(1:3, y0, f = 0)
sfun.2 <- stepfun(1:3, y0, f = .2)
sfun1  <- stepfun(1:3, y0, right = TRUE)

tt <- seq(0,3, by=0.1)
op <- par(mfrow=c(2,2))
plot(sfun0); plot(sfun0, xval=tt, add=TRUE, col.h="bisque")
plot(sfun.2);plot(sfun.2,xval=tt, add=TRUE, col.h="orange")
plot(sfun1);lines(sfun1, xval=tt, col.h="coral")
##-- This is  revealing :
plot(sfun0, verticals= FALSE,
     main = "stepfun(x, y0, f=f)  for f = 0, .2, 1")
for(i in 1:3)
  lines(list(sfun0,sfun.2,stepfun(1:3,y0,f = 1))[[i]], col.h=i, col.v=i)
legend(2.5, 1.9, paste("f =", c(0,0.2,1)), col=1:3, lty=1, y.inter=1)
par(op)

# Extend and/or restrict 'viewport':
plot(sfun0, xlim = c(0,5), ylim = c(0, 3.5),
     main = "plot(stepfun(*), xlim= . , ylim = .)")

##-- this works too (automatic call to  ecdf(.)):
plot.stepfun(rt(50, df=3), col.vert = "gray20")
\end{ExampleCode}
\end{Examples}

