The R Project SVN R

Rev

Rev 68948 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42333 ripley 1
% File src/library/graphics/man/plotformula.Rd
68948 ripley 2
% Part of the R package, https://www.R-project.org
67599 ripley 3
% Copyright 1995--2014 R Core Team
42333 ripley 4
% Distributed under GPL 2 or later
5
 
27442 ripley 6
\name{plot.formula}
56186 murdoch 7
\alias{plot.formula}
27442 ripley 8
\alias{lines.formula}
9
\alias{points.formula}
53575 maechler 10
\alias{text.formula}
27442 ripley 11
\title{Formula Notation for Scatterplots}
12
\description{
53575 maechler 13
  Specify a scatterplot or add points, lines, or text via a formula.
27442 ripley 14
}
15
\usage{
16
\method{plot}{formula}(formula, data = parent.frame(), \dots, subset,
43730 murrell 17
             ylab = varnames[response], ask = dev.interactive())
27442 ripley 18
 
19
\method{points}{formula}(formula, data = parent.frame(), \dots, subset)
20
 
21
\method{lines}{formula}(formula, data = parent.frame(), \dots, subset)
53575 maechler 22
 
23
\method{text}{formula}(formula, data = parent.frame(), \dots, subset)
27442 ripley 24
}
25
\arguments{
30461 ripley 26
  \item{formula}{a \code{\link{formula}}, such as \code{y ~ x}.}
27442 ripley 27
  \item{data}{a data.frame (or list) from which the variables in
56033 ripley 28
    \code{formula} should be taken.  A matrix is converted to a data frame.}
36139 ripley 29
  \item{\dots}{Arguments to be passed to or from other methods.
30
    \code{horizontal = TRUE} is also accepted.}
27442 ripley 31
  \item{subset}{an optional vector specifying a subset of observations
32
    to be used in the fitting process.}
33
  \item{ylab}{the y label of the plot(s).}
34
  \item{ask}{logical, see \code{\link{par}}.}
35
}
36
\details{
56033 ripley 37
  For the \code{lines}, \code{points} and \code{text} methods the formula
38
  should be of the form \code{y ~ x} or \code{y ~ 1} with a left-hand
39
  side and a single term on the right-hand side.  The \code{plot} method
40
  accepts other forms discussed later in this section.
61433 ripley 41
 
27442 ripley 42
  Both the terms in the formula and the \code{\dots} arguments are
43
  evaluated in \code{data} enclosed in \code{parent.frame()} if
56033 ripley 44
  \code{data} is a list or a data frame.  The terms of the formula and
27442 ripley 45
  those arguments in \code{\dots} that are of the same length as
46
  \code{data} are subjected to the subsetting specified in
56033 ripley 47
  \code{subset}.  A plot against the running index can be specified as
29251 ripley 48
  \code{plot(y ~ 1)}.
27442 ripley 49
 
56033 ripley 50
  If the formula in the \code{plot} method contains more than one term
51
  on the right-hand side, a series of plots is produced of the response
52
  against each non-response term.
61433 ripley 53
 
56033 ripley 54
  For the \code{plot} method the formula can be of the form
55
  \code{~ z + y + z}: the variables specified on the right-hand side are
56
  collected into a data frame, subsetted if specified, and displayed by
57
  \code{\link{plot.data.frame}}.
61433 ripley 58
 
29251 ripley 59
  Missing values are not considered in these methods, and in particular
60
  cases with missing values are not removed.
61
 
66444 hornik 62
  If \code{y} is an object (i.e., has a \code{\link{class}} attribute)
27442 ripley 63
  then \code{plot.formula} looks for a plot method for that class first.
64
  Otherwise, the class of \code{x} will determine the type of the plot.
65
  For factors this will be a parallel boxplot, and argument
56033 ripley 66
  \code{horizontal = TRUE} can be specified (see \code{\link{boxplot}}).
61433 ripley 67
 
56033 ripley 68
  Note that some arguments will need to be protected from premature
69
  evaluation by enclosing them in \code{\link{quote}}: currently this is
70
  done automatically for \code{main}, \code{sub} and \code{xlab}.  For
71
  example, it is needed for the \code{panel.first} and \code{panel.last}
72
  arguments passed to \code{\link{plot.default}}.
27442 ripley 73
}
74
\value{
53575 maechler 75
  These functions are invoked for their side effect of drawing
56033 ripley 76
  on the active graphics device.
27442 ripley 77
}
78
\seealso{
36139 ripley 79
  \code{\link{plot.default}}, \code{\link{points}}, \code{\link{lines}},
80
  \code{\link{plot.factor}}.
27442 ripley 81
}
82
\examples{
56031 ripley 83
op <- par(mfrow = c(2,1))
84
plot(Ozone ~ Wind, data = airquality, pch = as.character(Month))
85
plot(Ozone ~ Wind, data = airquality, pch = as.character(Month),
27442 ripley 86
     subset = Month != 7)
87
par(op)
53575 maechler 88
 
89
## text.formula() can be very natural:
90
wb <- within(warpbreaks, {
91
    time <- seq_along(breaks); W.T <- wool:tension })
92
plot(breaks ~ time, data = wb, type = "b")
80079 hornik 93
text(breaks ~ time, data = wb, labels = W.T, col = 1+as.integer(wool))
27442 ripley 94
}
53575 maechler 95
\keyword{hplot}% plot
96
\keyword{aplot}% points, etc