<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><title>Calculate a Color Map — colormap • oce</title><script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="../deps/bootstrap-5.3.1/bootstrap.min.css" rel="stylesheet"><script src="../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><link href="../deps/font-awesome-6.4.2/css/all.min.css" rel="stylesheet"><link href="../deps/font-awesome-6.4.2/css/v4-shims.min.css" rel="stylesheet"><script src="../deps/headroom-0.11.0/headroom.min.js"></script><script src="../deps/headroom-0.11.0/jQuery.headroom.min.js"></script><script src="../deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script><script src="../deps/clipboard.js-2.0.11/clipboard.min.js"></script><script src="../deps/search-1.0.0/autocomplete.jquery.min.js"></script><script src="../deps/search-1.0.0/fuse.min.js"></script><script src="../deps/search-1.0.0/mark.min.js"></script><!-- pkgdown --><script src="../pkgdown.js"></script><meta property="og:title" content="Calculate a Color Map — colormap"><meta name="description" content="Create a mapping between numeric values and colors, for use in palettes and plots.
The return value can be used in various ways, including colorizing points
on scattergraphs, controlling images created by image() or imagep(),
drawing palettes with drawPalette(), etc."><meta property="og:description" content="Create a mapping between numeric values and colors, for use in palettes and plots.
The return value can be used in various ways, including colorizing points
on scattergraphs, controlling images created by image() or imagep(),
drawing palettes with drawPalette(), etc."></head><body>
    <a href="#main" class="visually-hidden-focusable">Skip to contents</a>


    <nav class="navbar navbar-expand-lg fixed-top bg-light" data-bs-theme="light" aria-label="Site navigation"><div class="container">

    <a class="navbar-brand me-2" href="../index.html">oce</a>

    <small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">1.8-4</small>


    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div id="navbar" class="collapse navbar-collapse ms-3">
      <ul class="navbar-nav me-auto"><li class="active nav-item"><a class="nav-link" href="../reference/index.html">Reference</a></li>
<li class="nav-item dropdown">
  <button class="nav-link dropdown-toggle" type="button" id="dropdown-articles" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true">Articles</button>
  <ul class="dropdown-menu" aria-labelledby="dropdown-articles"><li><a class="dropdown-item" href="../articles/A_oce.html">1. Introduction to Oce</a></li>
    <li><a class="dropdown-item" href="../articles/B_ctd.html">2. Analysis of CTD data</a></li>
    <li><a class="dropdown-item" href="../articles/C_adp.html">3. Analysis of acoustic-Doppler data</a></li>
    <li><a class="dropdown-item" href="../articles/D_map_projections.html">4. Using map projections</a></li>
    <li><a class="dropdown-item" href="../articles/E_flags.html">5. Dealing with data-quality flags</a></li>
    <li><a class="dropdown-item" href="../articles/F_subclassing.html">6. Subclassing oce objects</a></li>
    <li><a class="dropdown-item" href="../articles/G_altering_defaults.html">7. Altering oce Defaults</a></li>
    <li><a class="dropdown-item" href="../articles/H_tides.html">8. Tidal Analysis</a></li>
  </ul></li>
<li class="nav-item"><a class="nav-link" href="../news/index.html">Changelog</a></li>
      </ul><ul class="navbar-nav"><li class="nav-item"><form class="form-inline" role="search">
 <input class="form-control" type="search" name="search-input" id="search-input" autocomplete="off" aria-label="Search site" placeholder="Search for" data-search-index="../search.json"></form></li>
<li class="nav-item"><a class="external-link nav-link" href="https://github.com/dankelley/oce/" aria-label="GitHub"><span class="fa fab fa-github fa-lg"></span></a></li>
      </ul></div>


  </div>
</nav><div class="container template-reference-topic">
<div class="row">
  <main id="main" class="col-md-9"><div class="page-header">

      <h1>Calculate a Color Map</h1>
      <small class="dont-index">Source: <a href="https://github.com/dankelley/oce/blob/HEAD/R/colors.R" class="external-link"><code>R/colors.R</code></a></small>
      <div class="d-none name"><code>colormap.Rd</code></div>
    </div>

    <div class="ref-description section level2">
    <p>Create a mapping between numeric values and colors, for use in palettes and plots.
