<!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>4. Using map projections • 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="4. Using map projections">
</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="nav-item"><a class="nav-link" href="../reference/index.html">Reference</a></li>
<li class="active 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-article">




<div class="row">
  <main id="main" class="col-md-9"><div class="page-header">

      <h1>4. Using map projections</h1>
                        <h4 data-toc-skip class="author">Dan Kelley (<a href="https://orcid.org/0000-0001-7808-5911" class="external-link uri">https://orcid.org/0000-0001-7808-5911</a>)</h4>
            
            <h4 data-toc-skip class="date">2024-09-24</h4>
      
      <small class="dont-index">Source: <a href="https://github.com/dankelley/oce/blob/HEAD/vignettes/D_map_projections.Rmd" class="external-link"><code>vignettes/D_map_projections.Rmd</code></a></small>
      <div class="d-none name"><code>D_map_projections.Rmd</code></div>
    </div>

    
    
<!-- HOW TO BUILD THE VIGNETTE. -->
<!-- Look in oce.Rmd for instructions. -->
<p><strong>Abstract.</strong> An overview of the handling of map
projections in oce is presented, along with a few examples of common
projections. Readers are cautioned that oce has difficulties with some
projections, which can cause spurious horizontal lines (or poor landmass
filling) on plots.</p>
<div class="section level2">
<h2 id="introduction">Introduction<a class="anchor" aria-label="anchor" href="#introduction"></a>
</h2>
<p>Map projections provide methods for representing the
three-dimensional surface of the earth as two-dimensional plots.
Although most oceanographers are likely to be familiar with the basic
ideas of map projection, they may find it helpful to consult the wide
literature on this topic, whether to learn about the details of
individual projections and to get advice on the best choice of
projection for a particular task. Snyder (1987), Snyder (1993) and
Snyder and Voxland (1994) are all excellent sources on these topics, and
the first and last of these are available for free online.</p>
<p>Oce handles map projections by calling the <code>sf_project</code>
function of the <code>sf</code> R package, and so the notation for
representing the projection is borrowed from <code>sf</code>. This
system will be familiar to many readers, because it is used in other R
packages, and more widely in the software called PROJ, which has
interfaces in python and other programming languages (PROJ contributors,
2020). Since oce uses inverse projections in some of its graphical work,
only PROJ projections that have inverses are incorporated into oce.
Furthermore, some projections are omitted from oce because they have
been witnessed to cause problems on the oce developer’s computers,
including infinite loops and core dumps. See the help for the oce
function <code>mapPlot</code> for a list of the available projections,
and some advice on choosing them.</p>
<p>You must ensure that the <code>sf</code> package is installed for the
examples provided in this vignette to work. If this package is not
installed, it may be installed with</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/utils/install.packages.html" class="external-link">install.packages</a></span><span class="op">(</span><span class="st">"sf"</span><span class="op">)</span></span></code></pre></div>
<p>There are far too many projections to illustrate here. See
<code>https://dankelley.github.io/r/2015/04/03/oce-proj.html</code> for
a blog item that provides examples of the available projections. Note
that some have a problem with spurious horizontal lines. This can result
from coastline segments that cross the edge of the plotting area, and
getting rid of this is tricky enough to be the heart of the
longest-lived bug in the <code>oce</code> issue list, i.e.
<code>https://github.com/dankelley/oce/issues/388</code>. In some
instances the function <code><a href="../reference/coastlineCut.html">coastlineCut()</a></code> can help, but it is
provisional and subject to change.</p>
</div>
<div class="section level2">
<h2 id="avoiding-projections-for-small-regions">Avoiding projections for small regions<a class="anchor" aria-label="anchor" href="#avoiding-projections-for-small-regions"></a>
</h2>
<p>For map views that span only a few tens or hundreds of kilometers, it
may be sufficient to plot directly, in rectilinear longitude-latitude
space, but with an appropriate aspect ratio so that circular islands
will appear circular in the plot.</p>
<p>To see the need for setting the aspect ratio, consider the following
view of North America.</p>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><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="co">#&gt; Loading required package: gsw</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">coastlineWorld</span><span class="op">)</span></span>
<span><span class="va">lon</span> <span class="op">&lt;-</span> <span class="va">coastlineWorld</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">coastlineWorld</span><span class="op">[[</span><span class="st">"latitude"</span><span class="op">]</span><span class="op">]</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>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">4</span>, <span class="fl">4</span>, <span class="fl">0.5</span>, <span class="fl">0.5</span><span class="op">)</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">lon</span>, <span class="va">lat</span>,</span>
<span>    type <span class="op">=</span> <span class="st">"l"</span>,</span>
<span>    xlim <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">130</span>, <span class="op">-</span><span class="fl">50</span><span class="op">)</span>, ylim <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">40</span>, <span class="fl">50</span><span class="op">)</span></span>
<span><span class="op">)</span></span></code></pre></div>
<div class="figure">
<img src="D_map_projections_files/figure-html/unnamed-chunk-3-1.png" alt="Distorted North American view, without control of aspect ratio." width="216"><p class="caption">
Distorted North American view, without control of aspect ratio.
</p>
</div>
<p>Readers familiar with this region will notice that the coastline
shapes are distorted. The solution to this problem is to set the
<code>asp</code> argument of <code><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot()</a></code> to a value appropriate
to the general latitude of the view (45N, in this case).</p>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><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">4</span>, <span class="fl">4</span>, <span class="fl">0.5</span>, <span class="fl">0.5</span><span class="op">)</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">lon</span>, <span class="va">lat</span>,</span>
<span>    type <span class="op">=</span> <span class="st">"l"</span>,</span>
<span>    xlim <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">130</span>, <span class="op">-</span><span class="fl">50</span><span class="op">)</span>, ylim <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">40</span>, <span class="fl">50</span><span class="op">)</span>, asp <span class="op">=</span> <span class="fl">1</span> <span class="op">/</span> <span class="fu"><a href="https://rdrr.io/r/base/Trig.html" class="external-link">cos</a></span><span class="op">(</span><span class="fl">45</span> <span class="op">*</span> <span class="va">pi</span> <span class="op">/</span> <span class="fl">180</span><span class="op">)</span></span>
<span><span class="op">)</span></span></code></pre></div>
<div class="figure">
<img src="D_map_projections_files/figure-html/unnamed-chunk-4-1.png" alt="North American view, with distortion limited by choice of aspect ratio." width="216"><p class="caption">
North American view, with distortion limited by choice of aspect ratio.
</p>
</div>
<p>Although the above approach is not exactly taxing, the effort of
setting the aspect ratio and setting line-type plots can be spared by
using the generic <code><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot()</a></code> function for
<code>coastline</code> objects, as follows.</p>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><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">coastlineWorld</span>, clongitude <span class="op">=</span> <span class="op">-</span><span class="fl">90</span>, clatitude <span class="op">=</span> <span class="fl">45</span>, span <span class="op">=</span> <span class="fl">7000</span><span class="op">)</span></span></code></pre></div>
<div class="figure">
<img src="D_map_projections_files/figure-html/unnamed-chunk-5-1.png" alt="North American view, drawn with mapPlot()." width="216"><p class="caption">
North American view, drawn with mapPlot().
</p>
</div>
<p>Note that this <code>plot</code> is being transferred to the
specialized method for a <code>coastline</code> object (defined by the
<code>oce</code> package) and that this means that there are some
arguments in addition to those of the normal <code>plot</code> function.
In this example, the second and third arguments specify the central spot
of interest, and the fourth is a suggested diagonal span, in kilometres.
(The span is not always obeyed exactly, and the results also depend on
aspect ratio of the plot device.)</p>
<p>The graphs shown above share a common strength: the axes for
longitude and latitude are orthogonal, and the scale along each axis is
linear. This makes it easy for readers to identify the location of
features of the diagrams. However, using linear axes on large-scale
views leads to distortions of coastline shapes and relative feature
sizes, and motivates the use of map projections. (Readers who question
the previous sentence are again encouraged to consult some of the
references in the bibliography.)</p>
</div>
<div class="section level2">
<h2 id="choosing-a-map-projection">Choosing a map projection<a class="anchor" aria-label="anchor" href="#choosing-a-map-projection"></a>
</h2>
<div class="section level3">
<h3 id="world-views">World views<a class="anchor" aria-label="anchor" href="#world-views"></a>
</h3>
<p>It makes sense to switch to a coarser coastline file for the examples
to follow, because plotting a detailed coastline in a world view leads
to a scribbling effect that obscures the large-scale coastline
shapes.</p>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><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">coastlineWorld</span><span class="op">)</span></span></code></pre></div>
<p>The function used to produce maps with projections is
<code>mapPlot</code>, and with default arguments it produces</p>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><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">1.5</span>, <span class="fl">1.5</span>, <span class="fl">0.5</span>, <span class="fl">0.5</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/mapPlot.html">mapPlot</a></span><span class="op">(</span><span class="va">coastlineWorld</span>, col <span class="op">=</span> <span class="st">"lightgray"</span><span class="op">)</span></span></code></pre></div>
<div class="figure">
<img src="D_map_projections_files/figure-html/unnamed-chunk-7-1.png" alt="World coastline with default (Mollweide) projection." width="360"><p class="caption">
World coastline with default (Mollweide) projection.
</p>
</div>
<p>Note that the land is coloured in this example, but that sometimes
doing that will yield odd-looking plots, because of a bug in how some
projections are handled in oce.</p>
<p>This default plot uses the Mollweide projection (see any of the
Snyder references in the bibliography), which is set by the default
value <code>"+proj=moll"</code> for <code>mapPlot</code>. Another
popular world view is the Robinson projection, which has been used by
Rand McNally, the National Geographic Society, and other groups.</p>
<p><strong>Exercise 1.</strong> Plot the world with a Robinson
projection, using gray shading for land.</p>
<p><strong>Exercise 2.</strong> Plot an image of world topography with
the Mollweide projection.</p>
</div>
<div class="section level3">
<h3 id="polar-views">Polar views<a class="anchor" aria-label="anchor" href="#polar-views"></a>
</h3>
<p>In both these views (and in most world-spanning projections) there is
substantial distortion at high latitudes. The Stereographic projection
offers a solution to this problem, e.g. in the following (which employs
a trick on the latitude limit, specifying an image point on the other
side of the planet, with the pole in between).</p>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><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">1.5</span>, <span class="fl">1.5</span>, <span class="fl">0.5</span>, <span class="fl">0.5</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/mapPlot.html">mapPlot</a></span><span class="op">(</span><span class="va">coastlineWorld</span>,</span>
<span>    longitudelim <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">180</span>, <span class="fl">180</span><span class="op">)</span>, latitudelim <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">60</span>, <span class="fl">90</span><span class="op">)</span>,</span>
<span>    projection <span class="op">=</span> <span class="st">"+proj=stere +lat_0=90 +lat_ts=90"</span>, col <span class="op">=</span> <span class="st">"gray"</span></span>
<span><span class="op">)</span></span></code></pre></div>
<div class="figure">
<img src="D_map_projections_files/figure-html/unnamed-chunk-8-1.png" alt="Polar view with stereographic projection." width="216"><p class="caption">
Polar view with stereographic projection.
</p>
</div>
<p>Here, the region of interest is defined with
<code>longitudelim</code> and <code>latitudelim</code>, instead of with
<code>clongitude</code>, <code>clatitude</code> and <code>span</code>.
Note that the latitude limit is set to extend past the pole, which is a
way of making the plot include the pole. See the table in the
documentation for <code>mapPlot</code> for a listing of arguments, and
for citations to external resources that explain what they mean.</p>
<p><strong>Exercise 3.</strong> Draw a view of Antarctica and the
Southern Ocean.</p>
</div>
<div class="section level3">
<h3 id="mid-latitude-views">Mid-latitude views<a class="anchor" aria-label="anchor" href="#mid-latitude-views"></a>
</h3>
<p>The Lambert Conformal view is often used in maps that span wide
longitudinal ranges, e.g. a map of Canada may be produced as
follows.</p>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R"><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">1.5</span>, <span class="fl">1.5</span>, <span class="fl">0.5</span>, <span class="fl">0.5</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/mapPlot.html">mapPlot</a></span><span class="op">(</span><span class="va">coastlineWorld</span>,</span>
<span>    longitudelim <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">130</span>, <span class="op">-</span><span class="fl">55</span><span class="op">)</span>, latitudelim <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">45</span>, <span class="fl">70</span><span class="op">)</span>,</span>
<span>    projection <span class="op">=</span> <span class="st">"+proj=lcc +lat_1=50 +lat_2=65 +lon_0=-100"</span>, col <span class="op">=</span> <span class="st">"gray"</span></span>
<span><span class="op">)</span></span></code></pre></div>
<div class="figure">
<img src="D_map_projections_files/figure-html/unnamed-chunk-9-1.png" alt="Canada in Lambert Conformal projection." width="216"><p class="caption">
Canada in Lambert Conformal projection.
</p>
</div>
<p>Here, <code>lat_1</code> and <code>lat_2</code>, the latitudes where
the projection cone intersects the earth, are set to span southern
Canada and northern USA, and <code>lon_0</code>, the meridian that will
be vertical on the plot, is chosen to lie near the middle of the
continent.</p>
<p><strong>Exercise 4.</strong> Plot the eastern North Atlantic using
the Universal Transverse Mercator projection.</p>
<p><strong>Exercise 5.</strong> Plot the eastern North Atlantic using
the Albers Equal-Area Conic projection.</p>
</div>
</div>
<div class="section level2">
<h2 id="adding-to-map-plots">Adding to map plots<a class="anchor" aria-label="anchor" href="#adding-to-map-plots"></a>
</h2>
<p>Several functions are provided by oce to draw additional features on
maps. These include <code>mapText</code> for adding text,
<code>mapPoints</code> for adding points, <code>mapLines</code> for
adding lines, <code>mapContour</code> for adding contours, and
<code>mapImage</code> for adding images. Each of these requires a map to
have been drawn first with <code>mapPlot</code>. The interfaces ought to
be similar enough to base-R functions that readers can decide how to
accomplish common tasks.</p>
<p><strong>Exercise 6.</strong> Plot the world with the Goode
projection, superimposing sea surface temperature as contours.</p>
</div>
<div class="section level2">
<h2 id="solutions-to-exercises">Solutions to exercises<a class="anchor" aria-label="anchor" href="#solutions-to-exercises"></a>
</h2>
<p><strong>Exercise 1.</strong> Plot the world with a Robinson
projection, using gray shading for land.</p>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R"><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/rep.html" class="external-link">rep</a></span><span class="op">(</span><span class="fl">0.5</span>, <span class="fl">4</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/mapPlot.html">mapPlot</a></span><span class="op">(</span><span class="va">coastlineWorld</span>, col <span class="op">=</span> <span class="st">"lightgray"</span>, projection <span class="op">=</span> <span class="st">"+proj=robin"</span><span class="op">)</span></span></code></pre></div>
<div class="figure">
<img src="D_map_projections_files/figure-html/unnamed-chunk-10-1.png" alt="World coastline with Robinson projection (exercise 1)." width="360"><p class="caption">
World coastline with Robinson projection (exercise 1).
</p>
</div>
<p><strong>Exercise 2.</strong> Plot an image of world topography with
the Mollweide projection.</p>
<p>Note that some adjustment of the margins is required to fit the
colorbar.</p>
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r">
<code class="sourceCode R"><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">1.5</span>, <span class="fl">1</span>, <span class="fl">1.5</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">topo</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/decimate.html">decimate</a></span><span class="op">(</span><span class="va">topoWorld</span>, <span class="fl">2</span><span class="op">)</span> <span class="co"># coarsen grid: 4X faster plot</span></span>
<span><span class="va">lon</span> <span class="op">&lt;-</span> <span class="va">topo</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">topo</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">topo</span><span class="op">[[</span><span class="st">"z"</span><span class="op">]</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/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="../reference/mapPlot.html">mapPlot</a></span><span class="op">(</span><span class="va">coastlineWorld</span>, projection <span class="op">=</span> <span class="st">"+proj=moll"</span>, grid <span class="op">=</span> <span class="cn">FALSE</span>, col <span class="op">=</span> <span class="st">"lightgray"</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/mapImage.html">mapImage</a></span><span class="op">(</span><span class="va">lon</span>, <span class="va">lat</span>, <span class="va">z</span>, colormap <span class="op">=</span> <span class="va">cm</span><span class="op">)</span></span></code></pre></div>
<div class="figure">
<img src="D_map_projections_files/figure-html/unnamed-chunk-11-1.png" alt="World topography with Mollweide projection (exercise 2)." width="360"><p class="caption">
World topography with Mollweide projection (exercise 2).
</p>
</div>
<p><strong>Exercise 3.</strong> Draw a view of Antarctica and the
Southern Ocean.</p>
<div class="sourceCode" id="cb11"><pre class="downlit sourceCode r">
<code class="sourceCode R"><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">1.5</span>, <span class="fl">1.5</span>, <span class="fl">0.5</span>, <span class="fl">0.5</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/mapPlot.html">mapPlot</a></span><span class="op">(</span><span class="va">coastlineWorld</span>,</span>
<span>    longitudelim <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">180</span>, <span class="fl">180</span><span class="op">)</span>, latitudelim <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">130</span>, <span class="op">-</span><span class="fl">50</span><span class="op">)</span>,</span>
<span>    projection <span class="op">=</span> <span class="st">"+proj=stere +lat_0=-90"</span>, col <span class="op">=</span> <span class="st">"gray"</span>, grid <span class="op">=</span> <span class="fl">15</span></span>
<span><span class="op">)</span></span></code></pre></div>
<div class="figure">
<img src="D_map_projections_files/figure-html/unnamed-chunk-12-1.png" alt="Antarctica (exercise 3)." width="216"><p class="caption">
Antarctica (exercise 3).
</p>
</div>
<p><strong>Exercise 4.</strong> Plot the eastern North Atlantic using
the Universal Transverse Mercator projection.</p>
<p>Zone 20 includes Nova Scotia, which is also a good place to centre
the view.</p>
<div class="sourceCode" id="cb12"><pre class="downlit sourceCode r">
<code class="sourceCode R"><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">1.5</span>, <span class="fl">1.5</span>, <span class="fl">0.5</span>, <span class="fl">0.5</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/mapPlot.html">mapPlot</a></span><span class="op">(</span><span class="va">coastlineWorld</span>,</span>
<span>    col <span class="op">=</span> <span class="st">"lightgray"</span>,</span>
<span>    projection <span class="op">=</span> <span class="st">"+proj=utm +zone=20"</span>,</span>
<span>    longitudelim <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">85</span>, <span class="op">-</span><span class="fl">45</span><span class="op">)</span>, latitudelim <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">40</span>, <span class="fl">60</span><span class="op">)</span></span>
<span><span class="op">)</span></span></code></pre></div>
<div class="figure">
<img src="D_map_projections_files/figure-html/unnamed-chunk-13-1.png" alt="Eastern Canadian waters shown in Universal Transverse Mercator projection." width="216"><p class="caption">
Eastern Canadian waters shown in Universal Transverse Mercator
projection.
</p>
</div>
<p><strong>Exercise 5.</strong> Plot the eastern North Atlantic using an
Albers Equal-Area Conic projection.</p>
<p>In the solution given below, note how the <code>lon_0</code> argument
is set to be at the central value of <code>longitudelim</code>. This
makes the
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msup><mn>60</mn><mo>∘</mo></msup><annotation encoding="application/x-tex">60^\circ</annotation></semantics></math>W
line be vertical on the plot. The settings for <code>lat_1</code> and
<code>lat_2</code> are the locations at which the cone intersects the
earth, so distortion is minimized at those latitudes. Note how the lines
of constant longitude are changed, compared with those in the Mercator
view. It may be informative to compare the relative ratio of the area of
Nova Scotia (at
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msup><mn>45</mn><mo>∘</mo></msup><annotation encoding="application/x-tex">45^\circ</annotation></semantics></math>N)
and Ungava Bay (at
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msup><mn>60</mn><mo>∘</mo></msup><annotation encoding="application/x-tex">60^\circ</annotation></semantics></math>N)
in this Albers Equal-Area projection, and the Mercator projection shown
in the previous diagram.</p>
<div class="sourceCode" id="cb13"><pre class="downlit sourceCode r">
<code class="sourceCode R"><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">1.5</span>, <span class="fl">1.5</span>, <span class="fl">0.5</span>, <span class="fl">0.5</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/mapPlot.html">mapPlot</a></span><span class="op">(</span><span class="va">coastlineWorld</span>,</span>
<span>    col <span class="op">=</span> <span class="st">"lightgray"</span>,</span>
<span>    projection <span class="op">=</span> <span class="st">"+proj=aea +lat_1=45 +lat_2=55 +lon_0=-65"</span>,</span>
<span>    longitudelim <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">85</span>, <span class="op">-</span><span class="fl">45</span><span class="op">)</span>, latitudelim <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">40</span>, <span class="fl">60</span><span class="op">)</span></span>
<span><span class="op">)</span></span></code></pre></div>
<div class="figure">
<img src="D_map_projections_files/figure-html/unnamed-chunk-14-1.png" alt="Eastern North Atlantic with Albers equal-area projection (exercise 5)." width="216"><p class="caption">
Eastern North Atlantic with Albers equal-area projection (exercise 5).
</p>
</div>
<p><strong>Exercise 6.</strong> Plot the world with the Goode
projection, superimposing sea surface temperature as contours.</p>
<p>Note that the temperature is provided by the <code>ocedata</code>
package.</p>
<div class="sourceCode" id="cb14"><pre class="downlit sourceCode r">
<code class="sourceCode R"><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/rep.html" class="external-link">rep</a></span><span class="op">(</span><span class="fl">0.5</span>, <span class="fl">4</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/mapPlot.html">mapPlot</a></span><span class="op">(</span><span class="va">coastlineWorld</span>, projection <span class="op">=</span> <span class="st">"+proj=goode"</span>, col <span class="op">=</span> <span class="st">"lightgray"</span><span class="op">)</span></span>
<span><span class="kw">if</span> <span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/ns-load.html" class="external-link">requireNamespace</a></span><span class="op">(</span><span class="st">"ocedata"</span>, quietly <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</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">levitus</span>, package <span class="op">=</span> <span class="st">"ocedata"</span><span class="op">)</span></span>
<span>    <span class="fu"><a href="../reference/mapContour.html">mapContour</a></span><span class="op">(</span><span class="va">levitus</span><span class="op">[[</span><span class="st">"longitude"</span><span class="op">]</span><span class="op">]</span>, <span class="va">levitus</span><span class="op">[[</span><span class="st">"latitude"</span><span class="op">]</span><span class="op">]</span>, <span class="va">levitus</span><span class="op">[[</span><span class="st">"SST"</span><span class="op">]</span><span class="op">]</span><span class="op">)</span></span>
<span><span class="op">}</span></span></code></pre></div>
<div class="figure">
<img src="D_map_projections_files/figure-html/unnamed-chunk-15-1.png" alt="SST contours with the Goode projection (exercise 6)" width="360"><p class="caption">
SST contours with the Goode projection (exercise 6)
</p>
</div>
</div>
<div class="section level2">
<h2 id="references">References<a class="anchor" aria-label="anchor" href="#references"></a>
</h2>
<p>PROJ contributors. “PROJ Coordinate Transformation Software Library.”
Open Source Geospatial Foundation, 2020.
<code>https://proj.org/</code></p>
<p>Snyder, John P. “Map Projections-a Working Manual.” Washington: U.S.
Geological survey professional paper 1395, 1987.</p>
<p>Snyder, John Parr. “Flattening the Earth: Two Thousand Years of Map
Projections.” Chicago, IL: University of Chicago Press, 1993.
<code>https://press.uchicago.edu/ucp/books/book/chicago/F/bo3632853.html</code></p>
<p>Snyder, John P., and Philip M. Voxland. “An Album of Map
Projections.” U. S. Geological Survey Professional Paper. Washington,
DC, USA: U. S. Department of the Interior: U. S. Geological Survey,
1994. <code>https://pubs.er.usgs.gov/publication/pp1453</code></p>
</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>
