| 42333 |
ripley |
1 |
% File src/library/stats/man/plot.stepfun.Rd
|
|
|
2 |
% Part of the R package, http://www.R-project.org
|
| 59039 |
ripley |
3 |
% Copyright 1995-2009 R Core Team
|
| 42333 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
| 27652 |
maechler |
6 |
\name{plot.stepfun}
|
| 56186 |
murdoch |
7 |
\alias{plot.stepfun}
|
| 27652 |
maechler |
8 |
\alias{lines.stepfun}
|
|
|
9 |
\title{Plot Step Functions}
|
|
|
10 |
\description{
|
|
|
11 |
Method of the generic \code{\link{plot}} for \code{\link{stepfun}}
|
|
|
12 |
objects and utility for plotting piecewise constant functions.
|
|
|
13 |
}
|
|
|
14 |
\usage{
|
| 61168 |
ripley |
15 |
\method{plot}{stepfun}(x, xval, xlim, ylim = range(c(y, Fn.kn)),
|
| 27652 |
maechler |
16 |
xlab = "x", ylab = "f(x)", main = NULL,
|
| 49011 |
maechler |
17 |
add = FALSE, verticals = TRUE, do.points = (n < 1000),
|
| 47018 |
maechler |
18 |
pch = par("pch"), col = par("col"),
|
|
|
19 |
col.points = col, cex.points = par("cex"),
|
|
|
20 |
col.hor = col, col.vert = col,
|
| 27652 |
maechler |
21 |
lty = par("lty"), lwd = par("lwd"), \dots)
|
|
|
22 |
|
|
|
23 |
\method{lines}{stepfun}(x, \dots)
|
|
|
24 |
}
|
|
|
25 |
\arguments{
|
|
|
26 |
\item{x}{an \R object inheriting from \code{"stepfun"}.}
|
|
|
27 |
\item{xval}{numeric vector of abscissa values at which to evaluate
|
|
|
28 |
\code{x}. Defaults to \code{\link{knots}(x)} restricted to \code{xlim}.}
|
| 48876 |
murdoch |
29 |
\item{xlim, ylim}{limits for the plot region: see
|
| 49011 |
maechler |
30 |
\code{\link{plot.window}}. Both have sensible defaults if omitted.}
|
| 47404 |
ripley |
31 |
\item{xlab, ylab}{labels for x and y axis.}
|
| 27652 |
maechler |
32 |
\item{main}{main title.}
|
|
|
33 |
\item{add}{logical; if \code{TRUE} only \emph{add} to an existing plot.}
|
|
|
34 |
\item{verticals}{logical; if \code{TRUE}, draw vertical lines at steps.}
|
| 47404 |
ripley |
35 |
\item{do.points}{logical; if \code{TRUE}, also draw points at the
|
| 48320 |
maechler |
36 |
(\code{xlim} restricted) knot locations. Default is true, for
|
| 60196 |
maechler |
37 |
sample size \eqn{< 1000}.}% n = 1 + 'sample size'
|
| 27652 |
maechler |
38 |
\item{pch}{character; point character if \code{do.points}.}
|
| 47018 |
maechler |
39 |
\item{col}{default color of all points and lines.}
|
| 27652 |
maechler |
40 |
\item{col.points}{character or integer code; color of points if
|
|
|
41 |
\code{do.points}.}
|
|
|
42 |
\item{cex.points}{numeric; character expansion factor if \code{do.points}.}
|
|
|
43 |
\item{col.hor}{color of horizontal lines.}
|
|
|
44 |
\item{col.vert}{color of vertical lines.}
|
|
|
45 |
\item{lty, lwd}{line type and thickness for all lines.}
|
|
|
46 |
\item{\dots}{further arguments of \code{\link{plot}(.)}, or if\code{(add)}
|
|
|
47 |
\code{\link{segments}(.)}.}
|
|
|
48 |
}
|
|
|
49 |
\value{
|
|
|
50 |
A list with two components
|
|
|
51 |
\item{t}{abscissa (x) values, including the two outermost ones.}
|
|
|
52 |
\item{y}{y values \sQuote{in between} the \code{t[]}.}
|
|
|
53 |
}
|
|
|
54 |
\author{Martin Maechler \email{maechler@stat.math.ethz.ch}, 1990,
|
|
|
55 |
1993; ported to \R, 1997.}
|
|
|
56 |
\seealso{\code{\link{ecdf}} for empirical distribution functions as
|
|
|
57 |
special step functions,
|
|
|
58 |
\code{\link{approxfun}} and \code{\link{splinefun}}.
|
|
|
59 |
}
|
|
|
60 |
\examples{
|
| 41508 |
ripley |
61 |
require(graphics)
|
|
|
62 |
|
| 27652 |
maechler |
63 |
y0 <- c(1,2,4,3)
|
|
|
64 |
sfun0 <- stepfun(1:3, y0, f = 0)
|
|
|
65 |
sfun.2 <- stepfun(1:3, y0, f = .2)
|
|
|
66 |
sfun1 <- stepfun(1:3, y0, right = TRUE)
|
|
|
67 |
|
| 61168 |
ripley |
68 |
tt <- seq(0, 3, by = 0.1)
|
| 61160 |
ripley |
69 |
op <- par(mfrow = c(2,2))
|
|
|
70 |
plot(sfun0); plot(sfun0, xval = tt, add = TRUE, col.hor = "bisque")
|
| 61168 |
ripley |
71 |
plot(sfun.2);plot(sfun.2, xval = tt, add = TRUE, col = "orange") # all colors
|
| 61160 |
ripley |
72 |
plot(sfun1);lines(sfun1, xval = tt, col.hor = "coral")
|
| 27652 |
maechler |
73 |
##-- This is revealing :
|
| 61160 |
ripley |
74 |
plot(sfun0, verticals = FALSE,
|
| 27652 |
maechler |
75 |
main = "stepfun(x, y0, f=f) for f = 0, .2, 1")
|
|
|
76 |
for(i in 1:3)
|
| 61168 |
ripley |
77 |
lines(list(sfun0, sfun.2, stepfun(1:3, y0, f = 1))[[i]], col = i)
|
|
|
78 |
legend(2.5, 1.9, paste("f =", c(0, 0.2, 1)), col = 1:3, lty = 1, y.intersp = 1)
|
| 36816 |
ripley |
79 |
par(op)
|
| 27652 |
maechler |
80 |
|
|
|
81 |
# Extend and/or restrict 'viewport':
|
|
|
82 |
plot(sfun0, xlim = c(0,5), ylim = c(0, 3.5),
|
|
|
83 |
main = "plot(stepfun(*), xlim= . , ylim = .)")
|
|
|
84 |
|
|
|
85 |
##-- this works too (automatic call to ecdf(.)):
|
| 61160 |
ripley |
86 |
plot.stepfun(rt(50, df = 3), col.vert = "gray20")
|
| 27652 |
maechler |
87 |
}
|
|
|
88 |
\keyword{hplot}
|