The return value can be used in various ways, including colorizing points
on scattergraphs, controlling images created by <code><a href="https://rdrr.io/r/graphics/image.html" class="external-link">image()</a></code> or <code><a href="imagep.html">imagep()</a></code>,
drawing palettes with <code><a href="drawPalette.html">drawPalette()</a></code>, etc.</p>
    </div>

    <div class="section level2">
    <h2 id="ref-usage">Usage<a class="anchor" aria-label="anchor" href="#ref-usage"></a></h2>
    <div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">colormap</span><span class="op">(</span></span>
<span>  z <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  <span class="va">zlim</span>,</span>
<span>  zclip <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span>  <span class="va">breaks</span>,</span>
<span>  col <span class="op">=</span> <span class="va">oceColorsViridis</span>,</span>
<span>  <span class="va">name</span>,</span>
<span>  <span class="va">x0</span>,</span>
<span>  <span class="va">x1</span>,</span>
<span>  <span class="va">col0</span>,</span>
<span>  <span class="va">col1</span>,</span>
<span>  blend <span class="op">=</span> <span class="fl">0</span>,</span>
<span>  <span class="va">missingColor</span>,</span>
<span>  debug <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/options.html" class="external-link">getOption</a></span><span class="op">(</span><span class="st">"oceDebug"</span><span class="op">)</span></span>
<span><span class="op">)</span></span></code></pre></div>
    </div>

    <div class="section level2">
    <h2 id="arguments">Arguments<a class="anchor" aria-label="anchor" href="#arguments"></a></h2>


<dl><dt id="arg-z">z<a class="anchor" aria-label="anchor" href="#arg-z"></a></dt>
<dd><p>an optional vector or other set of numerical values to be examined.
If <code>z</code> is given, the return value will contain an item named
<code>zcol</code> that will be a vector of the same length as <code>z</code>, containing
a color for each point.  If <code>z</code> is not given, <code>zcol</code> will contain
just one item, the color <code>"black"</code>.</p></dd>


<dt id="arg-zlim">zlim<a class="anchor" aria-label="anchor" href="#arg-zlim"></a></dt>
<dd><p>optional vector containing two numbers that specify the <code>z</code>
limits for the color scale. This can only be provided in cases A
and B, as defined in “Details”.  For case A, if <code>zlim</code> is not
provided, then it is inferred by using <code><a href="rangeExtended.html">rangeExtended()</a></code>
on <code>breaks</code>, if that is provided, or from <code>z</code> otherwise.  Also,
in case A, it is an error to provide both <code>zlim</code> and <code>breaks</code>,
unless the latter is of length 1, meaning the number of
subdivisions to use within the range set by <code>zlim</code>.
In case B, <code>zlim</code> is inferred from using <code><a href="rangeExtended.html">rangeExtended()</a></code> on <code>c(x0,x1)</code>.
In case C, providing <code>zlim</code> yields an error message, because it makes no
sense in the context of a named, predefined color scheme.</p></dd>


<dt id="arg-zclip">zclip<a class="anchor" aria-label="anchor" href="#arg-zclip"></a></dt>
<dd><p>logical, with <code>TRUE</code> indicating that z values outside the
range of <code>zlim</code> or <code>breaks</code> should be painted with
<code>missingColor</code> and <code>FALSE</code> indicating that these values should be
painted with the nearest in-range color.</p></dd>


