The R Project SVN R

Rev

Rev 61168 | Rev 67599 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42333 ripley 1
% File src/library/graphics/man/plotdefault.Rd
2
% Part of the R package, http://www.R-project.org
59039 ripley 3
% Copyright 1995-2012 R Core Team
42333 ripley 4
% Distributed under GPL 2 or later
5
 
27442 ripley 6
\name{plot.default}
56186 murdoch 7
\alias{plot.default}
27442 ripley 8
\title{The Default Scatterplot Function}
9
\description{
42961 ripley 10
  Draw a scatter plot with decorations such as axes and titles
27442 ripley 11
  in the active graphics window.
12
}
13
\usage{
14
\method{plot}{default}(x, y = NULL, type = "p",  xlim = NULL, ylim = NULL,
15
     log = "", main = NULL, sub = NULL, xlab = NULL, ylab = NULL,
16
     ann = par("ann"), axes = TRUE, frame.plot = axes,
36110 ripley 17
     panel.first = NULL, panel.last = NULL, asp = NA, \dots)
27442 ripley 18
}
19
\arguments{
36110 ripley 20
  \item{x, y}{the \code{x} and \code{y} arguments provide the x and y
27442 ripley 21
    coordinates for the plot.  Any reasonable way of defining the
22
    coordinates is acceptable.  See the function \code{\link{xy.coords}}
45364 ripley 23
    for details.  If supplied separately, they must be of the same length.}
27442 ripley 24
  \item{type}{1-character string giving the type of plot desired.  The
25
    following values are possible, for details, see \code{\link{plot}}:
26
    \code{"p"} for points, \code{"l"} for lines,
58047 murdoch 27
    \code{"b"} for both points and lines,
61433 ripley 28
    \code{"c"} for empty points joined by lines,
27442 ripley 29
    \code{"o"} for overplotted points and lines,
30
    \code{"s"} and \code{"S"} for stair steps and
31
    \code{"h"} for histogram-like vertical lines.  Finally,
32
    \code{"n"} does not produce any points or lines.}
39607 ripley 33
  \item{xlim}{the x limits (x1, x2) of the plot.  Note that \code{x1 > x2}
56108 ripley 34
    is allowed and leads to a \sQuote{reversed axis}.
35
 
36
    The default value, \code{NULL}, indicates that the range of the
37
    \link{finite} values to be plotted should be used.}
27442 ripley 38
  \item{ylim}{the y limits of the plot.}
39
  \item{log}{a character string which contains \code{"x"} if the x axis
40
    is to be logarithmic, \code{"y"} if the y axis is to be logarithmic
41
    and \code{"xy"} or \code{"yx"} if both axes are to be logarithmic.}
42
 
38167 maechler 43
  \item{main}{a main title for the plot, see also \code{\link{title}}.}
27442 ripley 44
  \item{sub}{a sub title for the plot.}
36110 ripley 45
  \item{xlab}{a label for the x axis, defaults to a description of \code{x}.}
46
  \item{ylab}{a label for the y axis, defaults to a description of \code{y}.}
27442 ripley 47
 
48
  \item{ann}{a logical value indicating whether the default annotation
49
    (title and x and y axis labels) should appear on the plot.}
36269 ripley 50
  \item{axes}{a logical value indicating whether both axes should be drawn on
56113 ripley 51
    the plot.  Use \link{graphical parameter} \code{"xaxt"} or \code{"yaxt"}
36269 ripley 52
    to suppress just one of the axes.}
27442 ripley 53
  \item{frame.plot}{a logical indicating whether a box should be drawn
54
    around the plot.}
55
 
56108 ripley 56
  \item{panel.first}{an \sQuote{expression} to be evaluated after the
57
    plot axes are set up but before any plotting takes place.  This can
58
    be useful for drawing background grids or scatterplot smooths.  Note
59
    that this works by lazy evaluation: passing this argument from other
55983 ripley 60
    \code{plot} methods may well not work since it may be evaluated too
61
    early.}
61433 ripley 62
 
27442 ripley 63
  \item{panel.last}{an expression to be evaluated after plotting has
56010 hornik 64
    taken place but before the axes, title and box are added.  See the
56108 ripley 65
    comments about \code{panel.first}.}
27442 ripley 66
 
67
  \item{asp}{the \eqn{y/x} aspect ratio, see \code{\link{plot.window}}.}
56113 ripley 68
  \item{\dots}{other \link{graphical parameters} (see \code{\link{par}} and
38167 maechler 69
    section \sQuote{Details} below).}
27442 ripley 70
}
36110 ripley 71
\details{
56113 ripley 72
  Commonly used \link{graphical parameters} are:
36110 ripley 73
  \describe{
74
    \item{\code{col}}{The colors for lines and points.  Multiple colors can be
75
      specified so that each point can be given its own color.  If there
76
      are fewer colors than points they are recycled in the standard
77
      fashion.  Lines will all be plotted in the first colour specified.}
78
    \item{\code{bg}}{a vector of background colors for open plot symbols, see
79
      \code{\link{points}}.  Note: this is \bold{not} the same setting
80
      as \code{\link{par}("bg")}.}
81
    \item{\code{pch}}{a vector of plotting characters or symbols:
82
      see \code{\link{points}}.}
83
    \item{\code{cex}}{a numerical vector giving the amount by which
45975 ripley 84
      plotting characters and symbols should be scaled relative to the
36110 ripley 85
      default.  This works as a multiple of \code{\link{par}("cex")}.
45975 ripley 86
      \code{NULL} and \code{NA} are equivalent to \code{1.0}.  Note that
87
      this does not affect annotation: see below.}
59510 ripley 88
    \item{\code{lty}}{a vector of line types, see \code{\link{par}}.}
49612 hornik 89
    \item{\code{cex.main}, \code{col.lab}, \code{font.sub},
90
      etc}{settings for main- and sub-title and axis annotation, see
91
      \code{\link{title}} and \code{\link{par}}.}
59510 ripley 92
    \item{\code{lwd}}{a vector of line widths, see \code{\link{par}}.}
36110 ripley 93
  }
94
}
58321 ripley 95
\note{
96
  The presence of \code{panel.first} and \code{panel.last} is a
97
  historical anomaly: default plots do not have \sQuote{panels}, unlike
98
  e.g. \code{\link{pairs}} plots.  For more control, use lower-level
99
  plotting functions: \code{plot.default} calls in turn some of
100
  \code{\link{plot.new}}, \code{\link{plot.window}},
101
  \code{\link{plot.xy}}, \code{\link{axis}}, \code{\link{box}} and
102
  \code{\link{title}}, and plots can be built up by calling these
103
  individually, or by calling \code{plot(type = "n")} and adding further
104
  elements.
105
}
106
 
