EVOLUTION-MANAGER
Edit File: scale_manual.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: Create your own discrete scale</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_manual {ggplot2}"><tr><td>scale_manual {ggplot2}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Create your own discrete scale</h2> <h3>Description</h3> <p>These functions allow you to specify your own set of mappings from levels in the data to aesthetic values. </p> <h3>Usage</h3> <pre> scale_colour_manual(..., values, aesthetics = "colour", breaks = waiver()) scale_fill_manual(..., values, aesthetics = "fill", breaks = waiver()) scale_size_manual(..., values, breaks = waiver()) scale_shape_manual(..., values, breaks = waiver()) scale_linetype_manual(..., values, breaks = waiver()) scale_alpha_manual(..., values, breaks = waiver()) scale_discrete_manual(aesthetics, ..., values, breaks = waiver()) </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>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>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>guide</code></dt><dd><p>A function used to create a guide or its name. See <code><a href="guides.html">guides()</a></code> for more information.</p> </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>values</code></td> <td> <p>a set of aesthetic values to map data values to. The values will be matched in order (usually alphabetical) with the limits of the scale, or with <code>breaks</code> if provided. If this is a named vector, then the values will be matched based on the names instead. Data values that don't match will be given <code>na.value</code>.</p> </td></tr> <tr valign="top"><td><code>aesthetics</code></td> <td> <p>Character string or vector of character strings listing the name(s) of the aesthetic(s) that this scale works with. This can be useful, for example, to apply colour settings to the <code>colour</code> and <code>fill</code> aesthetics at the same time, via <code>aesthetics = c("colour", "fill")</code>.</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 (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> </td></tr> </table> <h3>Details</h3> <p>The functions <code>scale_colour_manual()</code>, <code>scale_fill_manual()</code>, <code>scale_size_manual()</code>, etc. work on the aesthetics specified in the scale name: <code>colour</code>, <code>fill</code>, <code>size</code>, etc. However, the functions <code>scale_colour_manual()</code> and <code>scale_fill_manual()</code> also have an optional <code>aesthetics</code> argument that can be used to define both <code>colour</code> and <code>fill</code> aesthetic mappings via a single function call (see examples). The function <code>scale_discrete_manual()</code> is a generic scale that can work with any aesthetic or set of aesthetics provided via the <code>aesthetics</code> argument. </p> <h3>Color Blindness</h3> <p>Many color palettes derived from RGB combinations (like the "rainbow" color palette) are not suitable to support all viewers, especially those with color vision deficiencies. Using <code>viridis</code> type, which is perceptually uniform in both colour and black-and-white display is an easy option to ensure good perceptive properties of your visulizations. The colorspace package offers functionalities </p> <ul> <li><p> to generate color palettes with good perceptive properties, </p> </li> <li><p> to analyse a given color palette, like emulating color blindness, </p> </li> <li><p> and to modify a given color palette for better perceptivity. </p> </li></ul> <p>For more information on color vision deficiencies and suitable color choices see the <a href="https://arxiv.org/abs/1903.06490">paper on the colorspace package</a> and references therein. </p> <h3>Examples</h3> <pre> p <- ggplot(mtcars, aes(mpg, wt)) + geom_point(aes(colour = factor(cyl))) p + scale_colour_manual(values = c("red", "blue", "green")) # It's recommended to use a named vector cols <- c("8" = "red", "4" = "blue", "6" = "darkgreen", "10" = "orange") p + scale_colour_manual(values = cols) # You can set color and fill aesthetics at the same time ggplot( mtcars, aes(mpg, wt, colour = factor(cyl), fill = factor(cyl)) ) + geom_point(shape = 21, alpha = 0.5, size = 2) + scale_colour_manual( values = cols, aesthetics = c("colour", "fill") ) # As with other scales you can use breaks to control the appearance # of the legend. p + scale_colour_manual(values = cols) p + scale_colour_manual( values = cols, breaks = c("4", "6", "8"), labels = c("four", "six", "eight") ) # And limits to control the possible values of the scale p + scale_colour_manual(values = cols, limits = c("4", "8")) p + scale_colour_manual(values = cols, limits = c("4", "6", "8", "10")) </pre> <hr /><div style="text-align: center;">[Package <em>ggplot2</em> version 3.3.2 <a href="00Index.html">Index</a>]</div> </body></html>