EVOLUTION-MANAGER
Edit File: sec_axis.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: Specify a secondary axis</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 sec_axis {ggplot2}"><tr><td>sec_axis {ggplot2}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Specify a secondary axis</h2> <h3>Description</h3> <p>This function is used in conjunction with a position scale to create a secondary axis, positioned opposite of the primary axis. All secondary axes must be based on a one-to-one transformation of the primary axes. </p> <h3>Usage</h3> <pre> sec_axis( trans = NULL, name = waiver(), breaks = waiver(), labels = waiver(), guide = waiver() ) dup_axis( trans = ~., name = derive(), breaks = derive(), labels = derive(), guide = derive() ) derive() </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>trans</code></td> <td> <p>A formula or function of transformation</p> </td></tr> <tr valign="top"><td><code>name</code></td> <td> <p>The name of the secondary axis</p> </td></tr> <tr valign="top"><td><code>breaks</code></td> <td> <p>One of: </p> <ul> <li> <p><code>NULL</code> for no breaks </p> </li> <li> <p><code>waiver()</code> for the default breaks computed by the transformation object </p> </li> <li><p> A numeric vector of positions </p> </li> <li><p> A function that takes the limits as input and returns breaks as output </p> </li></ul> </td></tr> <tr valign="top"><td><code>labels</code></td> <td> <p>One of: </p> <ul> <li> <p><code>NULL</code> for no labels </p> </li> <li> <p><code>waiver()</code> for the default labels computed by the transformation object </p> </li> <li><p> A character vector giving labels (must be same length as <code>breaks</code>) </p> </li> <li><p> A function that takes the breaks as input and returns labels as output </p> </li></ul> </td></tr> <tr valign="top"><td><code>guide</code></td> <td> <p>A position guide that will be used to render the axis on the plot. Usually this is <code><a href="guide_axis.html">guide_axis()</a></code>.</p> </td></tr> </table> <h3>Details</h3> <p><code>sec_axis()</code> is used to create the specifications for a secondary axis. Except for the <code>trans</code> argument any of the arguments can be set to <code>derive()</code> which would result in the secondary axis inheriting the settings from the primary axis. </p> <p><code>dup_axis()</code> is provide as a shorthand for creating a secondary axis that is a duplication of the primary axis, effectively mirroring the primary axis. </p> <p>As of v3.1, date and datetime scales have limited secondary axis capabilities. Unlike other continuous scales, secondary axis transformations for date and datetime scales must respect their primary POSIX data structure. This means they may only be transformed via addition or subtraction, e.g. <code>~ . + hms::hms(days = 8)</code>, or <code>~ . - 8*60*60</code>. Nonlinear transformations will return an error. To produce a time-since-event secondary axis in this context, users may consider adapting secondary axis labels. </p> <h3>Examples</h3> <pre> p <- ggplot(mtcars, aes(cyl, mpg)) + geom_point() # Create a simple secondary axis p + scale_y_continuous(sec.axis = sec_axis(~ . + 10)) # Inherit the name from the primary axis p + scale_y_continuous("Miles/gallon", sec.axis = sec_axis(~ . + 10, name = derive())) # Duplicate the primary axis p + scale_y_continuous(sec.axis = dup_axis()) # You can pass in a formula as a shorthand p + scale_y_continuous(sec.axis = ~ .^2) # Secondary axes work for date and datetime scales too: df <- data.frame( dx = seq(as.POSIXct("2012-02-29 12:00:00", tz = "UTC", format = "%Y-%m-%d %H:%M:%S" ), length.out = 10, by = "4 hour" ), price = seq(20, 200000, length.out = 10) ) # This may useful for labelling different time scales in the same plot ggplot(df, aes(x = dx, y = price)) + geom_line() + scale_x_datetime("Date", date_labels = "%b %d", date_breaks = "6 hour", sec.axis = dup_axis(name = "Time of Day", labels = scales::time_format("%I %p"))) # or to transform axes for different timezones ggplot(df, aes(x = dx, y = price)) + geom_line() + scale_x_datetime("GMT", date_labels = "%b %d %I %p", sec.axis = sec_axis(~ . + 8 * 3600, name = "GMT+8", labels = scales::time_format("%b %d %I %p"))) </pre> <hr /><div style="text-align: center;">[Package <em>ggplot2</em> version 3.3.2 <a href="00Index.html">Index</a>]</div> </body></html>