
Last chance! 50% off unlimited learning
Sale ends in
"plot"(x, y = NULL, type = "p", xlim = NULL, ylim = NULL, log = "", main = NULL, sub = NULL, xlab = NULL, ylab = NULL, ann = par("ann"), axes = TRUE, frame.plot = axes, panel.first = NULL, panel.last = NULL, asp = NA, ...)
x
and y
arguments provide the x and y
coordinates for the plot. Any reasonable way of defining the
coordinates is acceptable. See the function xy.coords
for details. If supplied separately, they must be of the same length.plot
:
"p"
for points, "l"
for lines,
"b"
for both points and lines,
"c"
for empty points joined by lines,
"o"
for overplotted points and lines,
"s"
and "S"
for stair steps and
"h"
for histogram-like vertical lines. Finally,
"n"
does not produce any points or lines.x1 > x2
is allowed and leads to a ‘reversed axis’. The default value, NULL
, indicates that the range of the
finite values to be plotted should be used.
"x"
if the x axis
is to be logarithmic, "y"
if the y axis is to be logarithmic
and "xy"
or "yx"
if both axes are to be logarithmic.title
.x
.y
."xaxt"
or "yaxt"
to suppress just one of the axes.plot
methods may well not work since it may be evaluated too
early.panel.first
.plot.window
.par
and
section ‘Details’ below).col
bg
points
. Note: this is not the same setting
as par("bg")
.
pch
points
.
cex
par("cex")
.
NULL
and NA
are equivalent to 1.0
. Note that
this does not affect annotation: see below.
lty
par
.
cex.main
, col.lab
, font.sub
,
etctitle
and par
.
lwd
par
.
Cleveland, W. S. (1985) The Elements of Graphing Data. Monterey, CA: Wadsworth.
Murrell, P. (2005) R Graphics. Chapman & Hall/CRC Press.
plot
, plot.window
, xy.coords
.
Speed <- cars$speed
Distance <- cars$dist
plot(Speed, Distance, panel.first = grid(8, 8),
pch = 0, cex = 1.2, col = "blue")
plot(Speed, Distance,
panel.first = lines(stats::lowess(Speed, Distance), lty = "dashed"),
pch = 0, cex = 1.2, col = "blue")
## Show the different plot types
x <- 0:12
y <- sin(pi/5 * x)
op <- par(mfrow = c(3,3), mar = .1+ c(2,2,3,1))
for (tp in c("p","l","b", "c","o","h", "s","S","n")) {
plot(y ~ x, type = tp, main = paste0("plot(*, type = \"", tp, "\")"))
if(tp == "S") {
lines(x, y, type = "s", col = "red", lty = 2)
mtext("lines(*, type = \"s\", ...)", col = "red", cex = 0.8)
}
}
par(op)
##--- Log-Log Plot with custom axes
lx <- seq(1, 5, length = 41)
yl <- expression(e^{-frac(1,2) * {log[10](x)}^2})
y <- exp(-.5*lx^2)
op <- par(mfrow = c(2,1), mar = par("mar")+c(0,1,0,0))
plot(10^lx, y, log = "xy", type = "l", col = "purple",
main = "Log-Log plot", ylab = yl, xlab = "x")
plot(10^lx, y, log = "xy", type = "o", pch = ".", col = "forestgreen",
main = "Log-Log plot with custom axes", ylab = yl, xlab = "x",
axes = FALSE, frame.plot = TRUE)
my.at <- 10^(1:5)
axis(1, at = my.at, labels = formatC(my.at, format = "fg"))
at.y <- 10^(-5:-1)
axis(2, at = at.y, labels = formatC(at.y, format = "fg"), col.axis = "red")
par(op)
Run the code above in your browser using DataLab