EVOLUTION-MANAGER
Edit File: scale_discrete.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: Position scales for discrete data</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 scale_x_discrete {ggplot2}"><tr><td>scale_x_discrete {ggplot2}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Position scales for discrete data</h2> <h3>Description</h3> <p><code>scale_x_discrete()</code> and <code>scale_y_discrete()</code> are used to set the values for discrete x and y scale aesthetics. For simple manipulation of scale labels and limits, you may wish to use <code><a href="labs.html">labs()</a></code> and <code><a href="lims.html">lims()</a></code> instead. </p> <h3>Usage</h3> <pre> scale_x_discrete(..., expand = waiver(), guide = waiver(), position = "bottom") scale_y_discrete(..., expand = waiver(), guide = waiver(), position = "left") </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>...</code></td> <td> <p>Arguments passed on to <code><a href="discrete_scale.html">discrete_scale</a></code> </p> <dl> <dt><code>palette</code></dt><dd><p>A palette function that when called with a single integer argument (the number of levels in the scale) returns the values that they should take (e.g., <code><a href="../../scales/html/hue_pal.html">scales::hue_pal()</a></code>).</p> </dd> <dt><code>breaks</code></dt><dd><p>One of: </p> <ul> <li> <p><code>NULL</code> for no breaks </p> </li> <li> <p><code>waiver()</code> for the default breaks (the scale limits) </p> </li> <li><p> A character vector of breaks </p> </li> <li><p> A function that takes the limits as input and returns breaks as output </p> </li></ul> </dd> <dt><code>limits</code></dt><dd><p>One of: </p> <ul> <li> <p><code>NULL</code> to use the default scale values </p> </li> <li><p> A character vector that defines possible values of the scale and their order </p> </li> <li><p> A function that accepts the existing (automatic) values and returns new ones </p> </li></ul> </dd> <dt><code>drop</code></dt><dd><p>Should unused factor levels be omitted from the scale? The default, <code>TRUE</code>, uses the levels that appear in the data; <code>FALSE</code> uses all the levels in the factor.</p> </dd> <dt><code>na.translate</code></dt><dd><p>Unlike continuous scales, discrete scales can easily show missing values, and do so by default. If you want to remove missing values from a discrete scale, specify <code>na.translate = FALSE</code>.</p> </dd> <dt><code>na.value</code></dt><dd><p>If <code>na.translate = TRUE</code>, what aesthetic value should the missing values be displayed as? Does not apply to position scales where <code>NA</code> is always placed at the far right.</p> </dd> <dt><code>aesthetics</code></dt><dd><p>The names of the aesthetics that this scale works with.</p> </dd> <dt><code>scale_name</code></dt><dd><p>The name of the scale that should be used for error messages associated with this scale.</p> </dd> <dt><code>name</code></dt><dd><p>The name of the scale. Used as the axis or legend title. If <code>waiver()</code>, the default, the name of the scale is taken from the first mapping used for that aesthetic. If <code>NULL</code>, the legend title will be omitted.</p> </dd> <dt><code>labels</code></dt><dd><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> </dd> <dt><code>super</code></dt><dd><p>The super class to use for the constructed scale</p> </dd> </dl> </td></tr> <tr valign="top"><td><code>expand</code></td> <td> <p>For position scales, a vector of range expansion constants used to add some padding around the data to ensure that they are placed some distance away from the axes. Use the convenience function <code><a href="expansion.html">expansion()</a></code> to generate the values for the <code>expand</code> argument. The defaults are to expand the scale by 5% on each side for continuous variables, and by 0.6 units on each side for discrete variables.</p> </td></tr> <tr valign="top"><td><code>guide</code></td> <td> <p>A function used to create a guide or its name. See <code><a href="guides.html">guides()</a></code> for more information.</p> </td></tr> <tr valign="top"><td><code>position</code></td> <td> <p>For position scales, The position of the axis. <code>left</code> or <code>right</code> for y axes, <code>top</code> or <code>bottom</code> for x axes.</p> </td></tr> </table> <h3>Details</h3> <p>You can use continuous positions even with a discrete position scale - this allows you (e.g.) to place labels between bars in a bar chart. Continuous positions are numeric values starting at one for the first level, and increasing by one for each level (i.e. the labels are placed at integer positions). This is what allows jittering to work. </p> <h3>See Also</h3> <p>Other position scales: <code><a href="scale_binned.html">scale_x_binned</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> ggplot(diamonds, aes(cut)) + geom_bar() # The discrete position scale is added automatically whenever you # have a discrete position. (d <- ggplot(subset(diamonds, carat > 1), aes(cut, clarity)) + geom_jitter()) d + scale_x_discrete("Cut") d + scale_x_discrete("Cut", labels = c("Fair" = "F","Good" = "G", "Very Good" = "VG","Perfect" = "P","Ideal" = "I")) # Use limits to adjust the which levels (and in what order) # are displayed d + scale_x_discrete(limits = c("Fair","Ideal")) # you can also use the short hand functions xlim and ylim d + xlim("Fair","Ideal", "Good") d + ylim("I1", "IF") # See ?reorder to reorder based on the values of another variable ggplot(mpg, aes(manufacturer, cty)) + geom_point() ggplot(mpg, aes(reorder(manufacturer, cty), cty)) + geom_point() ggplot(mpg, aes(reorder(manufacturer, displ), cty)) + geom_point() # Use abbreviate as a formatter to reduce long names ggplot(mpg, aes(reorder(manufacturer, displ), cty)) + geom_point() + scale_x_discrete(labels = abbreviate) </pre> <hr /><div style="text-align: center;">[Package <em>ggplot2</em> version 3.3.2 <a href="00Index.html">Index</a>]</div> </body></html>