tmap More maps of the Highlands?
Yep, same as last time, but no need to install dev versions of anything, we can get awesome maps courtesy of the tmap package.
Get the shapefile from the last post
<span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">tmap</span><span class="p">)</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">tmaptools</span><span class="p">)</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">viridis</span><span class="p">)</span><span class="w">
</span><span class="n">scot</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">read_shape</span><span class="p">(</span><span class="s2">"SG_SIMD_2016.shp"</span><span class="p">,</span><span class="w"> </span><span class="n">as.sf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">TRUE</span><span class="p">)</span><span class="w">
</span><span class="n">highland</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="p">(</span><span class="n">scot</span><span class="p">[</span><span class="n">scot</span><span class="o">$</span><span class="n">LAName</span><span class="o">==</span><span class="s2">"Highland"</span><span class="p">,</span><span class="w"> </span><span class="p">])</span><span class="w">
</span><span class="c1">#replicate plot from previous blog post:</span><span class="w">
</span><span class="n">quint</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">tm_shape</span><span class="p">(</span><span class="n">highland</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
</span><span class="n">tm_fill</span><span class="p">(</span><span class="n">col</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Quintile"</span><span class="p">,</span><span class="w">
</span><span class="n">palette</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">viridis</span><span class="p">(</span><span class="n">n</span><span class="o">=</span><span class="m">5</span><span class="p">,</span><span class="w"> </span><span class="n">direction</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">-1</span><span class="p">,</span><span class="n">option</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"C"</span><span class="p">),</span><span class="w">
</span><span class="n">fill.title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Quintile"</span><span class="p">,</span><span class="w">
</span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"SIMD 2016 - Highland Council Area by Quintile"</span><span class="p">)</span><span class="w">
</span><span class="n">quint</span><span class="w"> </span><span class="c1"># plot</span><span class="w">
</span><span class="n">ttm</span><span class="p">()</span><span class="w"> </span><span class="c1">#switch between static and interactive - this will use interactive</span><span class="w">
</span><span class="n">quint</span><span class="w"> </span><span class="c1"># or use last_map()</span><span class="w">
</span><span class="c1"># in R Studio you will find leaflet map in your Viewer tab</span><span class="w">
</span><span class="n">ttm</span><span class="p">()</span><span class="w"> </span><span class="c1"># return to plotting</span><span class="w">
</span>
The results:
One really nice thing is that because the polygons don’...