27442 ripley 107
\references{
108
  Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
109
  \emph{The New S Language}.
47262 ripley 110
  Wadsworth & Brooks/Cole.
27442 ripley 111
 
112
  Cleveland, W. S. (1985)
113
  \emph{The Elements of Graphing Data.}
114
  Monterey, CA: Wadsworth.
36222 ripley 115
 
116
  Murrell, P. (2005) \emph{R Graphics}. Chapman & Hall/CRC Press.
27442 ripley 117
}
118
\seealso{
119
  \code{\link{plot}}, \code{\link{plot.window}}, \code{\link{xy.coords}}.
120
}
121
\examples{
122
Speed <- cars$speed
123
Distance <- cars$dist
61168 ripley 124
plot(Speed, Distance, panel.first = grid(8, 8),
27442 ripley 125
     pch = 0, cex = 1.2, col = "blue")
126
plot(Speed, Distance,
41502 ripley 127
     panel.first = lines(stats::lowess(Speed, Distance), lty = "dashed"),
27442 ripley 128
     pch = 0, cex = 1.2, col = "blue")
129
 
130
## Show the different plot types
131
x <- 0:12
132
y <- sin(pi/5 * x)
133
op <- par(mfrow = c(3,3), mar = .1+ c(2,2,3,1))
134
for (tp in c("p","l","b",  "c","o","h",  "s","S","n")) {
61156 ripley 135
   plot(y ~ x, type = tp, main = paste0("plot(*, type = \"", tp, "\")"))
27442 ripley 136
   if(tp == "S") {
61168 ripley 137
      lines(x, y, type = "s", col = "red", lty = 2)
61156 ripley 138
      mtext("lines(*, type = \"s\", ...)", col = "red", cex = 0.8)
27442 ripley 139
   }
140
}
141
par(op)
142
 
143
##--- Log-Log Plot  with  custom axes
61168 ripley 144
lx <- seq(1, 5, length = 41)
27442 ripley 145
yl <- expression(e^{-frac(1,2) * {log[10](x)}^2})
146
y <- exp(-.5*lx^2)
61153 ripley 147
op <- par(mfrow = c(2,1), mar = par("mar")+c(0,1,0,0))
148
plot(10^lx, y, log = "xy", type = "l", col = "purple",
149
     main = "Log-Log plot", ylab = yl, xlab = "x")
61168 ripley 150
plot(10^lx, y, log = "xy", type = "o", pch = ".", col = "forestgreen",
61153 ripley 151
     main = "Log-Log plot with custom axes", ylab = yl, xlab = "x",
27442 ripley 152
     axes = FALSE, frame.plot = TRUE)
40660 ripley 153
my.at <- 10^(1:5)
61153 ripley 154
axis(1, at = my.at, labels = formatC(my.at, format = "fg"))
27442 ripley 155
at.y <- 10^(-5:-1)
61153 ripley 156
axis(2, at = at.y, labels = formatC(at.y, format = "fg"), col.axis = "red")
27442 ripley 157
par(op)
158
}
159
\keyword{hplot}