<dt id="arg-breaks">breaks<a class="anchor" aria-label="anchor" href="#arg-breaks"></a></dt>
<dd><p>an optional indication of break points between color levels
(see <code><a href="https://rdrr.io/r/graphics/image.html" class="external-link">image()</a></code>).  If this is provided, the arguments <code>name</code>
through <code>blend</code> are all ignored (see “Details”).  If it is
provided, then it may either be a vector of break points, or a single number
indicating the desired number of break points to be computed with
<code><a href="https://rdrr.io/r/base/pretty.html" class="external-link">pretty</a></code><code>(z,breaks)</code>.  In either case of non-missing
<code>breaks</code>, the resultant break points must number 1 plus the number of
colors (see <code>col</code>).</p></dd>


<dt id="arg-col">col<a class="anchor" aria-label="anchor" href="#arg-col"></a></dt>
<dd><p>either a vector of colors or a function taking a numerical value
as its single argument and returning a vector of colors.  Prior to 2021-02-08,
the default for <code>col</code> was <code>oceColorsJet</code>, but it was switched to
<code>oceColorsViridis</code> on that date.  The value of
<code>col</code> is ignored if <code>name</code> is provided, or if <code>x0</code> through
<code>col1</code> are provided.</p></dd>


<dt id="arg-name">name<a class="anchor" aria-label="anchor" href="#arg-name"></a></dt>
<dd><p>an optional string naming a built-in colormap (one of
<code>"gmt_relief"</code>, <code>"gmt_ocean"</code>, <code>"gmt_globe"</code> or
<code>"gmt_gebco"</code>) or the name of a file or URL that contains a color map
specification in GMT format.  If <code>name</code> is given, then it is
passed to <code><a href="colormapGMT.html">colormapGMT()</a></code>, which creates the colormap.
Note that the colormap thus created has a fixed
relationship between value and color, and <code>zlim</code>,
only other argument that is examined is <code>z</code> (which may be used
so that <code>zcol</code> will be defined in the return value), and warnings
are issued if some irrelevant arguments are provided.</p></dd>


<dt id="arg-x-x-col-col-">x0, x1, col0, col1<a class="anchor" aria-label="anchor" href="#arg-x-x-col-col-"></a></dt>
<dd><p>Vectors that specify a color map.  They must all be
the same length, with <code>x0</code> and <code>x1</code> being numerical values, and
<code>col0</code> and <code>col1</code> being colors.  The colors may be strings (e.g.
<code>"red"</code>) or colors as defined by <code><a href="https://rdrr.io/r/grDevices/rgb.html" class="external-link">rgb()</a></code> or <code><a href="https://rdrr.io/r/grDevices/hsv.html" class="external-link">hsv()</a></code>.</p></dd>


<dt id="arg-blend">blend<a class="anchor" aria-label="anchor" href="#arg-blend"></a></dt>
<dd><p>a number indicating how to blend colors within each band.
This is ignored except when <code>x0</code> through <code>col1</code> are supplied.  A
value of 0 means to use <code>col0[i]</code> through the interval <code>x0[i]</code> to
<code>x1[i]</code>.  A value of 1 means to use <code>col1[i]</code> in that interval.  A
value between 0 and 1 means to blend between the two colors according to
the stated fraction.  Values exceeding 1 are an error at present, but there
is a plan to use this to indicate sub-intervals, so a smooth palette can be
created from a few colors.</p></dd>


<dt id="arg-missingcolor">missingColor<a class="anchor" aria-label="anchor" href="#arg-missingcolor"></a></dt>
<dd><p>color to use for missing values. This cannot be provided
if <code>name</code> is also provided (case C), because named schemes have pre-defined
colors.  For other cases, <code>missingColor</code> defaults to <code>"gray"</code>, if it
is not provided as an argument.</p></dd>


<dt id="arg-debug">debug<a class="anchor" aria-label="anchor" href="#arg-debug"></a></dt>
<dd><p>a flag that turns on debugging.  Set to 1 to get a moderate
amount of debugging information, or to 2 to get more.</p></dd>

</dl></div>
    <div class="section level2">
    <h2 id="value">Value<a class="anchor" aria-label="anchor" href="#value"></a></h2>
    <p>a list containing the following (not necessarily in this order)</p><ul><li><p><code>zcol</code>, a vector of colors for <code>z</code>, if <code>z</code> was
