EVOLUTION-MANAGER
Edit File: geom_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: Connect observations</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 geom_path {ggplot2}"><tr><td>geom_path {ggplot2}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Connect observations</h2> <h3>Description</h3> <p><code>geom_path()</code> connects the observations in the order in which they appear in the data. <code>geom_line()</code> connects them in order of the variable on the x axis. <code>geom_step()</code> creates a stairstep plot, highlighting exactly when changes occur. The <code>group</code> aesthetic determines which cases are connected together. </p> <h3>Usage</h3> <pre> geom_path( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., lineend = "butt", linejoin = "round", linemitre = 10, arrow = NULL, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_line( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE, ... ) geom_step( mapping = NULL, data = NULL, stat = "identity", position = "identity", direction = "hv", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... ) </pre> <h3>Arguments</h3> <table summary="R argblock"> <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>...</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>lineend</code></td> <td> <p>Line end style (round, butt, square).</p> </td></tr> <tr valign="top"><td><code>linejoin</code></td> <td> <p>Line join style (round, mitre, bevel).</p> </td></tr> <tr valign="top"><td><code>linemitre</code></td> <td> <p>Line mitre limit (number greater than 1).</p> </td></tr> <tr valign="top"><td><code>arrow</code></td> <td> <p>Arrow specification, as created by <code><a href="../../grid/html/arrow.html">grid::arrow()</a></code>.</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. It can also be a named logical vector to finely select the aesthetics to display.</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>orientation</code></td> <td> <p>The orientation of the layer. The default (<code>NA</code>) automatically determines the orientation from the aesthetic mapping. In the rare event that this fails it can be given explicitly by setting <code>orientation</code> to either <code>"x"</code> or <code>"y"</code>. See the <em>Orientation</em> section for more detail.</p> </td></tr> <tr valign="top"><td><code>direction</code></td> <td> <p>direction of stairs: 'vh' for vertical then horizontal, 'hv' for horizontal then vertical, or 'mid' for step half-way between adjacent x-values.</p> </td></tr> </table> <h3>Details</h3> <p>An alternative parameterisation is <code><a href="geom_segment.html">geom_segment()</a></code>, where each line corresponds to a single case which provides the start and end coordinates. </p> <h3>Orientation</h3> <p>This geom treats each axis differently and, thus, can thus have two orientations. Often the orientation is easy to deduce from a combination of the given mappings and the types of positional scales in use. Thus, ggplot2 will by default try to guess which orientation the layer should have. Under rare circumstances, the orientation is ambiguous and guessing may fail. In that case the orientation can be specified directly using the <code>orientation</code> parameter, which can be either <code>"x"</code> or <code>"y"</code>. The value gives the axis that the geom should run along, <code>"x"</code> being the default orientation you would expect for the geom. </p> <h3>Aesthetics</h3> <p><code>geom_path()</code> understands the following aesthetics (required aesthetics are in bold): </p> <ul> <li> <p><strong><code>x</code></strong> </p> </li> <li> <p><strong><code>y</code></strong> </p> </li> <li> <p><code>alpha</code> </p> </li> <li> <p><code>colour</code> </p> </li> <li> <p><code>group</code> </p> </li> <li> <p><code>linetype</code> </p> </li> <li> <p><code>size</code> </p> </li></ul> <p>Learn more about setting these aesthetics in <code>vignette("ggplot2-specs")</code>. </p> <h3>Missing value handling</h3> <p><code>geom_path()</code>, <code>geom_line()</code>, and <code>geom_step</code> handle <code>NA</code> as follows: </p> <ul> <li><p> If an <code>NA</code> occurs in the middle of a line, it breaks the line. No warning is shown, regardless of whether <code>na.rm</code> is <code>TRUE</code> or <code>FALSE</code>. </p> </li> <li><p> If an <code>NA</code> occurs at the start or the end of the line and <code>na.rm</code> is <code>FALSE</code> (default), the <code>NA</code> is removed with a warning. </p> </li> <li><p> If an <code>NA</code> occurs at the start or the end of the line and <code>na.rm</code> is <code>TRUE</code>, the <code>NA</code> is removed silently, without warning. </p> </li></ul> <h3>See Also</h3> <p><code><a href="geom_polygon.html">geom_polygon()</a></code>: Filled paths (polygons); <code><a href="geom_segment.html">geom_segment()</a></code>: Line segments </p> <h3>Examples</h3> <pre> # geom_line() is suitable for time series ggplot(economics, aes(date, unemploy)) + geom_line() ggplot(economics_long, aes(date, value01, colour = variable)) + geom_line() # You can get a timeseries that run vertically by setting the orientation ggplot(economics, aes(unemploy, date)) + geom_line(orientation = "y") # geom_step() is useful when you want to highlight exactly when # the y value changes recent <- economics[economics$date > as.Date("2013-01-01"), ] ggplot(recent, aes(date, unemploy)) + geom_line() ggplot(recent, aes(date, unemploy)) + geom_step() # geom_path lets you explore how two variables are related over time, # e.g. unemployment and personal savings rate m <- ggplot(economics, aes(unemploy/pop, psavert)) m + geom_path() m + geom_path(aes(colour = as.numeric(date))) # Changing parameters ---------------------------------------------- ggplot(economics, aes(date, unemploy)) + geom_line(colour = "red") # Use the arrow parameter to add an arrow to the line # See ?arrow for more details c <- ggplot(economics, aes(x = date, y = pop)) c + geom_line(arrow = arrow()) c + geom_line( arrow = arrow(angle = 15, ends = "both", type = "closed") ) # Control line join parameters df <- data.frame(x = 1:3, y = c(4, 1, 9)) base <- ggplot(df, aes(x, y)) base + geom_path(size = 10) base + geom_path(size = 10, lineend = "round") base + geom_path(size = 10, linejoin = "mitre", lineend = "butt") # You can use NAs to break the line. df <- data.frame(x = 1:5, y = c(1, 2, NA, 4, 5)) ggplot(df, aes(x, y)) + geom_point() + geom_line() # Setting line type vs colour/size # Line type needs to be applied to a line as a whole, so it can # not be used with colour or size that vary across a line x <- seq(0.01, .99, length.out = 100) df <- data.frame( x = rep(x, 2), y = c(qlogis(x), 2 * qlogis(x)), group = rep(c("a","b"), each = 100) ) p <- ggplot(df, aes(x=x, y=y, group=group)) # These work p + geom_line(linetype = 2) p + geom_line(aes(colour = group), linetype = 2) p + geom_line(aes(colour = x)) # But this doesn't should_stop(p + geom_line(aes(colour = x), linetype=2)) </pre> <hr /><div style="text-align: center;">[Package <em>ggplot2</em> version 3.3.2 <a href="00Index.html">Index</a>]</div> </body></html>