The R Project SVN R

Rev

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