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
can be either a logical flag or the color to be used as the border of the ploygon. If border=T, the default is "#000000" (black). If border is a numeric value, it is the index into a color palette. If the color is given as a string, it must be either an RGB value, an RGBA value, or a color name. Refer to the Color Specification section in the "Guide to Packages" for more information.
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 ).

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. The graphsheet window has a limit of about 16,000 vertices. Some PostScript printers have a limit of about 1,500 vertices.

SEE ALSO:

, , ,

EXAMPLES:

# set up to create two by two display on page
par(mfrow=c(2,2))

# read graphic input, draw and shade polygon 
# click around on graphsheet, then double click off
# graph area to see the polygon made
plot(1:10, 1:10, type="n")
polygon(locator(type="l")) 

# shade the area between lines 
plot(-1:10, -1:10, type="n") 
polygon(c(0,5,7,2), c(2,7,5,0)) 

# two polygons px1,py1 and px2,py2 separated by 'NA's 
plot(1:5, 1:5, type="n") 
px1 <- c(1,2,2,1)
px2 <- c(4,5,5,4)
py1 <- c(1,1,2,2)
py2 <- c(3,3,4,4)
polygon( c(px1,NA,px2), c(py1,NA,py2), col=3:4) 

# abstract art
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))