provided, otherwise <code>"black"</code></p></li>
<li><p><code>zlim</code>, a two-element vector suitable as the argument of the same
name supplied to <code><a href="https://rdrr.io/r/graphics/image.html" class="external-link">image()</a></code> or <code><a href="imagep.html">imagep()</a></code></p></li>
<li><p><code>breaks</code> and <code>col</code>, vectors of breakpoints and colors,
suitable as the same-named arguments to <code><a href="https://rdrr.io/r/graphics/image.html" class="external-link">image()</a></code> or
<code><a href="imagep.html">imagep()</a></code></p></li>
<li><p><code>zclip</code> the provided value of <code>zclip</code>.</p></li>
<li><p><code>x0</code> and <code>x1</code>, numerical vectors of the sides of color
intervals, and <code>col0</code> and <code>col1</code>, vectors of corresponding
colors.  The meaning is the same as on input.  The purpose of returning
these four vectors is to permit users to alter color mapping, as in example
3 in “Examples”.</p></li>
<li><p><code>missingColor</code>, a color that could be used to specify missing
values, e.g. as the same-named argument to <code><a href="imagep.html">imagep()</a></code>.</p></li>
<li><p><code>colfunction</code>, a univariate function that returns a vector
of colors, given a vector of <code>z</code> values; see Example 6.</p></li>
</ul></div>
    <div class="section level2">
    <h2 id="details">Details<a class="anchor" aria-label="anchor" href="#details"></a></h2>
    <p><code>colormap</code> can be used in a variety of ways, including the following.</p><ul><li><p><strong>Case A.</strong> Supply some combination of arguments that
is sufficient to define a mapping of value to color, without
providing <code>x0</code>, <code>col0</code>, <code>x1</code> or <code>col1</code> (see case B for these),
or providing <code>name</code> (see Case C). There are several ways to
do this.  One approach is to supply <code>z</code> but no
other argument, in which case <code>zlim</code>, and <code>breaks</code> will be determined
from <code>z</code>, and the default <code>col</code> will be used.  Another approach is
to specify <code>breaks</code> and <code>col</code> together, in the same way as they
might be specified for the base R function <code><a href="https://rdrr.io/r/graphics/image.html" class="external-link">image()</a></code>.  It is
also possible to supply only <code>zlim</code>, in which case <code>breaks</code> is
inferred from that value.
The figure below explains the
(`breaks`, `col`) method of specifying a color mapping.  Note
that there must be one more break than color.  This is the method used by
e.g. [image()].
<img src="figures/colormap_fig_1.png" alt=""></p></li>
<li><p><strong>Case B.</strong> Supply <code>x0</code>, <code>col0</code>, <code>x1</code>, and <code>col1</code>, but <em>not</em>
<code>zlim</code>, <code>breaks</code>, <code>col</code> or <code>name</code>.
The <code>x0</code>, <code>col0</code>, <code>x1</code> and <code>col1</code> values specify a
value-color mapping that is similar to that used
for GMT color maps.  The method works by using <code><a href="https://rdrr.io/r/base/seq.html" class="external-link">seq()</a></code> to
interpolate between the elements of the <code>x0</code> vector.  The same is done
for <code>x1</code>.  Similarly, <code><a href="https://rdrr.io/r/grDevices/colorRamp.html" class="external-link">colorRampPalette()</a></code> is used to
interpolate between the colors in the <code>col0</code> vector, and the same is
done for <code>col1</code>.  The figure above explains the (`x0`,
`x1`, `col0`, `col1`) method of specifying a color mapping.
Note that the each of the items has the same length. The case of
`blend=0`, which has color `col0[i]` between `x0[i]` and
`x1[i]`, is illustrated below.
<img src="figures/colormap_fig_2.png" alt=""></p></li>
<li><p><strong>Case C.</strong> Supply <code>name</code> and possibly also <code>z</code>, but <em>not</em>
<code>zlim</code>, <code>breaks</code>, <code>col</code>, <code>x0</code>, <code>col0</code>, <code>x1</code> or <code>col1</code>.
The <code>name</code> may be the name of a pre-defined color palette
(<code>"gmt_relief"</code>, <code>"gmt_ocean"</code>, <code>"gmt_globe"</code> or
<code>"gmt_gebco"</code>), or it may be the name of a file (or URL pointing to a file)
that contains a color map in the GMT format (see “References”). If
<code>z</code> is supplied along with <code>name</code>, then <code>zcol</code> will be set up in the
return value, e.g. for use in colorizing points.  Another method
for finding colors for data points is to use the <code>colfunction()</code>
function in the return value.</p></li>
</ul></div>
    <div class="section level2">
    <h2 id="sample-of-usage">Sample of Usage<a class="anchor" aria-label="anchor" href="#sample-of-usage"></a></h2>


