EVOLUTION-MANAGER
Edit File: scale_gradient.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: Gradient colour scales</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_colour_gradient {ggplot2}"><tr><td>scale_colour_gradient {ggplot2}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Gradient colour scales</h2> <h3>Description</h3> <p><code style="white-space: pre;">scale_*_gradient</code> creates a two colour gradient (low-high), <code style="white-space: pre;">scale_*_gradient2</code> creates a diverging colour gradient (low-mid-high), <code style="white-space: pre;">scale_*_gradientn</code> creates a n-colour gradient. </p> <h3>Usage</h3> <pre> scale_colour_gradient( ..., low = "#132B43", high = "#56B1F7", space = "Lab", na.value = "grey50", guide = "colourbar", aesthetics = "colour" ) scale_fill_gradient( ..., low = "#132B43", high = "#56B1F7", space = "Lab", na.value = "grey50", guide = "colourbar", aesthetics = "fill" ) scale_colour_gradient2( ..., low = muted("red"), mid = "white", high = muted("blue"), midpoint = 0, space = "Lab", na.value = "grey50", guide = "colourbar", aesthetics = "colour" ) scale_fill_gradient2( ..., low = muted("red"), mid = "white", high = muted("blue"), midpoint = 0, space = "Lab", na.value = "grey50", guide = "colourbar", aesthetics = "fill" ) scale_colour_gradientn( ..., colours, values = NULL, space = "Lab", na.value = "grey50", guide = "colourbar", aesthetics = "colour", colors ) scale_fill_gradientn( ..., colours, values = NULL, space = "Lab", na.value = "grey50", guide = "colourbar", aesthetics = "fill", colors ) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>...</code></td> <td> <p>Arguments passed on to <code><a href="continuous_scale.html">continuous_scale</a></code> </p> <dl> <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>palette</code></dt><dd><p>A palette function that when called with a numeric vector with values between 0 and 1 returns the corresponding output values (e.g., <code><a href="../../scales/html/area_pal.html">scales::area_pal()</a></code>).</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>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 computed by the <a href="../../scales/html/trans_new.html">transformation object</a> </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 (e.g., a function returned by <code><a href="../../scales/html/breaks_extended.html">scales::extended_breaks()</a></code>) </p> </li></ul> </dd> <dt><code>minor_breaks</code></dt><dd><p>One of: </p> <ul> <li> <p><code>NULL</code> for no minor breaks </p> </li> <li> <p><code>waiver()</code> for the default breaks (one minor break between each major break) </p> </li> <li><p> A numeric vector of positions </p> </li> <li><p> A function that given the limits returns a vector of minor breaks. </p> </li></ul> </dd> <dt><code>n.breaks</code></dt><dd><p>An integer guiding the number of major breaks. The algorithm may choose a slightly different number to ensure nice break labels. Will only have an effect if <code>breaks = waiver()</code>. Use <code>NULL</code> to use the default number of breaks given by the transformation.</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>limits</code></dt><dd><p>One of: </p> <ul> <li> <p><code>NULL</code> to use the default scale range </p> </li> <li><p> A numeric vector of length two providing limits of the scale. Use <code>NA</code> to refer to the existing minimum or maximum </p> </li> <li><p> A function that accepts the existing (automatic) limits and returns new limits Note that setting limits on positional scales will <strong>remove</strong> data outside of the limits. If the purpose is to zoom, use the limit argument in the coordinate system (see <code><a href="coord_cartesian.html">coord_cartesian()</a></code>). </p> </li></ul> </dd> <dt><code>rescaler</code></dt><dd><p>A function used to scale the input values to the range [0, 1]. This is always <code><a href="../../scales/html/rescale.html">scales::rescale()</a></code>, except for diverging and n colour gradients (i.e., <code><a href="scale_gradient.html">scale_colour_gradient2()</a></code>, <code><a href="scale_gradient.html">scale_colour_gradientn()</a></code>). The <code>rescaler</code> is ignored by position scales, which always use <code><a href="../../scales/html/rescale.html">scales::rescale()</a></code>.</p> </dd> <dt><code>oob</code></dt><dd><p>One of: </p> <ul> <li><p> Function that handles limits outside of the scale limits (out of bounds). </p> </li> <li><p> The default (<code><a href="../../scales/html/oob.html">scales::censor()</a></code>) replaces out of bounds values with <code>NA</code>. </p> </li> <li> <p><code><a href="../../scales/html/oob.html">scales::squish()</a></code> for squishing out of bounds values into range. </p> </li> <li> <p><code><a href="../../scales/html/oob.html">scales::squish_infinite()</a></code> for squishing infinite values into range. </p> </li></ul> </dd> <dt><code>trans</code></dt><dd><p>For continuous scales, the name of a transformation object or the object itself. Built-in transformations include "asn", "atanh", "boxcox", "date", "exp", "hms", "identity", "log", "log10", "log1p", "log2", "logit", "modulus", "probability", "probit", "pseudo_log", "reciprocal", "reverse", "sqrt" and "time". </p> <p>A transformation object bundles together a transform, its inverse, and methods for generating breaks and labels. Transformation objects are defined in the scales package, and are called <code style="white-space: pre;"><name>_trans</code> (e.g., <code><a href="../../scales/html/boxcox_trans.html">scales::boxcox_trans()</a></code>). You can create your own transformation with <code><a href="../../scales/html/trans_new.html">scales::trans_new()</a></code>.</p> </dd> <dt><code>expand</code></dt><dd><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> </dd> <dt><code>position</code></dt><dd><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> </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>low, high</code></td> <td> <p>Colours for low and high ends of the gradient.</p> </td></tr> <tr valign="top"><td><code>space</code></td> <td> <p>colour space in which to calculate gradient. Must be "Lab" - other values are deprecated.</p> </td></tr> <tr valign="top"><td><code>na.value</code></td> <td> <p>Colour to use for missing values</p> </td></tr> <tr valign="top"><td><code>guide</code></td> <td> <p>Type of legend. Use <code>"colourbar"</code> for continuous colour bar, or <code>"legend"</code> for discrete colour legend.</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>mid</code></td> <td> <p>colour for mid point</p> </td></tr> <tr valign="top"><td><code>midpoint</code></td> <td> <p>The midpoint (in data value) of the diverging scale. Defaults to 0.</p> </td></tr> <tr valign="top"><td><code>colours, colors</code></td> <td> <p>Vector of colours to use for n-colour gradient.</p> </td></tr> <tr valign="top"><td><code>values</code></td> <td> <p>if colours should not be evenly positioned along the gradient this vector gives the position (between 0 and 1) for each colour in the <code>colours</code> vector. See <code><a href="../../scales/html/rescale.html">rescale()</a></code> for a convenience function to map an arbitrary range to between 0 and 1.</p> </td></tr> </table> <h3>Details</h3> <p>Default colours are generated with <span class="pkg">munsell</span> and <code>mnsl(c("2.5PB 2/4", "2.5PB 7/10"))</code>. Generally, for continuous colour scales you want to keep hue constant, but vary chroma and luminance. The <span class="pkg">munsell</span> package makes this easy to do using the Munsell colour system. </p> <h3>See Also</h3> <p><code><a href="../../scales/html/seq_gradient_pal.html">scales::seq_gradient_pal()</a></code> for details on underlying palette </p> <p>Other colour scales: <code><a href="scale_alpha.html">scale_alpha</a>()</code>, <code><a href="scale_brewer.html">scale_colour_brewer</a>()</code>, <code><a href="scale_grey.html">scale_colour_grey</a>()</code>, <code><a href="scale_hue.html">scale_colour_hue</a>()</code>, <code><a href="scale_steps.html">scale_colour_steps</a>()</code>, <code><a href="scale_viridis.html">scale_colour_viridis_d</a>()</code> </p> <h3>Examples</h3> <pre> df <- data.frame( x = runif(100), y = runif(100), z1 = rnorm(100), z2 = abs(rnorm(100)) ) df_na <- data.frame( value = seq(1, 20), x = runif(20), y = runif(20), z1 = c(rep(NA, 10), rnorm(10)) ) # Default colour scale colours from light blue to dark blue ggplot(df, aes(x, y)) + geom_point(aes(colour = z2)) # For diverging colour scales use gradient2 ggplot(df, aes(x, y)) + geom_point(aes(colour = z1)) + scale_colour_gradient2() # Use your own colour scale with gradientn ggplot(df, aes(x, y)) + geom_point(aes(colour = z1)) + scale_colour_gradientn(colours = terrain.colors(10)) # Equivalent fill scales do the same job for the fill aesthetic ggplot(faithfuld, aes(waiting, eruptions)) + geom_raster(aes(fill = density)) + scale_fill_gradientn(colours = terrain.colors(10)) # Adjust colour choices with low and high ggplot(df, aes(x, y)) + geom_point(aes(colour = z2)) + scale_colour_gradient(low = "white", high = "black") # Avoid red-green colour contrasts because ~10% of men have difficulty # seeing them # Use `na.value = NA` to hide missing values but keep the original axis range ggplot(df_na, aes(x = value, y)) + geom_bar(aes(fill = z1), stat = "identity") + scale_fill_gradient(low = "yellow", high = "red", na.value = NA) ggplot(df_na, aes(x, y)) + geom_point(aes(colour = z1)) + scale_colour_gradient(low = "yellow", high = "red", na.value = NA) </pre> <hr /><div style="text-align: center;">[Package <em>ggplot2</em> version 3.3.2 <a href="00Index.html">Index</a>]</div> </body></html>