The R Project SVN R

Rev

Rev 88581 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
52406 murrell 1
% File src/library/graphics/man/path.Rd
68948 ripley 2
% Part of the R package, https://www.R-project.org
59039 ripley 3
% Copyright 1995-2011 R Core Team
52406 murrell 4
% Distributed under GPL 2 or later
5
 
6
\name{polypath}
56186 murdoch 7
\alias{polypath}
52406 murrell 8
\title{Path Drawing}
9
\description{
10
  \code{path} draws a path whose vertices are
11
  given in \code{x} and \code{y}.
12
}
13
\usage{
61433 ripley 14
polypath(x, y = NULL,
52406 murrell 15
         border = NULL, col = NA, lty = par("lty"),
16
         rule = "winding", \dots)
17
}
18
\arguments{
61168 ripley 19
  \item{x, y}{vectors containing the coordinates of the vertices
52406 murrell 20
    of the path.}
21
   \item{col}{the color for filling the path. The default,
79580 murrell 22
     \code{NA}, is to leave paths unfilled.}
52406 murrell 23
  \item{border}{the color to draw the border.  The default, \code{NULL},
24
    means to use \code{\link{par}("fg")}.  Use \code{border = NA} to
25
    omit borders.
61433 ripley 26
 
52406 murrell 27
    For compatibility with S, \code{border} can also be logical, in
28
    which case \code{FALSE} is equivalent to \code{NA} (borders omitted)
29
    and \code{TRUE} is equivalent to \code{NULL} (use the foreground colour),
30
  }
31
  \item{lty}{the line type to be used, as in \code{\link{par}}.}
32
  \item{rule}{character value specifying the path fill mode: either
61433 ripley 33
    \code{"winding"} or \code{"evenodd"}.}
56113 ripley 34
  \item{\dots}{\link{graphical parameters} such as \code{xpd}, \code{lend},
52406 murrell 35
    \code{ljoin} and \code{lmitre} can be given as arguments.}
36
}
37
\details{
38
  The coordinates can be passed in a plotting structure
39
  (a list with \code{x} and \code{y} components), a two-column matrix,
40
  \dots.  See \code{\link{xy.coords}}.
41
 
42
  It is assumed that the path is to be closed by joining the last point to
43
  the first point.
61433 ripley 44
 
52406 murrell 45
  The coordinates can contain missing values.  The behaviour is similar
56846 ripley 46
  to that of \code{\link{polygon}}, except that instead of breaking a
47
  polygon into several polygons, \code{NA} values break the path into
48
  several sub-paths (including closing the last point to the first point
49
  in each sub-path).  See the examples below.
52406 murrell 50
 
51
  The distinction between a path and a polygon is that the former
52
  can contain holes, as interpreted by the fill rule; these fill a region if
53
  the path border encircles it an odd or non-zero number of times,
54
  respectively.
61433 ripley 55
 
52406 murrell 56
  Hatched shading (as implemented for \code{polygon()}) is not
57
  (currently) supported.
61433 ripley 58
 
56846 ripley 59
  Not all graphics devices support this function: for example
60
  \code{xfig} and \code{pictex} do not.
52406 murrell 61
}
62
\references{
88581 hornik 63
  \bibshow{R:Becker+Chambers+Wilks:1988}
52406 murrell 64
 
88585 hornik 65
  \bibshow{R:Murrell:2005}
52406 murrell 66
}
67
\seealso{
68
  \code{\link{segments}} for even more flexibility, \code{\link{lines}},
69
  \code{\link{rect}}, \code{\link{box}}, \code{\link{polygon}}.
70
 
71
  \code{\link{par}} for how to specify colors.
72
}
73
\examples{
56280 ripley 74
plotPath <- function(x, y, col = "grey", rule = "winding") {
52406 murrell 75
    plot.new()
56280 ripley 76
    plot.window(range(x, na.rm = TRUE), range(y, na.rm = TRUE))
77
    polypath(x, y, col = col, rule = rule)
52406 murrell 78
    if (!is.na(col))
56280 ripley 79
        mtext(paste("Rule:", rule), side = 1, line = 0)
52406 murrell 80
}
81
 
82
plotRules <- function(x, y, title) {
83
    plotPath(x, y)
56280 ripley 84
    plotPath(x, y, rule = "evenodd")
85
    mtext(title, side = 3, line = 0)
86
    plotPath(x, y, col = NA)
52406 murrell 87
}
88
 
56280 ripley 89
op <- par(mfrow = c(5, 3), mar = c(2, 1, 1, 1))
52406 murrell 90
 
91
plotRules(c(.1, .1, .9, .9, NA, .2, .2, .8, .8),
92
          c(.1, .9, .9, .1, NA, .2, .8, .8, .2),
56280 ripley 93
          "Nested rectangles, both clockwise")
94
plotRules(c(.1, .1, .9, .9, NA, .2, .8, .8, .2),
95
          c(.1, .9, .9, .1, NA, .2, .2, .8, .8),
96
          "Nested rectangles, outer clockwise, inner anti-clockwise")
97
plotRules(c(.1, .1, .4, .4, NA, .6, .9, .9, .6),
98
          c(.1, .4, .4, .1, NA, .6, .6, .9, .9),
99
          "Disjoint rectangles")
100
plotRules(c(.1, .1, .6, .6, NA, .4, .4, .9, .9),
101
          c(.1, .6, .6, .1, NA, .4, .9, .9, .4),
102
          "Overlapping rectangles, both clockwise")
103
plotRules(c(.1, .1, .6, .6, NA, .4, .9, .9, .4),
104
          c(.1, .6, .6, .1, NA, .4, .4, .9, .9),
105
          "Overlapping rectangles, one clockwise, other anti-clockwise")
52406 murrell 106
 
107
par(op)
108
}
109
\keyword{aplot}