<div class="sourceCode"><pre><code><span></span>
<span><span class="co"># Example 2. topographic image with a standard color scheme</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/graphics/par.html" class="external-link">par</a></span><span class="op">(</span>mfrow<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="fl">1</span>,<span class="fl">1</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/utils/data.html" class="external-link">data</a></span><span class="op">(</span><span class="va">topoWorld</span><span class="op">)</span></span>
<span><span class="va">cm</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/colormap.html">colormap</a></span><span class="op">(</span>name<span class="op">=</span><span class="st">"gmt_globe"</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/imagep.html">imagep</a></span><span class="op">(</span><span class="va">topoWorld</span>, breaks<span class="op">=</span><span class="va">cm</span><span class="op">$</span><span class="va">breaks</span>, col<span class="op">=</span><span class="va">cm</span><span class="op">$</span><span class="va">col</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Example 3. topographic image with modified colors,</span></span>
<span><span class="co"># black for depths below 4km.</span></span>
<span><span class="va">cm</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/colormap.html">colormap</a></span><span class="op">(</span>name<span class="op">=</span><span class="st">"gmt_globe"</span><span class="op">)</span></span>
<span><span class="va">deep</span> <span class="op">&lt;-</span> <span class="va">cm</span><span class="op">$</span><span class="va">x0</span> <span class="op">&lt;</span> <span class="op">-</span><span class="fl">4000</span></span>
<span><span class="va">cm</span><span class="op">$</span><span class="va">col0</span><span class="op">[</span><span class="va">deep</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="st">"black"</span></span>
<span><span class="va">cm</span><span class="op">$</span><span class="va">col1</span><span class="op">[</span><span class="va">deep</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="st">"black"</span></span>
<span><span class="va">cm</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/colormap.html">colormap</a></span><span class="op">(</span>x0<span class="op">=</span><span class="va">cm</span><span class="op">$</span><span class="va">x0</span>, x1<span class="op">=</span><span class="va">cm</span><span class="op">$</span><span class="va">x1</span>, col0<span class="op">=</span><span class="va">cm</span><span class="op">$</span><span class="va">col0</span>, col1<span class="op">=</span><span class="va">cm</span><span class="op">$</span><span class="va">col1</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/imagep.html">imagep</a></span><span class="op">(</span><span class="va">topoWorld</span>, breaks<span class="op">=</span><span class="va">cm</span><span class="op">$</span><span class="va">breaks</span>, col<span class="op">=</span><span class="va">cm</span><span class="op">$</span><span class="va">col</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Example 4. image of world topography with water colorized</span></span>
<span><span class="co"># smoothly from violet at 8km depth to blue</span></span>
<span><span class="co"># at 4km depth, then blending in 0.5km increments</span></span>
<span><span class="co"># to white at the coast, with tan for land.</span></span>
<span><span class="va">cm</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/colormap.html">colormap</a></span><span class="op">(</span>x0<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="op">-</span><span class="fl">8000</span>, <span class="op">-</span><span class="fl">4000</span>,   <span class="fl">0</span>,  <span class="fl">100</span><span class="op">)</span>,</span>
<span>     x1<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="op">-</span><span class="fl">4000</span>,     <span class="fl">0</span>, <span class="fl">100</span>, <span class="fl">5000</span><span class="op">)</span>,</span>
<span>     col0<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"violet"</span>,<span class="st">"blue"</span>,<span class="st">"white"</span>,<span class="st">"tan"</span><span class="op">)</span>,</span>
<span>     col1<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"blue"</span>,<span class="st">"white"</span>,<span class="st">"tan"</span>,<span class="st">"yellow"</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="va">lon</span> <span class="op">&lt;-</span> <span class="va">topoWorld</span><span class="op">[[</span><span class="st">"longitude"</span><span class="op">]</span><span class="op">]</span></span>
<span><span class="va">lat</span> <span class="op">&lt;-</span> <span class="va">topoWorld</span><span class="op">[[</span><span class="st">"latitude"</span><span class="op">]</span><span class="op">]</span></span>
<span><span class="va">z</span> <span class="op">&lt;-</span> <span class="va">topoWorld</span><span class="op">[[</span><span class="st">"z"</span><span class="op">]</span><span class="op">]</span></span>
<span><span class="fu"><a href="../reference/imagep.html">imagep</a></span><span class="op">(</span><span class="va">lon</span>, <span class="va">lat</span>, <span class="va">z</span>, breaks<span class="op">=</span><span class="va">cm</span><span class="op">$</span><span class="va">breaks</span>, col<span class="op">=</span><span class="va">cm</span><span class="op">$</span><span class="va">col</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/graphics/contour.html" class="external-link">contour</a></span><span class="op">(</span><span class="va">lon</span>, <span class="va">lat</span>, <span class="va">z</span>, levels<span class="op">=</span><span class="fl">0</span>, add<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Example 5. visualize GMT style color map</span></span>
<span><span class="va">cm</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/colormap.html">colormap</a></span><span class="op">(</span>name<span class="op">=</span><span class="st">"gmt_globe"</span>, debug<span class="op">=</span><span class="fl">4</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/seq.html" class="external-link">seq_along</a></span><span class="op">(</span><span class="va">cm</span><span class="op">$</span><span class="va">x0</span><span class="op">)</span>, <span class="va">cm</span><span class="op">$</span><span class="va">x0</span>, pch<span class="op">=</span><span class="fl">21</span>, bg<span class="op">=</span><span class="va">cm</span><span class="op">$</span><span class="va">col0</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/graphics/grid.html" class="external-link">grid</a></span><span class="op">(</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/graphics/points.html" class="external-link">points</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/seq.html" class="external-link">seq_along</a></span><span class="op">(</span><span class="va">cm</span><span class="op">$</span><span class="va">x1</span><span class="op">)</span>, <span class="va">cm</span><span class="op">$</span><span class="va">x1</span>, pch<span class="op">=</span><span class="fl">21</span>, bg<span class="op">=</span><span class="va">cm</span><span class="op">$</span><span class="va">col1</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Example 6. colfunction</span></span>
<span><span class="va">cm</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/colormap.html">colormap</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="fl">0</span>, <span class="fl">1</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="va">x</span> <span class="op">&lt;-</span> <span class="fl">1</span><span class="op">:</span><span class="fl">10</span></span>
<span><span class="va">y</span> <span class="op">&lt;-</span> <span class="op">(</span><span class="va">x</span> <span class="op">-</span> <span class="fl">5.5</span><span class="op">)</span><span class="op">^</span><span class="fl">2</span></span>
<span><span class="va">z</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/seq.html" class="external-link">seq</a></span><span class="op">(</span><span class="fl">0</span>, <span class="fl">1</span>, length.out<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/length.html" class="external-link">length</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/drawPalette.html">drawPalette</a></span><span class="op">(</span>colormap<span class="op">=</span><span class="va">cm</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot</a></span><span class="op">(</span><span class="va">x</span>, <span class="va">y</span>, pch<span class="op">=</span><span class="fl">21</span>, bg<span class="op">=</span><span class="va">cm</span><span class="op">$</span><span class="fu">colfunction</span><span class="op">(</span><span class="va">z</span><span class="op">)</span>, cex<span class="op">=</span><span class="fl">3</span><span class="op">)</span></span></code></pre></div>

    </div>
    <div class="section level2">
    <h2 id="references">References<a class="anchor" aria-label="anchor" href="#references"></a></h2>
    <p>The following references provide information on choosing
colour schemes, that are suitable for viewers who have
colour deficiencies.</p>
<p>Light, Adam, and Patrick J. Bartlein. "The End of the Rainbow? Color
Schemes for Improved Data Graphics." <em>Eos, Transactions American Geophysical
Union</em> 85, no. 40 (2004): 385.
DOI: 10.1029/2004EO400002</p>
<p>Stephenson, David B. "Comment on 'Color Schemes for Improved Data
Graphics', by A Light and P.J. Bartlein." <em>Eos, Transactions American
Geophysical Union</em> 86, no.  20 (2005): 196.
DOI: 10.1029/2005EO200005</p>
<p>Light, Adam, and Patrick J. Bartlein. "Reply to 'Comment on Color
Schemes for Improved Data Graphics,' by A. Light and P.J.  Bartlein'."
<em>Eos, Transactions American Geophysical Union</em> 86, no. 20 (2005): 196–196.
DOI: 10.1029/2005EO200006</p>
    </div>
    <div class="section level2">
    <h2 id="see-also">See also<a class="anchor" aria-label="anchor" href="#see-also"></a></h2>
    <div class="dont-index"><p>Other things related to colors:
<code><a href="colormapGMT.html">colormapGMT</a>()</code>,
<code><a href="oceColors9B.html">oceColors9B</a>()</code>,
<code><a href="oceColorsCDOM.html">oceColorsCDOM</a>()</code>,
<code><a href="oceColorsChlorophyll.html">oceColorsChlorophyll</a>()</code>,
<code><a href="oceColorsClosure.html">oceColorsClosure</a>()</code>,
<code><a href="oceColorsDensity.html">oceColorsDensity</a>()</code>,
<code><a href="oceColorsFreesurface.html">oceColorsFreesurface</a>()</code>,
<code><a href="oceColorsGebco.html">oceColorsGebco</a>()</code>,
<code><a href="oceColorsJet.html">oceColorsJet</a>()</code>,
<code><a href="oceColorsOxygen.html">oceColorsOxygen</a>()</code>,
<code><a href="oceColorsPAR.html">oceColorsPAR</a>()</code>,
<code><a href="oceColorsPalette.html">oceColorsPalette</a>()</code>,
<code><a href="oceColorsPhase.html">oceColorsPhase</a>()</code>,
<code><a href="oceColorsSalinity.html">oceColorsSalinity</a>()</code>,
<code><a href="oceColorsTemperature.html">oceColorsTemperature</a>()</code>,
<code><a href="oceColorsTurbidity.html">oceColorsTurbidity</a>()</code>,
<code><a href="oceColorsTurbo.html">oceColorsTurbo</a>()</code>,
<code><a href="oceColorsTwo.html">oceColorsTwo</a>()</code>,
<code><a href="oceColorsVelocity.html">oceColorsVelocity</a>()</code>,
<code><a href="oceColorsViridis.html">oceColorsViridis</a>()</code>,
<code><a href="oceColorsVorticity.html">oceColorsVorticity</a>()</code>,
<code><a href="ocecolors.html">ocecolors</a></code></p></div>
    </div>
    <div class="section level2">
    <h2 id="author">Author<a class="anchor" aria-label="anchor" href="#author"></a></h2>
    <p>Dan Kelley</p>
    </div>

    <div class="section level2">
    <h2 id="ref-examples">Examples<a class="anchor" aria-label="anchor" href="#ref-examples"></a></h2>
    <div class="sourceCode"><pre class="sourceCode r"><code><span class="r-in"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dankelley.github.io/oce/">oce</a></span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="co"># Example 1. color scheme for points on xy plot</span></span></span>
<span class="r-in"><span><span class="va">x</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/seq.html" class="external-link">seq</a></span><span class="op">(</span><span class="fl">0</span>, <span class="fl">1</span>, length.out <span class="op">=</span> <span class="fl">40</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="va">y</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/Trig.html" class="external-link">sin</a></span><span class="op">(</span><span class="fl">2</span> <span class="op">*</span> <span class="va">pi</span> <span class="op">*</span> <span class="va">x</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/graphics/par.html" class="external-link">par</a></span><span class="op">(</span>mar <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="fl">3</span>, <span class="fl">3</span>, <span class="fl">1</span>, <span class="fl">1</span><span class="op">)</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="va">mar</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/graphics/par.html" class="external-link">par</a></span><span class="op">(</span><span class="st">"mar"</span><span class="op">)</span> <span class="co"># prevent margin creep by drawPalette()</span></span></span>
<span class="r-in"><span><span class="co"># First, default breaks</span></span></span>
<span class="r-in"><span><span class="va">c</span> <span class="op">&lt;-</span> <span class="fu">colormap</span><span class="op">(</span><span class="va">y</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="drawPalette.html">drawPalette</a></span><span class="op">(</span><span class="va">c</span><span class="op">$</span><span class="va">zlim</span>, col <span class="op">=</span> <span class="va">c</span><span class="op">$</span><span class="va">col</span>, breaks <span class="op">=</span> <span class="va">c</span><span class="op">$</span><span class="va">breaks</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot</a></span><span class="op">(</span><span class="va">x</span>, <span class="va">y</span>, bg <span class="op">=</span> <span class="va">c</span><span class="op">$</span><span class="va">zcol</span>, pch <span class="op">=</span> <span class="fl">21</span>, cex <span class="op">=</span> <span class="fl">1</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/graphics/grid.html" class="external-link">grid</a></span><span class="op">(</span><span class="op">)</span></span></span>
<span class="r-plt img"><img src="colormap-1.png" alt="" width="700" height="700"></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/graphics/par.html" class="external-link">par</a></span><span class="op">(</span>mar <span class="op">=</span> <span class="va">mar</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="co"># Second, 100 breaks, yielding a smoother palette</span></span></span>
<span class="r-in"><span><span class="va">c</span> <span class="op">&lt;-</span> <span class="fu">colormap</span><span class="op">(</span><span class="va">y</span>, breaks <span class="op">=</span> <span class="fl">100</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="drawPalette.html">drawPalette</a></span><span class="op">(</span><span class="va">c</span><span class="op">$</span><span class="va">zlim</span>, col <span class="op">=</span> <span class="va">c</span><span class="op">$</span><span class="va">col</span>, breaks <span class="op">=</span> <span class="va">c</span><span class="op">$</span><span class="va">breaks</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot</a></span><span class="op">(</span><span class="va">x</span>, <span class="va">y</span>, bg <span class="op">=</span> <span class="va">c</span><span class="op">$</span><span class="va">zcol</span>, pch <span class="op">=</span> <span class="fl">21</span>, cex <span class="op">=</span> <span class="fl">1</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/graphics/grid.html" class="external-link">grid</a></span><span class="op">(</span><span class="op">)</span></span></span>
<span class="r-plt img"><img src="colormap-2.png" alt="" width="700" height="700"></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/graphics/par.html" class="external-link">par</a></span><span class="op">(</span>mar <span class="op">=</span> <span class="va">mar</span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
</code></pre></div>
    </div>
  </main><aside class="col-md-3"><nav id="toc" aria-label="Table of contents"><h2>On this page</h2>
    </nav></aside></div>


    <footer><div class="pkgdown-footer-left">
  <p>Developed by Dan Kelley, Clark Richards.</p>
</div>

<div class="pkgdown-footer-right">
  <p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.1.0.9000.</p>
</div>

    </footer></div>





  </body></html>

