polygon(x, y, density=-1, angle=45, border=T, col=par("col"))
i
th point is connected to the
i+1
st.
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 (
NA
s) are allowed and signify breaks between polygons.
density
is zero, no shading will occur.
If
density
is negative, the polygon will be filled solidly
using the device-dependent
polygon filling algorithm.
This is a generic function; currently, there is only a default method.
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.
# 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))