polygon  R Documentation 
polygon
draws the polygons whose vertices are
given in x
and y
.
polygon(x, y = NULL, density = NULL, angle = 45, border = NULL, col = NA, lty = par("lty"), ..., fillOddEven = FALSE)
x, y 
vectors containing the coordinates of the vertices of the polygon. 
density 
the density of shading lines, in lines per inch. The
default value of 
angle 
the slope of shading lines, given as an angle in degrees (counterclockwise). 
col 
the color for filling the polygon. The default,

border 
the color to draw the border. The default, For compatibility with S, 
lty 
the line type to be used, as in 
... 
graphical parameters such as 
fillOddEven 
logical controlling the polygon shading mode: see
below for details. Default 
The coordinates can be passed in a plotting structure
(a list with x
and y
components), a twocolumn matrix,
.... See xy.coords
.
It is assumed that the polygon is to be closed by joining the last point to the first point.
The coordinates can contain missing values. The behaviour is similar
to that of lines
, except that instead of breaking a line
into several lines, NA
values break the polygon into several
complete polygons (including closing the last point to the first
point). See the examples below.
When multiple polygons are produced, the values of density
,
angle
, col
, border
, and lty
are recycled
in the usual manner.
Shading of polygons is only implemented for linear plots: if either axis is on log scale then shading is omitted, with a warning.
Selfintersecting polygons may be filled using either the
“oddeven” or “nonzero” rule. These fill a region if
the polygon border encircles it an odd or nonzero number of times,
respectively. Shading lines are handled internally by R according
to the fillOddEven
argument, but devicebased solid fills
depend on the graphics device. The windows
, pdf
and postscript
devices have their own fillOddEven
argument to control this.
The code implementing polygon shading was donated by Kevin Buhr buhr@stat.wisc.edu.
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
Murrell, P. (2005) R Graphics. Chapman & Hall/CRC Press.
segments
for even more flexibility, lines
,
rect
, box
, abline
.
par
for how to specify colors.
x < c(1:9, 8:1) y < c(1, 2*(5:3), 2, 1, 17, 9, 8, 2:9) op < par(mfcol = c(3, 1)) for(xpd in c(FALSE, TRUE, NA)) { plot(1:10, main = paste("xpd =", xpd)) box("figure", col = "pink", lwd = 3) polygon(x, y, xpd = xpd, col = "orange", lty = 2, lwd = 2, border = "red") } par(op) n < 100 xx < c(0:n, n:0) yy < c(c(0, cumsum(stats::rnorm(n))), rev(c(0, cumsum(stats::rnorm(n))))) plot (xx, yy, type = "n", xlab = "Time", ylab = "Distance") polygon(xx, yy, col = "gray", border = "red") title("Distance Between Brownian Motions") # Multiple polygons from NA values # and recycling of col, border, and lty op < par(mfrow = c(2, 1)) plot(c(1, 9), 1:2, type = "n") polygon(1:9, c(2,1,2,1,1,2,1,2,1), col = c("red", "blue"), border = c("green", "yellow"), lwd = 3, lty = c("dashed", "solid")) plot(c(1, 9), 1:2, type = "n") polygon(1:9, c(2,1,2,1,NA,2,1,2,1), col = c("red", "blue"), border = c("green", "yellow"), lwd = 3, lty = c("dashed", "solid")) par(op) # Lineshaded polygons plot(c(1, 9), 1:2, type = "n") polygon(1:9, c(2,1,2,1,NA,2,1,2,1), density = c(10, 20), angle = c(45, 45))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.