The R Project SVN R

Rev

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

Rev Author Line No. Line
77912 deepayan 1
% File src/library/base/man/plot.Rd
2
% (Previously src/library/graphics/man/plot.Rd for R < 4.0.0)
68948 ripley 3
% Part of the R package, https://www.R-project.org
77912 deepayan 4
% Copyright 1995-2020 R Core Team
42333 ripley 5
% Distributed under GPL 2 or later
6
 
27442 ripley 7
\name{plot}
8
\title{Generic X-Y Plotting}
56186 murdoch 9
\alias{plot}
56562 maechler 10
\description{
77912 deepayan 11
  Generic function for plotting of \R objects.
56562 maechler 12
 
13
  For simple scatter plots, \code{\link{plot.default}} will be used.
14
  However, there are \code{plot} methods for many \R objects,
15
  including \code{\link{function}}s, \code{\link{data.frame}}s,
16
  \code{\link{density}} objects, etc.  Use \code{methods(plot)} and
77912 deepayan 17
  the documentation for these. Most of these methods are implemented
18
  using traditional graphics (the \pkg{graphics} package), but this is
19
  not mandatory.
20
 
21
  For more details about graphical parameter arguments used by
22
  traditional graphics, see \code{\link{par}}.
56562 maechler 23
}
27442 ripley 24
\usage{
25
plot(x, y, \dots)
26
}
27
\arguments{
28
  \item{x}{the coordinates of points in the plot. Alternatively, a
29
      single plotting structure, function or \emph{any \R object with a
38888 ripley 30
        \code{plot} method} can be provided.}
27442 ripley 31
  \item{y}{the y coordinates of points in the plot, \emph{optional}
38888 ripley 32
    if \code{x} is an appropriate structure.}
85065 smeyer 33
  \item{\dots}{arguments to be passed to methods, such as
56113 ripley 34
    \link{graphical parameters} (see \code{\link{par}}).
38888 ripley 35
    Many methods will accept the following arguments:
46908 murdoch 36
    \describe{
36139 ripley 37
    \item{\code{type}}{what type of plot should be drawn.  Possible types are
27442 ripley 38
      \itemize{
47621 ripley 39
        \item \code{"p"} for \bold{p}oints,
40
        \item \code{"l"} for \bold{l}ines,
41
        \item \code{"b"} for \bold{b}oth,
42
        \item \code{"c"} for the lines part alone of \code{"b"},
43
        \item \code{"o"} for both \sQuote{\bold{o}verplotted},
44
        \item \code{"h"} for \sQuote{\bold{h}istogram} like (or
45
        \sQuote{high-density}) vertical lines,
46
        \item \code{"s"} for stair \bold{s}teps,
47
        \item \code{"S"} for other \bold{s}teps, see \sQuote{Details} below,
48
        \item \code{"n"} for no plotting.
27442 ripley 49
      }
50
      All other \code{type}s give a warning or an error; using, e.g.,
51
      \code{type = "punkte"} being equivalent to \code{type = "p"} for S
48610 ripley 52
      compatibility.  Note that some methods,
66444 hornik 53
      e.g.\sspace{}\code{\link{plot.factor}}, do not accept this.
27442 ripley 54
    }
36139 ripley 55
    \item{\code{main}}{an overall title for the plot: see \code{\link{title}}.}
81315 smeyer 56
    \item{\code{sub}}{a subtitle for the plot: see \code{\link{title}}.}
36139 ripley 57
    \item{\code{xlab}}{a title for the x axis: see \code{\link{title}}.}
58
    \item{\code{ylab}}{a title for the y axis: see \code{\link{title}}.}
38888 ripley 59
    \item{\code{asp}}{the \eqn{y/x} aspect ratio,
60
      see \code{\link{plot.window}}.}
46908 murdoch 61
    }
27442 ripley 62
  }
63
}
64
\details{
65
  The two step types differ in their x-y preference: Going from
66
  \eqn{(x1,y1)} to \eqn{(x2,y2)} with \eqn{x1 < x2}, \code{type = "s"}
67
  moves first horizontal, then vertical, whereas \code{type = "S"} moves
68
  the other way around.
69
}
77912 deepayan 70
\note{
71
  The \code{plot} generic was moved from the \pkg{graphics} package to
72
  the \pkg{base} package in \R 4.0.0. It is currently re-exported from
73
  the \pkg{graphics} namespace to allow packages importing it from there
74
  to continue working, but this may change in future versions of \R.
75
}
27442 ripley 76
\seealso{
77
  \code{\link{plot.default}}, \code{\link{plot.formula}} and other
78
  methods; \code{\link{points}}, \code{\link{lines}}, \code{\link{par}}.
68988 maechler 79
  For thousands of points, consider using \code{\link{smoothScatter}()}
80
  instead of \code{plot()}.
56562 maechler 81
 
51681 ripley 82
  For X-Y-Z plotting see \code{\link{contour}}, \code{\link{persp}} and
83
  \code{\link{image}}.
27442 ripley 84
}
85
\examples{
67689 ripley 86
require(stats) # for lowess, rpois, rnorm
77912 deepayan 87
require(graphics) # for plot methods
27442 ripley 88
plot(cars)
89
lines(lowess(cars))
90
 
56562 maechler 91
plot(sin, -pi, 2*pi) # see ?plot.function
27442 ripley 92
 
93
## Discrete Distribution Plot:
61168 ripley 94
plot(table(rpois(100, 5)), type = "h", col = "red", lwd = 10,
95
     main = "rpois(100, lambda = 5)")
27442 ripley 96
 
27653 maechler 97
## Simple quantiles/ECDF, see ecdf() {library(stats)} for a better one:
27442 ripley 98
plot(x <- sort(rnorm(47)), type = "s", main = "plot(x, type = \"s\")")
99
points(x, cex = .5, col = "dark red")
100
}
101
\keyword{hplot}