Description Usage Arguments Details
This function can be used to add legends to plots. Note that a call
to the function locator(1)
can be used in place of the x
and y
arguments.
1 2 3 4 5 6 7 8 9 | legend(x, y = NULL, legend, fill = NULL, col = par("col"),
border = "black", lty, lwd, pch, angle = 45, density = NULL,
bty = "o", bg = par("bg"), box.lwd = par("lwd"), box.lty = par("lty"),
box.col = par("fg"), pt.bg = NA, cex = 1, pt.cex = cex,
pt.lwd = lwd, xjust = 0, yjust = 1, x.intersp = 1, y.intersp = 1,
adj = c(0, 0.5), text.width = NULL, text.col = par("col"),
merge = do.lines && has.pch, trace = FALSE, plot = TRUE, ncol = 1,
horiz = FALSE, title = NULL, inset = 0, xpd, title.col = text.col,
title.adj = 0.5, seg.len = 2)
|
x |
the x coordinates to be used to position the legend. |
y |
the y coordinates to be used to position the legend.
|
legend |
a character or expression vector.
of length >= 1 to appear in the legend. Other
objects will be coerced by |
fill |
if specified, this argument will cause boxes filled with the specified colors (or shaded in the specified colors) to appear beside the legend text. |
col |
the color of points or lines appearing in the legend. |
border |
the border color for the boxes (used only if |
lty |
the line types for lines appearing in the legend. |
lwd |
the line widths for lines appearing in the legend.
One of |
pch |
the plotting symbols appearing in the legend, either as vector of 1-character strings, or one (multi character) string. Must be specified for symbol drawing. |
angle |
angle of shading lines. |
density |
the density of shading lines, if numeric and
positive. If |
bty |
the type of box to be drawn around the legend. The allowed
values are |
bg |
the background color for the legend box. (Note that this is
only used if |
box.lwd |
the line type for the legend box. |
box.lty |
the line width for the legend box. |
box.col |
the color for the legend box. |
pt.bg |
the background color for the |
cex |
character expansion factor relative to current
|
pt.cex |
expansion factor(s) for the points. |
pt.lwd |
line width for the points, defaults to the one for
lines, or if that is not set, to |
xjust |
how the legend is to be justified relative to the legend x location. A value of 0 means left justified, 0.5 means centered and 1 means right justified. |
yjust |
the same as |
x.intersp |
character interspacing factor for horizontal (x) spacing. |
y.intersp |
the same for vertical (y) line distances. |
adj |
numeric of length 1 or 2; the string adjustment for legend
text. Useful for y-adjustment when |
text.width |
the width of the legend text in x ( |
text.col |
the color used for the legend text. |
merge |
logical; if |
trace |
logical; if |
plot |
logical. If |
ncol |
the number of columns in which to set the legend items (default is 1, a vertical legend). |
horiz |
logical; if |
title |
a character string or length-one expression giving a
title to be placed at the top of the legend. Other objects will be
coerced by |
inset |
inset distance(s) from the margins as a fraction of the plot region when legend is placed by keyword. |
xpd |
if supplied, a value of the graphical parameter 'xpd' to be used while the legend is being drawn. |
title.col |
color for |
title.adj |
horizontal adjustment for |
seg.len |
the length of lines drawn to illustrate |
see legend
in package:graphics for details;
Note: Old versions of graphics:::legend do not have ‘border’ option.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.