R: Generic X-Y Plotting (original) (raw)
plot {base} | R Documentation |
---|
Description
Generic function for plotting of R objects.
For simple scatter plots, [plot.default](../../graphics/html/plot.default.html)
will be used. However, there are plot
methods for many R objects, including [function](../../base/help/function.html)
s, [data.frame](../../base/help/data.frame.html)
s,[density](../../stats/html/density.html)
objects, etc. Use methods(plot)
and the documentation for these. Most of these methods are implemented using traditional graphics (the graphics package), but this is not mandatory.
For more details about graphical parameter arguments used by traditional graphics, see [par](../../graphics/html/par.html)
.
Usage
plot(x, y, ...)
Arguments
x | the coordinates of points in the plot. Alternatively, a single plotting structure, function or any R object with aplot method can be provided. |
---|---|
y | the y coordinates of points in the plot, _optional_if x is an appropriate structure. |
... | arguments to be passed to methods, such asgraphical parameters (see par). Many methods will accept the following arguments: typewhat type of plot should be drawn. Possible types are "p" for points, "l" for lines, "b" for both, "c" for the lines part alone of "b", "o" for both ‘overplotted’, "h" for ‘histogram’ like (or ‘high-density’) vertical lines, "s" for stair steps, "S" for other steps, see ‘Details’ below, "n" for no plotting. All other types give a warning or an error; using, e.g.,type = "punkte" being equivalent to type = "p" for S compatibility. Note that some methods, e.g. plot.factor, do not accept this. mainan overall title for the plot: see title. suba subtitle for the plot: see title. xlaba title for the x axis: see title. ylaba title for the y axis: see title. aspthe y/x aspect ratio, see plot.window. |
Details
The two step types differ in their x-y preference: Going from(x1,y1)
to (x2,y2)
with x1 < x2
, type = "s"
moves first horizontal, then vertical, whereas type = "S"
moves the other way around.
Note
The plot
generic was moved from the graphics package to the base package in R 4.0.0. It is currently re-exported from the graphics namespace to allow packages importing it from there to continue working, but this may change in future versions of R.
See Also
[plot.default](../../graphics/html/plot.default.html)
, [plot.formula](../../graphics/html/plot.formula.html)
and other methods; [points](../../graphics/html/points.html)
, [lines](../../graphics/html/lines.html)
, [par](../../graphics/html/par.html)
. For thousands of points, consider using [smoothScatter](../../graphics/html/smoothScatter.html)()
instead of plot()
.
For X-Y-Z plotting see [contour](../../graphics/html/contour.html)
, [persp](../../graphics/html/persp.html)
and[image](../../graphics/html/image.html)
.
Examples
require(stats) # for lowess, rpois, rnorm
require(graphics) # for plot methods
plot(cars)
lines(lowess(cars))
plot(sin, -pi, 2*pi) # see ?plot.function
## Discrete Distribution Plot:
plot(table(rpois(100, 5)), type = "h", col = "red", lwd = 10,
main = "rpois(100, lambda = 5)")
## Simple quantiles/ECDF, see ecdf() {library(stats)} for a better one:
plot(x <- sort(rnorm(47)), type = "s", main = "plot(x, type = \"s\")")
points(x, cex = .5, col = "dark red")
[Package _base_ version 4.6.0 Index]