The R Project SVN R

Rev

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

Rev Author Line No. Line
27442 ripley 1
\name{plot.default}
2
\alias{plot.default}
3
\title{The Default Scatterplot Function}
4
\description{
5
  Draw a scatter plot with \dQuote{decorations} such as axes and titles
6
  in the active graphics window.
7
}
8
\usage{
9
\method{plot}{default}(x, y = NULL, type = "p",  xlim = NULL, ylim = NULL,
10
     log = "", main = NULL, sub = NULL, xlab = NULL, ylab = NULL,
11
     ann = par("ann"), axes = TRUE, frame.plot = axes,
36110 ripley 12
     panel.first = NULL, panel.last = NULL, asp = NA, \dots)
27442 ripley 13
}
14
\arguments{
36110 ripley 15
  \item{x, y}{the \code{x} and \code{y} arguments provide the x and y
27442 ripley 16
    coordinates for the plot.  Any reasonable way of defining the
17
    coordinates is acceptable.  See the function \code{\link{xy.coords}}
18
    for details.}
19
  \item{type}{1-character string giving the type of plot desired.  The
20
    following values are possible, for details, see \code{\link{plot}}:
21
    \code{"p"} for points, \code{"l"} for lines,
22
    \code{"o"} for overplotted points and lines,
23
    \code{"b"}, \code{"c"}) for (empty if \code{"c"}) points joined by lines,
24
    \code{"s"} and \code{"S"} for stair steps and
25
    \code{"h"} for histogram-like vertical lines.  Finally,
26
    \code{"n"} does not produce any points or lines.}
39607 ripley 27
  \item{xlim}{the x limits (x1, x2) of the plot.  Note that \code{x1 > x2}
37566 maechler 28
    is allowed and leads to a \dQuote{reversed axis}.}
27442 ripley 29
  \item{ylim}{the y limits of the plot.}
30
  \item{log}{a character string which contains \code{"x"} if the x axis
31
    is to be logarithmic, \code{"y"} if the y axis is to be logarithmic
32
    and \code{"xy"} or \code{"yx"} if both axes are to be logarithmic.}
33
 
38167 maechler 34
  \item{main}{a main title for the plot, see also \code{\link{title}}.}
27442 ripley 35
  \item{sub}{a sub title for the plot.}
36110 ripley 36
  \item{xlab}{a label for the x axis, defaults to a description of \code{x}.}
37
  \item{ylab}{a label for the y axis, defaults to a description of \code{y}.}
27442 ripley 38
 
39
  \item{ann}{a logical value indicating whether the default annotation
40
    (title and x and y axis labels) should appear on the plot.}
36269 ripley 41
  \item{axes}{a logical value indicating whether both axes should be drawn on
42
    the plot.  Use graphical parameter \code{"xaxt"} or \code{"yaxt"}
43
    to suppress just one of the axes.}
27442 ripley 44
  \item{frame.plot}{a logical indicating whether a box should be drawn
45
    around the plot.}
46
 
47
  \item{panel.first}{an expression to be evaluated after the plot axes
48
    are set up but before any plotting takes place.  This can be useful
49
    for drawing background grids or scatterplot smooths.}
50
  \item{panel.last}{an expression to be evaluated after plotting has
51
    taken place.}
52
 
53
  \item{asp}{the \eqn{y/x} aspect ratio, see \code{\link{plot.window}}.}
38167 maechler 54
  \item{\dots}{other graphical parameters (see \code{\link{par}} and
55
    section \sQuote{Details} below).}
27442 ripley 56
}
36110 ripley 57
\details{
58
  Commonly used graphical parameters are:
59
  \describe{
60
    \item{\code{col}}{The colors for lines and points.  Multiple colors can be
61
      specified so that each point can be given its own color.  If there
62
      are fewer colors than points they are recycled in the standard
63
      fashion.  Lines will all be plotted in the first colour specified.}
64
    \item{\code{bg}}{a vector of background colors for open plot symbols, see
65
      \code{\link{points}}.  Note: this is \bold{not} the same setting
66
      as \code{\link{par}("bg")}.}
67
    \item{\code{pch}}{a vector of plotting characters or symbols:
68
      see \code{\link{points}}.}
69
    \item{\code{cex}}{a numerical vector giving the amount by which
70
      plotting text and symbols should be scaled relative to the
71
      default.  This works as a multiple of \code{\link{par}("cex")}.
72
      \code{NULL} and \code{NA} are equivalent to \code{1.0}.}
73
    \item{\code{lty}}{the line type, see \code{\link{par}}.}
38167 maechler 74
    \item{\code{cex.main, col.lab, font.sub}, etc}{settings for main- and
75
      sub-title and axis annotation, see \code{\link{title}} and
76
      \code{\link{par}}.}
36110 ripley 77
    \item{\code{lwd}}{the line width, see \code{\link{par}}.}
78
  }
79
}
27442 ripley 80
\references{
81
  Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
82
  \emph{The New S Language}.
83
  Wadsworth \& Brooks/Cole.
84
 
85
  Cleveland, W. S. (1985)
86
  \emph{The Elements of Graphing Data.}
87
  Monterey, CA: Wadsworth.
36222 ripley 88
 
89
  Murrell, P. (2005) \emph{R Graphics}. Chapman & Hall/CRC Press.
27442 ripley 90
}
91
\seealso{
92
  \code{\link{plot}}, \code{\link{plot.window}}, \code{\link{xy.coords}}.
93
}
94
\examples{
95
Speed <- cars$speed
96
Distance <- cars$dist
97
plot(Speed, Distance, panel.first = grid(8,8),
98
     pch = 0, cex = 1.2, col = "blue")
99
plot(Speed, Distance,
41502 ripley 100
     panel.first = lines(stats::lowess(Speed, Distance), lty = "dashed"),
27442 ripley 101
     pch = 0, cex = 1.2, col = "blue")
102
 
103
## Show the different plot types
104
x <- 0:12
105
y <- sin(pi/5 * x)
106
op <- par(mfrow = c(3,3), mar = .1+ c(2,2,3,1))
107
for (tp in c("p","l","b",  "c","o","h",  "s","S","n")) {
108
   plot(y ~ x, type = tp,
109
        main = paste("plot(*, type = \"",tp,"\")",sep=""))
110
   if(tp == "S") {
111
      lines(x,y, type = "s", col = "red", lty = 2)
112
      mtext("lines(*, type = \"s\", ...)", col = "red", cex=.8)
113
   }
114
}
115
par(op)
116
 
117
##--- Log-Log Plot  with  custom axes
118
lx <- seq(1,5, length=41)
119
yl <- expression(e^{-frac(1,2) * {log[10](x)}^2})
120
y <- exp(-.5*lx^2)
121
op <- par(mfrow=c(2,1), mar=par("mar")+c(0,1,0,0))
122
plot(10^lx, y, log="xy", type="l", col="purple",
123
     main="Log-Log plot", ylab=yl, xlab="x")
124
plot(10^lx, y, log="xy", type="o", pch='.', col="forestgreen",
125
     main="Log-Log plot with custom axes", ylab=yl, xlab="x",
126
     axes = FALSE, frame.plot = TRUE)
40660 ripley 127
my.at <- 10^(1:5)
128
axis(1, at = my.at, labels = formatC(my.at, format="fg"))
27442 ripley 129
at.y <- 10^(-5:-1)
130
axis(2, at = at.y, labels = formatC(at.y, format="fg"), col.axis="red")
131
par(op)
132
}
133
\keyword{hplot}