EVOLUTION-MANAGER
Edit File: lims.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: Set scale limits</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 lims {ggplot2}"><tr><td>lims {ggplot2}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Set scale limits</h2> <h3>Description</h3> <p>This is a shortcut for supplying the <code>limits</code> argument to the individual scales. By default, any values outside the limits specified are replaced with <code>NA</code>. Be warned that this will remove data outside the limits and this can produce unintended results. For changing x or y axis limits <strong>without</strong> dropping data observations, see <code><a href="coord_cartesian.html">coord_cartesian()</a></code>. </p> <h3>Usage</h3> <pre> lims(...) xlim(...) ylim(...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>...</code></td> <td> <p>For <code>xlim()</code> and <code>ylim()</code>: Two numeric values, specifying the left/lower limit and the right/upper limit of the scale. If the larger value is given first, the scale will be reversed. You can leave one value as <code>NA</code> if you want to compute the corresponding limit from the range of the data. </p> <p>For <code>lims()</code>: A name–value pair. The name must be an aesthetic, and the value must be either a length-2 numeric, a character, a factor, or a date/time. A numeric value will create a continuous scale. If the larger value comes first, the scale will be reversed. You can leave one value as <code>NA</code> if you want to compute the corresponding limit from the range of the data. A character or factor value will create a discrete scale. A date-time value will create a continuous date/time scale.</p> </td></tr> </table> <h3>See Also</h3> <p>To expand the range of a plot to always include certain values, see <code><a href="expand_limits.html">expand_limits()</a></code>. For other types of data, see <code><a href="scale_discrete.html">scale_x_discrete()</a></code>, <code><a href="scale_continuous.html">scale_x_continuous()</a></code>, <code><a href="scale_date.html">scale_x_date()</a></code>. </p> <h3>Examples</h3> <pre> # Zoom into a specified area ggplot(mtcars, aes(mpg, wt)) + geom_point() + xlim(15, 20) # reverse scale ggplot(mtcars, aes(mpg, wt)) + geom_point() + xlim(20, 15) # with automatic lower limit ggplot(mtcars, aes(mpg, wt)) + geom_point() + xlim(NA, 20) # You can also supply limits that are larger than the data. # This is useful if you want to match scales across different plots small <- subset(mtcars, cyl == 4) big <- subset(mtcars, cyl > 4) ggplot(small, aes(mpg, wt, colour = factor(cyl))) + geom_point() + lims(colour = c("4", "6", "8")) ggplot(big, aes(mpg, wt, colour = factor(cyl))) + geom_point() + lims(colour = c("4", "6", "8")) # There are two ways of setting the axis limits: with limits or # with coordinate systems. They work in two rather different ways. last_month <- Sys.Date() - 0:59 df <- data.frame( date = last_month, price = c(rnorm(30, mean = 15), runif(30) + 0.2 * (1:30)) ) p <- ggplot(df, aes(date, price)) + geom_line() + stat_smooth() p # Setting the limits with the scale discards all data outside the range. p + lims(x= c(Sys.Date() - 30, NA), y = c(10, 20)) # For changing x or y axis limits **without** dropping data # observations use [coord_cartesian()]. Setting the limits on the # coordinate system performs a visual zoom. p + coord_cartesian(xlim =c(Sys.Date() - 30, NA), ylim = c(10, 20)) </pre> <hr /><div style="text-align: center;">[Package <em>ggplot2</em> version 3.3.2 <a href="00Index.html">Index</a>]</div> </body></html>