EVOLUTION-MANAGER
Edit File: grid.path.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Draw a Path</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for grid.path {grid}"><tr><td>grid.path {grid}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2> Draw a Path </h2> <h3>Description</h3> <p>These functions create and draw one or more paths. The final point of a path will automatically be connected to the initial point. </p> <h3>Usage</h3> <pre> pathGrob(x, y, id=NULL, id.lengths=NULL, pathId=NULL, pathId.lengths=NULL, rule="winding", default.units="npc", name=NULL, gp=gpar(), vp=NULL) grid.path(...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>A numeric vector or unit object specifying x-locations.</p> </td></tr> <tr valign="top"><td><code>y</code></td> <td> <p>A numeric vector or unit object specifying y-locations.</p> </td></tr> <tr valign="top"><td><code>id</code></td> <td> <p>A numeric vector used to separate locations in <code>x</code> and <code>y</code> into sub-paths. All locations with the same <code>id</code> belong to the same sub-path.</p> </td></tr> <tr valign="top"><td><code>id.lengths</code></td> <td> <p>A numeric vector used to separate locations in <code>x</code> and <code>y</code> into sub-paths. Specifies consecutive blocks of locations which make up separate sub-paths.</p> </td></tr> <tr valign="top"><td><code>pathId</code></td> <td> <p>A numeric vector used to separate locations in <code>x</code> and <code>y</code> into distinct paths. All locations with the same <code>pathId</code> belong to the same path.</p> </td></tr> <tr valign="top"><td><code>pathId.lengths</code></td> <td> <p>A numeric vector used to separate locations in <code>x</code> and <code>y</code> into paths. Specifies consecutive blocks of locations which make up separate paths.</p> </td></tr> <tr valign="top"><td><code>rule</code></td> <td> <p>A character value specifying the fill rule: either <code>"winding"</code> or <code>"evenodd"</code>.</p> </td></tr> <tr valign="top"><td><code>default.units</code></td> <td> <p>A string indicating the default units to use if <code>x</code> or <code>y</code> are only given as numeric vectors.</p> </td></tr> <tr valign="top"><td><code>name</code></td> <td> <p> A character identifier. </p> </td></tr> <tr valign="top"><td><code>gp</code></td> <td> <p>An object of class <code>gpar</code>, typically the output from a call to the function <code>gpar</code>. This is basically a list of graphical parameter settings.</p> </td></tr> <tr valign="top"><td><code>vp</code></td> <td> <p>A Grid viewport object (or NULL).</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Arguments passed to <code>pathGrob()</code>.</p> </td></tr> </table> <h3>Details</h3> <p>Both functions create a path grob (a graphical object describing a path), but only <code>grid.path</code> draws the path (and then only if <code>draw</code> is <code>TRUE</code>). </p> <p>A path is like a polygon except that the former can contain holes, as interpreted by the fill rule; these fill a region if the path border encircles it an odd or non-zero number of times, respectively. </p> <p>Not all graphics devices support this function: for example <code>xfig</code> and <code>pictex</code> do not. </p> <h3>Value</h3> <p>A grob object. </p> <h3>Author(s)</h3> <p>Paul Murrell</p> <h3>See Also</h3> <p><a href="Grid.html">Grid</a>, <code><a href="viewport.html">viewport</a></code> </p> <h3>Examples</h3> <pre> pathSample <- function(x, y, rule, gp = gpar()) { if (is.na(rule)) grid.path(x, y, id = rep(1:2, each = 4), gp = gp) else grid.path(x, y, id = rep(1:2, each = 4), rule = rule, gp = gp) if (!is.na(rule)) grid.text(paste("Rule:", rule), y = 0, just = "bottom") } pathTriplet <- function(x, y, title) { pushViewport(viewport(height = 0.9, layout = grid.layout(1, 3), gp = gpar(cex = .7))) grid.rect(y = 1, height = unit(1, "char"), just = "top", gp = gpar(col = NA, fill = "grey")) grid.text(title, y = 1, just = "top") pushViewport(viewport(layout.pos.col = 1)) pathSample(x, y, rule = "winding", gp = gpar(fill = "grey")) popViewport() pushViewport(viewport(layout.pos.col = 2)) pathSample(x, y, rule = "evenodd", gp = gpar(fill = "grey")) popViewport() pushViewport(viewport(layout.pos.col = 3)) pathSample(x, y, rule = NA) popViewport() popViewport() } pathTest <- function() { grid.newpage() pushViewport(viewport(layout = grid.layout(5, 1))) pushViewport(viewport(layout.pos.row = 1)) pathTriplet(c(.1, .1, .9, .9, .2, .2, .8, .8), c(.1, .9, .9, .1, .2, .8, .8, .2), "Nested rectangles, both clockwise") popViewport() pushViewport(viewport(layout.pos.row = 2)) pathTriplet(c(.1, .1, .9, .9, .2, .8, .8, .2), c(.1, .9, .9, .1, .2, .2, .8, .8), "Nested rectangles, outer clockwise, inner anti-clockwise") popViewport() pushViewport(viewport(layout.pos.row = 3)) pathTriplet(c(.1, .1, .4, .4, .6, .9, .9, .6), c(.1, .4, .4, .1, .6, .6, .9, .9), "Disjoint rectangles") popViewport() pushViewport(viewport(layout.pos.row = 4)) pathTriplet(c(.1, .1, .6, .6, .4, .4, .9, .9), c(.1, .6, .6, .1, .4, .9, .9, .4), "Overlapping rectangles, both clockwise") popViewport() pushViewport(viewport(layout.pos.row = 5)) pathTriplet(c(.1, .1, .6, .6, .4, .9, .9, .4), c(.1, .6, .6, .1, .4, .4, .9, .9), "Overlapping rectangles, one clockwise, other anti-clockwise") popViewport() popViewport() } pathTest() # Drawing multiple paths at once holed_rect <- cbind(c(.15, .15, -.15, -.15, .1, .1, -.1, -.1), c(.15, -.15, -.15, .15, .1, -.1, -.1, .1)) holed_rects <- rbind( holed_rect + matrix(c(.7, .2), nrow = 8, ncol = 2, byrow = TRUE), holed_rect + matrix(c(.7, .8), nrow = 8, ncol = 2, byrow = TRUE), holed_rect + matrix(c(.2, .5), nrow = 8, ncol = 2, byrow = TRUE) ) grid.newpage() grid.path(x = holed_rects[, 1], y = holed_rects[, 2], id = rep(1:6, each = 4), pathId = rep(1:3, each = 8), gp = gpar(fill = c('red', 'blue', 'green')), rule = 'evenodd') # Not specifying pathId will treat all points as part of the same path, thus # having same fill grid.newpage() grid.path(x = holed_rects[, 1], y = holed_rects[, 2], id = rep(1:6, each = 4), gp = gpar(fill = c('red', 'blue', 'green')), rule = 'evenodd') </pre> <hr /><div style="text-align: center;">[Package <em>grid</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>