EVOLUTION-MANAGER
Edit File: plot.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: plot sf object</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 plot {sf}"><tr><td>plot {sf}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>plot sf object</h2> <h3>Description</h3> <p>plot one or more attributes of an sf object on a map Plot sf object </p> <h3>Usage</h3> <pre> ## S3 method for class 'sf' plot( x, y, ..., main, pal = NULL, nbreaks = 10, breaks = "pretty", max.plot = if (is.null(n <- options("sf_max.plot")[[1]])) 9 else n, key.pos = get_key_pos(x, ...), key.length = 0.618, key.width = lcm(1.8), reset = TRUE, logz = FALSE, extent = x, xlim = st_bbox(extent)[c(1, 3)], ylim = st_bbox(extent)[c(2, 4)] ) get_key_pos(x, ...) ## S3 method for class 'sfc_POINT' plot( x, y, ..., pch = 1, cex = 1, col = 1, bg = 0, lwd = 1, lty = 1, type = "p", add = FALSE ) ## S3 method for class 'sfc_MULTIPOINT' plot( x, y, ..., pch = 1, cex = 1, col = 1, bg = 0, lwd = 1, lty = 1, type = "p", add = FALSE ) ## S3 method for class 'sfc_LINESTRING' plot(x, y, ..., lty = 1, lwd = 1, col = 1, pch = 1, type = "l", add = FALSE) ## S3 method for class 'sfc_CIRCULARSTRING' plot(x, y, ...) ## S3 method for class 'sfc_MULTILINESTRING' plot(x, y, ..., lty = 1, lwd = 1, col = 1, pch = 1, type = "l", add = FALSE) ## S3 method for class 'sfc_POLYGON' plot( x, y, ..., lty = 1, lwd = 1, col = NA, cex = 1, pch = NA, border = 1, add = FALSE, rule = "evenodd" ) ## S3 method for class 'sfc_MULTIPOLYGON' plot( x, y, ..., lty = 1, lwd = 1, col = NA, border = 1, add = FALSE, rule = "evenodd" ) ## S3 method for class 'sfc_GEOMETRYCOLLECTION' plot( x, y, ..., pch = 1, cex = 1, bg = 0, lty = 1, lwd = 1, col = 1, border = 1, add = FALSE ) ## S3 method for class 'sfc_GEOMETRY' plot( x, y, ..., pch = 1, cex = 1, bg = 0, lty = 1, lwd = 1, col = ifelse(st_dimension(x) == 2, NA, 1), border = 1, add = FALSE ) ## S3 method for class 'sfg' plot(x, ...) plot_sf( x, xlim = NULL, ylim = NULL, asp = NA, axes = FALSE, bgc = par("bg"), ..., xaxs, yaxs, lab, setParUsrBB = FALSE, bgMap = NULL, expandBB = c(0, 0, 0, 0), graticule = NA_crs_, col_graticule = "grey", border ) sf.colors(n = 10, cutoff.tails = c(0.35, 0.2), alpha = 1, categorical = FALSE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>object of class sf</p> </td></tr> <tr valign="top"><td><code>y</code></td> <td> <p>ignored</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>further specifications, see <a href="plot.html">plot_sf</a> and <a href="plot.html">plot</a> and details.</p> </td></tr> <tr valign="top"><td><code>main</code></td> <td> <p>title for plot (<code>NULL</code> to remove)</p> </td></tr> <tr valign="top"><td><code>pal</code></td> <td> <p>palette function, similar to <a href="../../grDevices/html/palettes.html">rainbow</a>, or palette values; if omitted, <code>sf.colors</code> is used</p> </td></tr> <tr valign="top"><td><code>nbreaks</code></td> <td> <p>number of colors breaks (ignored for <code>factor</code> or <code>character</code> variables)</p> </td></tr> <tr valign="top"><td><code>breaks</code></td> <td> <p>either a numeric vector with the actual breaks, or a name of a method accepted by the <code>style</code> argument of <a href="../../classInt/html/classIntervals.html">classIntervals</a></p> </td></tr> <tr valign="top"><td><code>max.plot</code></td> <td> <p>integer; lower boundary to maximum number of attributes to plot; the default value (9) can be overriden by setting the global option <code>sf_max.plot</code>, e.g. <code>options(sf_max.plot=2)</code></p> </td></tr> <tr valign="top"><td><code>key.pos</code></td> <td> <p>integer; side to plot a color key: 1 bottom, 2 left, 3 top, 4 right; set to <code>NULL</code> to omit key, or -1 to select automatically. If multiple columns are plotted in a single function call by default no key is plotted and every submap is stretched individually; if a key is requested (and <code>col</code> is missing) all maps are colored according to a single key. Auto select depends on plot size, map aspect, and, if set, parameter <code>asp</code>.</p> </td></tr> <tr valign="top"><td><code>key.length</code></td> <td> <p>amount of space reserved for the key along its axis, length of the scale bar</p> </td></tr> <tr valign="top"><td><code>key.width</code></td> <td> <p>amount of space reserved for the key (incl. labels), thickness/width of the scale bar</p> </td></tr> <tr valign="top"><td><code>reset</code></td> <td> <p>logical; if <code>FALSE</code>, keep the plot in a mode that allows adding further map elements; if <code>TRUE</code> restore original mode after plotting <code>sf</code> objects with attributes; see details.</p> </td></tr> <tr valign="top"><td><code>logz</code></td> <td> <p>logical; if <code>TRUE</code>, use log10-scale for the attribute variable. In that case, <code>breaks</code> and <code>at</code> need to be given as log10-values; see examples.</p> </td></tr> <tr valign="top"><td><code>extent</code></td> <td> <p>object with an <code>st_bbox</code> method to define plot extent; defaults to <code>x</code></p> </td></tr> <tr valign="top"><td><code>xlim</code></td> <td> <p>see <a href="../../graphics/html/plot.window.html">plot.window</a></p> </td></tr> <tr valign="top"><td><code>ylim</code></td> <td> <p>see <a href="../../graphics/html/plot.window.html">plot.window</a></p> </td></tr> <tr valign="top"><td><code>pch</code></td> <td> <p>plotting symbol</p> </td></tr> <tr valign="top"><td><code>cex</code></td> <td> <p>symbol size</p> </td></tr> <tr valign="top"><td><code>col</code></td> <td> <p>color for plotting features; if <code>length(col)</code> does not equal 1 or <code>nrow(x)</code>, a warning is emitted that colors will be recycled. Specifying <code>col</code> suppresses plotting the legend key.</p> </td></tr> <tr valign="top"><td><code>bg</code></td> <td> <p>symbol background color</p> </td></tr> <tr valign="top"><td><code>lwd</code></td> <td> <p>line width</p> </td></tr> <tr valign="top"><td><code>lty</code></td> <td> <p>line type</p> </td></tr> <tr valign="top"><td><code>type</code></td> <td> <p>plot type: 'p' for points, 'l' for lines, 'b' for both</p> </td></tr> <tr valign="top"><td><code>add</code></td> <td> <p>logical; add to current plot? Note that when using <code>add=TRUE</code>, you may have to set <code>reset=FALSE</code> in the first plot command.</p> </td></tr> <tr valign="top"><td><code>border</code></td> <td> <p>color of polygon border(s)</p> </td></tr> <tr valign="top"><td><code>rule</code></td> <td> <p>see <a href="../../graphics/html/polypath.html">polypath</a>; for <code>winding</code>, exterior ring direction should be opposite that of the holes; with <code>evenodd</code>, plotting is robust against misspecified ring directions</p> </td></tr> <tr valign="top"><td><code>asp</code></td> <td> <p>see below, and see <a href="../../graphics/html/par.html">par</a></p> </td></tr> <tr valign="top"><td><code>axes</code></td> <td> <p>logical; should axes be plotted? (default FALSE)</p> </td></tr> <tr valign="top"><td><code>bgc</code></td> <td> <p>background color</p> </td></tr> <tr valign="top"><td><code>xaxs</code></td> <td> <p>see <a href="../../graphics/html/par.html">par</a></p> </td></tr> <tr valign="top"><td><code>yaxs</code></td> <td> <p>see <a href="../../graphics/html/par.html">par</a></p> </td></tr> <tr valign="top"><td><code>lab</code></td> <td> <p>see <a href="../../graphics/html/par.html">par</a></p> </td></tr> <tr valign="top"><td><code>setParUsrBB</code></td> <td> <p>default FALSE; set the <code>par</code> “usr” bounding box; see below</p> </td></tr> <tr valign="top"><td><code>bgMap</code></td> <td> <p>object of class <code>ggmap</code>, or returned by function <code>RgoogleMaps::GetMap</code></p> </td></tr> <tr valign="top"><td><code>expandBB</code></td> <td> <p>numeric; fractional values to expand the bounding box with, in each direction (bottom, left, top, right)</p> </td></tr> <tr valign="top"><td><code>graticule</code></td> <td> <p>logical, or object of class <code>crs</code> (e.g., <code>st_crs(4326)</code> for a WGS84 graticule), or object created by <a href="st_graticule.html">st_graticule</a>; <code>TRUE</code> will give the WGS84 graticule or object returned by <a href="st_graticule.html">st_graticule</a></p> </td></tr> <tr valign="top"><td><code>col_graticule</code></td> <td> <p>color to used for the graticule (if present)</p> </td></tr> <tr valign="top"><td><code>n</code></td> <td> <p>integer; number of colors</p> </td></tr> <tr valign="top"><td><code>cutoff.tails</code></td> <td> <p>numeric, in [0,0.5] start and end values</p> </td></tr> <tr valign="top"><td><code>alpha</code></td> <td> <p>numeric, in [0,1], transparency</p> </td></tr> <tr valign="top"><td><code>categorical</code></td> <td> <p>logical; do we want colors for a categorical variable? (see details)</p> </td></tr> </table> <h3>Details</h3> <p><code>plot.sf</code> maximally plots <code>max.plot</code> maps with colors following from attribute columns, one map per attribute. It uses <code>sf.colors</code> for default colors. For more control over placement of individual maps, set parameter <code>mfrow</code> with <a href="../../graphics/html/par.html">par</a> prior to plotting, and plot single maps one by one; note that this only works in combination with setting parameters <code>key.pos=NULL</code> (no legend) and <code>reset=FALSE</code>. </p> <p><code>plot.sfc</code> plots the geometry, additional parameters can be passed on to control color, lines or symbols. </p> <p>When setting <code>reset</code> to <code>FALSE</code>, the original device parameters are lost, and the device must be reset using <code>dev.off()</code> in order to reset it. </p> <p>parameter <code>at</code> can be set to specify where labels are placed along the key; see examples. </p> <p><code>plot_sf</code> sets up the plotting area, axes, graticule, or webmap background; it is called by all <code>plot</code> methods before anything is drawn. </p> <p>The argument <code>setParUsrBB</code> may be used to pass the logical value <code>TRUE</code> to functions within <code>plot.Spatial</code>. When set to <code>TRUE</code>, par(“usr”) will be overwritten with <code>c(xlim, ylim)</code>, which defaults to the bounding box of the spatial object. This is only needed in the particular context of graphic output to a specified device with given width and height, to be matched to the spatial object, when using par(“xaxs”) and par(“yaxs”) in addition to <code>par(mar=c(0,0,0,0))</code>. </p> <p>The default aspect for map plots is 1; if however data are not projected (coordinates are long/lat), the aspect is by default set to 1/cos(My * pi/180) with My the y coordinate of the middle of the map (the mean of <code>ylim</code>, which defaults to the y range of bounding box). This implies an <a href="https://en.wikipedia.org/wiki/Equirectangular_projection">Equirectangular projection</a>. </p> <p>non-categorical colors from <code>sf.colors</code> were taken from <a href="../../sp/html/bpy.colors.html">bpy.colors</a>, with modified <code>cutoff.tails</code> defaults If categorical is <code>TRUE</code>, default colors are from <a href="http://www.colorbrewer2.org/">http://www.colorbrewer2.org/</a> (if n < 9, Set2, else Set3). </p> <h3>Examples</h3> <pre> nc = st_read(system.file("gpkg/nc.gpkg", package="sf"), quiet = TRUE) # plot single attribute, auto-legend: plot(nc["SID74"]) # plot multiple: plot(nc[c("SID74", "SID79")]) # better use ggplot2::geom_sf to facet and get a single legend! # adding to a plot of an sf object only works when using reset=FALSE in the first plot: plot(nc["SID74"], reset = FALSE) plot(st_centroid(st_geometry(nc)), add = TRUE) # log10 z-scale: plot(nc["SID74"], logz = TRUE, breaks = c(0,.5,1,1.5,2), at = c(0,.5,1,1.5,2)) # and we need to reset the plotting device after that, e.g. by layout(1) # when plotting only geometries, the reset=FALSE is not needed: plot(st_geometry(nc)) plot(st_geometry(nc)[1], col = 'red', add = TRUE) # add a custom legend to an arbitray plot: layout(matrix(1:2, ncol = 2), widths = c(1, lcm(2))) plot(1) .image_scale(1:10, col = sf.colors(9), key.length = lcm(8), key.pos = 4, at = 1:10) sf.colors(10) </pre> <hr /><div style="text-align: center;">[Package <em>sf</em> version 0.9-5 <a href="00Index.html">Index</a>]</div> </body></html>