polygon                 package:base                 R Documentation

_P_o_l_y_g_o_n _D_r_a_w_i_n_g

_D_e_s_c_r_i_p_t_i_o_n:

     `polygon' draws the polygons whose vertices are given in `x' and
     `y'.

_U_s_a_g_e:

     polygon(x, y = NULL, density = NULL, angle = 45,
             border = NULL, col = NA, lty = NULL, xpd = NULL, ...)

_A_r_g_u_m_e_n_t_s:

     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 `NULL' means that no shading lines are drawn.
          Non-positive values of `density' also inhibit the drawing of
          shading lines.

   angle: the slope of shading lines, given as an angle in degrees
          (counter-clockwise).

     col: the color for filling the polygon. The default, `NA', is to
          leave polygons unfilled.

  border: the color to draw the border.  The default, `NULL', uses
          `par("fg")'.  Use `border=0' to omit borders.

     lty: the line type to be used, as in `par'.

     xpd: (where) should clipping take place?  Defaults to
          `par("xpd")'.

     ...: graphical parameters can be given as arguments to `polygon'.

_D_e_t_a_i_l_s:

     The coordinates can be passed in a plotting structure (a list with
     `x' and `y' components), a two-column matrix, ....  See
     `xy.coords'.

     It is assumed that the polygon is 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.

_B_u_g_s:

     The present shading algorithm can produce incorrect results for
     self-intesecting polygons.

_A_u_t_h_o_r(_s):

     The code implementing polygon shading was donated by Kevin Buhr
     buhr@stat.wisc.edu.

_S_e_e _A_l_s_o:

     `segments' for even more flexibility, `lines', `rect', `box',
     `abline'.

_E_x_a_m_p_l_e_s:

     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(rnorm(n))), rev(c(0,cumsum(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)

     # Line-shaded 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))

