EVOLUTION-MANAGER
Edit File: colorRamp.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: Color interpolation</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 colorRamp {grDevices}"><tr><td>colorRamp {grDevices}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Color interpolation</h2> <h3>Description</h3> <p>These functions return functions that interpolate a set of given colors to create new color palettes (like <code><a href="palettes.html">topo.colors</a></code>) and color ramps, functions that map the interval <i>[0, 1]</i> to colors (like <code><a href="gray.html">grey</a></code>). </p> <h3>Usage</h3> <pre> colorRamp(colors, bias = 1, space = c("rgb", "Lab"), interpolate = c("linear", "spline"), alpha = FALSE) colorRampPalette(colors, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>colors</code></td> <td> <p>colors to interpolate; must be a valid argument to <code><a href="col2rgb.html">col2rgb</a>()</code>.</p> </td></tr> <tr valign="top"><td><code>bias</code></td> <td> <p>a positive number. Higher values give more widely spaced colors at the high end.</p> </td></tr> <tr valign="top"><td><code>space</code></td> <td> <p>a character string; interpolation in RGB or CIE Lab color spaces.</p> </td></tr> <tr valign="top"><td><code>interpolate</code></td> <td> <p>use spline or linear interpolation.</p> </td></tr> <tr valign="top"><td><code>alpha</code></td> <td> <p>logical: should alpha channel (opacity) values be returned? It is an error to give a true value if <code>space</code> is specified.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>arguments to pass to <code>colorRamp</code>.</p> </td></tr> </table> <h3>Details</h3> <p>The CIE Lab color space is approximately perceptually uniform, and so gives smoother and more uniform color ramps. On the other hand, palettes that vary from one hue to another via white may have a more symmetrical appearance in RGB space. </p> <p>The conversion formulas in this function do not appear to be completely accurate and the color ramp may not reach the extreme values in Lab space. Future changes in the <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> color model may change the colors produced with <code>space = "Lab"</code>. </p> <h3>Value</h3> <p><code>colorRamp</code> returns a <code><a href="../../base/html/function.html">function</a></code> with argument a vector of values between 0 and 1 that are mapped to a numeric matrix of RGB color values with one row per color and 3 or 4 columns. </p> <p><code>colorRampPalette</code> returns a function that takes an integer argument (the required number of colors) and returns a character vector of colors (see <code><a href="rgb.html">rgb</a></code>) interpolating the given sequence (similar to <code><a href="palettes.html">heat.colors</a></code> or <code><a href="palettes.html">terrain.colors</a></code>). </p> <h3>See Also</h3> <p>Good starting points for interpolation are the “sequential” and “diverging” ColorBrewer palettes in the <a href="https://CRAN.R-project.org/package=RColorBrewer"><span class="pkg">RColorBrewer</span></a> package. </p> <p><code><a href="../../stats/html/splinefun.html">splinefun</a></code> or <code><a href="../../stats/html/approxfun.html">approxfun</a></code> are used for interpolation. </p> <h3>Examples</h3> <pre> ## Both return a *function* : colorRamp(c("red", "green"))( (0:4)/4 ) ## (x) , x in [0,1] colorRampPalette(c("blue", "red"))( 4 ) ## (n) ## a ramp in opacity of blue values colorRampPalette(c(rgb(0,0,1,1), rgb(0,0,1,0)), alpha = TRUE)(8) require(graphics) ## Here space="rgb" gives palettes that vary only in saturation, ## as intended. ## With space="Lab" the steps are more uniform, but the hues ## are slightly purple. filled.contour(volcano, color.palette = colorRampPalette(c("red", "white", "blue")), asp = 1) filled.contour(volcano, color.palette = colorRampPalette(c("red", "white", "blue"), space = "Lab"), asp = 1) ## Interpolating a 'sequential' ColorBrewer palette YlOrBr <- c("#FFFFD4", "#FED98E", "#FE9929", "#D95F0E", "#993404") filled.contour(volcano, color.palette = colorRampPalette(YlOrBr, space = "Lab"), asp = 1) filled.contour(volcano, color.palette = colorRampPalette(YlOrBr, space = "Lab", bias = 0.5), asp = 1) ## 'jet.colors' is "as in Matlab" ## (and hurting the eyes by over-saturation) jet.colors <- colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan", "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000")) filled.contour(volcano, color = jet.colors, asp = 1) ## space="Lab" helps when colors don't form a natural sequence m <- outer(1:20,1:20,function(x,y) sin(sqrt(x*y)/3)) rgb.palette <- colorRampPalette(c("red", "orange", "blue"), space = "rgb") Lab.palette <- colorRampPalette(c("red", "orange", "blue"), space = "Lab") filled.contour(m, col = rgb.palette(20)) filled.contour(m, col = Lab.palette(20)) </pre> <hr /><div style="text-align: center;">[Package <em>grDevices</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>