EVOLUTION-MANAGER
Edit File: ggsf.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: Visualise sf objects</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 CoordSf {ggplot2}"><tr><td>CoordSf {ggplot2}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Visualise sf objects</h2> <h3>Description</h3> <p>This set of geom, stat, and coord are used to visualise simple feature (sf) objects. For simple plots, you will only need <code>geom_sf()</code> as it uses <code>stat_sf()</code> and adds <code>coord_sf()</code> for you. <code>geom_sf()</code> is an unusual geom because it will draw different geometric objects depending on what simple features are present in the data: you can get points, lines, or polygons. For text and labels, you can use <code>geom_sf_text()</code> and <code>geom_sf_label()</code>. </p> <h3>Usage</h3> <pre> coord_sf( xlim = NULL, ylim = NULL, expand = TRUE, crs = NULL, datum = sf::st_crs(4326), label_graticule = waiver(), label_axes = waiver(), ndiscr = 100, default = FALSE, clip = "on" ) geom_sf( mapping = aes(), data = NULL, stat = "sf", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... ) geom_sf_label( mapping = aes(), data = NULL, stat = "sf_coordinates", position = "identity", ..., parse = FALSE, nudge_x = 0, nudge_y = 0, label.padding = unit(0.25, "lines"), label.r = unit(0.15, "lines"), label.size = 0.25, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, fun.geometry = NULL ) geom_sf_text( mapping = aes(), data = NULL, stat = "sf_coordinates", position = "identity", ..., parse = FALSE, nudge_x = 0, nudge_y = 0, check_overlap = FALSE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, fun.geometry = NULL ) stat_sf( mapping = NULL, data = NULL, geom = "rect", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... ) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>xlim</code></td> <td> <p>Limits for the x and y axes.</p> </td></tr> <tr valign="top"><td><code>ylim</code></td> <td> <p>Limits for the x and y axes.</p> </td></tr> <tr valign="top"><td><code>expand</code></td> <td> <p>If <code>TRUE</code>, the default, adds a small expansion factor to the limits to ensure that data and axes don't overlap. If <code>FALSE</code>, limits are taken exactly from the data or <code>xlim</code>/<code>ylim</code>.</p> </td></tr> <tr valign="top"><td><code>crs</code></td> <td> <p>Use this to select a specific coordinate reference system (CRS). If not specified, will use the CRS defined in the first layer.</p> </td></tr> <tr valign="top"><td><code>datum</code></td> <td> <p>CRS that provides datum to use when generating graticules</p> </td></tr> <tr valign="top"><td><code>label_graticule</code></td> <td> <p>Character vector indicating which graticule lines should be labeled where. Meridians run north-south, and the letters <code>"N"</code> and <code>"S"</code> indicate that they should be labeled on their north or south end points, respectively. Parallels run east-west, and the letters <code>"E"</code> and <code>"W"</code> indicate that they should be labeled on their east or west end points, respectively. Thus, <code>label_graticule = "SW"</code> would label meridians at their south end and parallels at their west end, whereas <code>label_graticule = "EW"</code> would label parallels at both ends and meridians not at all. Because meridians and parallels can in general intersect with any side of the plot panel, for any choice of <code>label_graticule</code> labels are not guaranteed to reside on only one particular side of the plot panel. Also, <code>label_graticule</code> can cause labeling artifacts, in particular if a graticule line coincides with the edge of the plot panel. In such circumstances, <code>label_axes</code> will generally yield better results and should be used instead. </p> <p>This parameter can be used alone or in combination with <code>label_axes</code>.</p> </td></tr> <tr valign="top"><td><code>label_axes</code></td> <td> <p>Character vector or named list of character values specifying which graticule lines (meridians or parallels) should be labeled on which side of the plot. Meridians are indicated by <code>"E"</code> (for East) and parallels by <code>"N"</code> (for North). Default is <code>"--EN"</code>, which specifies (clockwise from the top) no labels on the top, none on the right, meridians on the bottom, and parallels on the left. Alternatively, this setting could have been specified with <code>list(bottom = "E", left = "N")</code>. </p> <p>This parameter can be used alone or in combination with <code>label_graticule</code>.</p> </td></tr> <tr valign="top"><td><code>ndiscr</code></td> <td> <p>number of segments to use for discretising graticule lines; try increasing this when graticules look unexpected</p> </td></tr> <tr valign="top"><td><code>default</code></td> <td> <p>Is this the default coordinate system? If <code>FALSE</code> (the default), then replacing this coordinate system with another one creates a message alerting the user that the coordinate system is being replaced. If <code>TRUE</code>, that warning is suppressed.</p> </td></tr> <tr valign="top"><td><code>clip</code></td> <td> <p>Should drawing be clipped to the extent of the plot panel? A setting of <code>"on"</code> (the default) means yes, and a setting of <code>"off"</code> means no. In most cases, the default of <code>"on"</code> should not be changed, as setting <code>clip = "off"</code> can cause unexpected results. It allows drawing of data points anywhere on the plot, including in the plot margins. If limits are set via <code>xlim</code> and <code>ylim</code> and some data points fall outside those limits, then those data points may show up in places such as the axes, the legend, the plot title, or the plot margins.</p> </td></tr> <tr valign="top"><td><code>mapping</code></td> <td> <p>Set of aesthetic mappings created by <code><a href="aes.html">aes()</a></code> or <code><a href="aes_.html">aes_()</a></code>. If specified and <code>inherit.aes = TRUE</code> (the default), it is combined with the default mapping at the top level of the plot. You must supply <code>mapping</code> if there is no plot mapping.</p> </td></tr> <tr valign="top"><td><code>data</code></td> <td> <p>The data to be displayed in this layer. There are three options: </p> <p>If <code>NULL</code>, the default, the data is inherited from the plot data as specified in the call to <code><a href="ggplot.html">ggplot()</a></code>. </p> <p>A <code>data.frame</code>, or other object, will override the plot data. All objects will be fortified to produce a data frame. See <code><a href="fortify.html">fortify()</a></code> for which variables will be created. </p> <p>A <code>function</code> will be called with a single argument, the plot data. The return value must be a <code>data.frame</code>, and will be used as the layer data. A <code>function</code> can be created from a <code>formula</code> (e.g. <code>~ head(.x, 10)</code>).</p> </td></tr> <tr valign="top"><td><code>stat</code></td> <td> <p>The statistical transformation to use on the data for this layer, as a string.</p> </td></tr> <tr valign="top"><td><code>position</code></td> <td> <p>Position adjustment, either as a string, or the result of a call to a position adjustment function.</p> </td></tr> <tr valign="top"><td><code>na.rm</code></td> <td> <p>If <code>FALSE</code>, the default, missing values are removed with a warning. If <code>TRUE</code>, missing values are silently removed.</p> </td></tr> <tr valign="top"><td><code>show.legend</code></td> <td> <p>logical. Should this layer be included in the legends? <code>NA</code>, the default, includes if any aesthetics are mapped. <code>FALSE</code> never includes, and <code>TRUE</code> always includes. </p> <p>You can also set this to one of "polygon", "line", and "point" to override the default legend.</p> </td></tr> <tr valign="top"><td><code>inherit.aes</code></td> <td> <p>If <code>FALSE</code>, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. <code><a href="borders.html">borders()</a></code>.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Other arguments passed on to <code><a href="layer.html">layer()</a></code>. These are often aesthetics, used to set an aesthetic to a fixed value, like <code>colour = "red"</code> or <code>size = 3</code>. They may also be parameters to the paired geom/stat.</p> </td></tr> <tr valign="top"><td><code>parse</code></td> <td> <p>If <code>TRUE</code>, the labels will be parsed into expressions and displayed as described in <code>?plotmath</code>.</p> </td></tr> <tr valign="top"><td><code>nudge_x</code></td> <td> <p>Horizontal and vertical adjustment to nudge labels by. Useful for offsetting text from points, particularly on discrete scales. Cannot be jointly specified with <code>position</code>.</p> </td></tr> <tr valign="top"><td><code>nudge_y</code></td> <td> <p>Horizontal and vertical adjustment to nudge labels by. Useful for offsetting text from points, particularly on discrete scales. Cannot be jointly specified with <code>position</code>.</p> </td></tr> <tr valign="top"><td><code>label.padding</code></td> <td> <p>Amount of padding around label. Defaults to 0.25 lines.</p> </td></tr> <tr valign="top"><td><code>label.r</code></td> <td> <p>Radius of rounded corners. Defaults to 0.15 lines.</p> </td></tr> <tr valign="top"><td><code>label.size</code></td> <td> <p>Size of label border, in mm.</p> </td></tr> <tr valign="top"><td><code>fun.geometry</code></td> <td> <p>A function that takes a <code>sfc</code> object and returns a <code>sfc_POINT</code> with the same length as the input. If <code>NULL</code>, <code>function(x) sf::st_point_on_surface(sf::st_zm(x))</code> will be used. Note that the function may warn about the incorrectness of the result if the data is not projected, but you can ignore this except when you really care about the exact locations.</p> </td></tr> <tr valign="top"><td><code>check_overlap</code></td> <td> <p>If <code>TRUE</code>, text that overlaps previous text in the same layer will not be plotted. <code>check_overlap</code> happens at draw time and in the order of the data. Therefore data should be arranged by the label column before calling <code>geom_label()</code> or <code>geom_text()</code>.</p> </td></tr> <tr valign="top"><td><code>geom</code></td> <td> <p>The geometric object to use display the data</p> </td></tr> </table> <h3>Geometry aesthetic</h3> <p><code>geom_sf()</code> uses a unique aesthetic: <code>geometry</code>, giving an column of class <code>sfc</code> containing simple features data. There are three ways to supply the <code>geometry</code> aesthetic: </p> <ul> <li><p> Do nothing: by default <code>geom_sf()</code> assumes it is stored in the <code>geometry</code> column. </p> </li> <li><p> Explicitly pass an <code>sf</code> object to the <code>data</code> argument. This will use the primary geometry column, no matter what it's called. </p> </li> <li><p> Supply your own using <code>aes(geometry = my_column)</code> </p> </li></ul> <p>Unlike other aesthetics, <code>geometry</code> will never be inherited from the plot. </p> <h3>CRS</h3> <p><code>coord_sf()</code> ensures that all layers use a common CRS. You can either specify it using the <code>CRS</code> param, or <code>coord_sf()</code> will take it from the first layer that defines a CRS. </p> <h3>See Also</h3> <p><code><a href="stat_sf_coordinates.html">stat_sf_coordinates()</a></code> </p> <h3>Examples</h3> <pre> if (requireNamespace("sf", quietly = TRUE)) { nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE) ggplot(nc) + geom_sf(aes(fill = AREA)) # If not supplied, coord_sf() will take the CRS from the first layer # and automatically transform all other layers to use that CRS. This # ensures that all data will correctly line up nc_3857 <- sf::st_transform(nc, 3857) ggplot() + geom_sf(data = nc) + geom_sf(data = nc_3857, colour = "red", fill = NA) # Unfortunately if you plot other types of feature you'll need to use # show.legend to tell ggplot2 what type of legend to use nc_3857$mid <- sf::st_centroid(nc_3857$geometry) ggplot(nc_3857) + geom_sf(colour = "white") + geom_sf(aes(geometry = mid, size = AREA), show.legend = "point") # You can also use layers with x and y aesthetics: these are # assumed to already be in the common CRS. ggplot(nc) + geom_sf() + annotate("point", x = -80, y = 35, colour = "red", size = 4) # Thanks to the power of sf, a geom_sf nicely handles varying projections # setting the aspect ratio correctly. library(maps) world1 <- sf::st_as_sf(map('world', plot = FALSE, fill = TRUE)) ggplot() + geom_sf(data = world1) world2 <- sf::st_transform( world1, "+proj=laea +y_0=0 +lon_0=155 +lat_0=-90 +ellps=WGS84 +no_defs" ) ggplot() + geom_sf(data = world2) # To add labels, use geom_sf_label(). ggplot(nc_3857[1:3, ]) + geom_sf(aes(fill = AREA)) + geom_sf_label(aes(label = NAME)) } </pre> <hr /><div style="text-align: center;">[Package <em>ggplot2</em> version 3.3.2 <a href="00Index.html">Index</a>]</div> </body></html>