Shade in a Polygonal Figure

DESCRIPTION:
Adds a polygon with the specified vertices to the current plot.

USAGE:
polygon(x, y, density=-1, angle=45, border=T, col=par("col"))

REQUIRED ARGUMENTS:
x,y:
coordinates of the vertices of a polygon, listed in order, i.e., the ith point is connected to the i+1st. It is assumed the polygon closes by joining the last point to the first. A structure containing components x and y can also be given. Missing values (NAs) are allowed and signify breaks between polygons.

OPTIONAL ARGUMENTS:
density:
density of shading lines in lines per inch. If density is zero, no shading will occur. If density is negative, the polygon will be filled solidly using the device-dependent polygon filling algorithm.
angle:
angle of shading lines in degrees measured counterclockwise from horizontal.
border:
logical flag: should the border of the polygonal region be drawn?
col:
integer vector giving the color(s) in which to plot the polygons. This is used cyclically, moving to a new color whenever a break between polygons is detected.

Graphical parameters may also be supplied as arguments to this function (see par).


SIDE EFFECTS:
The polygon is added to the current plot.

DETAILS:
This is a generic function; currently, there is only a default method.

WARNING:
Some graphics devices impose a limit on the number of vertices there can be in a polygon. Some PostScript printers, for instance, have a limit of about 1500 vertices.

The Windows devices (win.graph, win.printer) in S-PLUS for Windows will look for a "MaxVertices" entry in the [Workarounds] section of the SPLUS.INI file for the limit to use. This limit has a max of about 16,000, but many devices have much lower limits. That entry may require some tuning for your particular printer device.


SEE ALSO:
segments , lines , par .

EXAMPLES:
  # read graphic input, draw and shade polygon
polygon(locator(type="l"))

# shade the area between lines x1,y1 and x2,y2 polygon( c(x1,rev(x2)), c(y1,rev(y2)) )

# two polygons px1,py1 and px2,py2 separated by NAs polygon( c(px1,NA,px2), c(py1,NA,py2), col=3:4)

# an abstract art show dev.ask() for (i in 1:20) { plot(type="n",xlim=c(0,20),ylim=c(0,20),1:4,axes=F,ylab="",xlab="") polygon(sample(20,40,replace=T),sample(20,40,replace=T))}