<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Useful R Stuff</title>
<link>https://abraver.github.io/usefulRstuff/index.html</link>
<atom:link href="https://abraver.github.io/usefulRstuff/index.xml" rel="self" type="application/rss+xml"/>
<description></description>
<generator>quarto-1.3.361</generator>
<lastBuildDate>Fri, 17 May 2024 05:00:00 GMT</lastBuildDate>
<item>
  <title>Tables for Word in flextable
</title>
  <dc:creator>Aaron Braver</dc:creator>
  <link>https://abraver.github.io/usefulRstuff/posts/tables_for_word_flextable/index.html</link>
  <description><![CDATA[ <script src="../../jquery-3.7.0.min.js"></script><script src="../../fold.js"></script><script src="../../move_session_info.js"></script><!-- begin content --><div class="cell" data-hash="index_cache/html/setup_2ba6a52b786234c62804130cb975095e">
<details><summary>Setup</summary><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://tidyverse.tidyverse.org">tidyverse</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://gt.rstudio.com">gt</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://ardata-fr.github.io/flextable-book/">flextable</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</details>
</div>
<p>On those occasions where I have a coauthor working in Word rather than LaTeX, it’s sometimes useful to be able to output nicely formatted, editable tables directly from R. I like the tables from <code>gt</code>, but they don’t render certain style and formatting options correctly in Word or RTF output (see <a href="https://github.com/rstudio/gt/issues/1098">this issue</a>).<sup>1</sup></p>
<p>So, in this post I’ll show some tables made with <code>flextable</code>, which has better Word support.</p>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
If you don’t need editability or formatting…
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<p>There are a few options if you don’t need editable output, or output with fancy formatting.</p>
<section id="editable-but-not-pretty" class="level3"><h3 class="anchored" data-anchor-id="editable-but-not-pretty">Editable but not pretty</h3>
<p>The option I use the most, for sending tables to Word or Excel is <code>clipr::write_clip(df)</code>, which writes <code>df</code> to the clipboard for easy pasting. There’s also <code><a href="http://matthewlincoln.net/clipr/reference/write_last_clip.html">clipr::write_last_clip()</a></code> which can be called right after you create a dataframe and copies it to the clipboard.</p>
</section><section id="pretty-but-not-editable" class="level3"><h3 class="anchored" data-anchor-id="pretty-but-not-editable">Pretty but not editable</h3>
<p>Another option is to save a <code>gt</code> as an image or a pdf:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-2_616f4fdad053735409b90803b1568825">
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/utils/head.html">head</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">mtcars</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://gt.rstudio.com/reference/gt.html">gt</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://gt.rstudio.com/reference/gtsave.html">gtsave</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"table.png"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># or table.pdf, or whatever</span></span></code></pre></div>
</div>
<p>(Saving as an image requires that <code>webshot2</code> be installed.)</p>
</section>
</div>
</div>
</div>
<section id="flextable" class="level2"><h2 class="anchored" data-anchor-id="flextable"><code>flextable</code></h2>
<p>Piping a dataframe to <code><a href="https://davidgohel.github.io/flextable/reference/flextable.html">flextable()</a></code> produces a pretty decent initial result:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-3_415929d359642b80ec85801c96ca9084">
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">palmerpenguins</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://allisonhorst.github.io/palmerpenguins/reference/penguins.html">penguins</a></span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">species</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">island</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bill_length_mm</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sex</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">year</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/slice.html">slice_sample</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># select 5 random rows</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/flextable.html">flextable</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">

<div class="tabwid">
<style>.cl-7d2a07a8{}.cl-7d26b314{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-7d28078c{margin:0;text-align:left;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-7d280796{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-7d2813a8{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-7d2813a9{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-7d2813b2{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-7d2813b3{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-7d2813b4{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-7d2813bc{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style>
<table data-quarto-disable-processing="true" class="cl-7d2a07a8">
<thead><tr style="overflow-wrap:break-word;">
<th class="cl-7d2813a8"><p class="cl-7d28078c"><span class="cl-7d26b314">species</span></p></th>
<th class="cl-7d2813a8"><p class="cl-7d28078c"><span class="cl-7d26b314">island</span></p></th>
<th class="cl-7d2813a9"><p class="cl-7d280796"><span class="cl-7d26b314">bill_length_mm</span></p></th>
<th class="cl-7d2813a8"><p class="cl-7d28078c"><span class="cl-7d26b314">sex</span></p></th>
<th class="cl-7d2813a9"><p class="cl-7d280796"><span class="cl-7d26b314">year</span></p></th>
</tr></thead>
<tbody>
<tr style="overflow-wrap:break-word;">
<td class="cl-7d2813b2"><p class="cl-7d28078c"><span class="cl-7d26b314">Gentoo</span></p></td>
<td class="cl-7d2813b2"><p class="cl-7d28078c"><span class="cl-7d26b314">Biscoe</span></p></td>
<td class="cl-7d2813b3"><p class="cl-7d280796"><span class="cl-7d26b314">49.1</span></p></td>
<td class="cl-7d2813b2"><p class="cl-7d28078c"><span class="cl-7d26b314">male</span></p></td>
<td class="cl-7d2813b3"><p class="cl-7d280796"><span class="cl-7d26b314">2,009</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-7d2813b2"><p class="cl-7d28078c"><span class="cl-7d26b314">Adelie</span></p></td>
<td class="cl-7d2813b2"><p class="cl-7d28078c"><span class="cl-7d26b314">Dream</span></p></td>
<td class="cl-7d2813b3"><p class="cl-7d280796"><span class="cl-7d26b314">39.5</span></p></td>
<td class="cl-7d2813b2"><p class="cl-7d28078c"><span class="cl-7d26b314">female</span></p></td>
<td class="cl-7d2813b3"><p class="cl-7d280796"><span class="cl-7d26b314">2,007</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-7d2813b2"><p class="cl-7d28078c"><span class="cl-7d26b314">Chinstrap</span></p></td>
<td class="cl-7d2813b2"><p class="cl-7d28078c"><span class="cl-7d26b314">Dream</span></p></td>
<td class="cl-7d2813b3"><p class="cl-7d280796"><span class="cl-7d26b314">46.8</span></p></td>
<td class="cl-7d2813b2"><p class="cl-7d28078c"><span class="cl-7d26b314">female</span></p></td>
<td class="cl-7d2813b3"><p class="cl-7d280796"><span class="cl-7d26b314">2,009</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-7d2813b2"><p class="cl-7d28078c"><span class="cl-7d26b314">Gentoo</span></p></td>
<td class="cl-7d2813b2"><p class="cl-7d28078c"><span class="cl-7d26b314">Biscoe</span></p></td>
<td class="cl-7d2813b3"><p class="cl-7d280796"><span class="cl-7d26b314">46.8</span></p></td>
<td class="cl-7d2813b2"><p class="cl-7d28078c"><span class="cl-7d26b314">female</span></p></td>
<td class="cl-7d2813b3"><p class="cl-7d280796"><span class="cl-7d26b314">2,009</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-7d2813b4"><p class="cl-7d28078c"><span class="cl-7d26b314">Adelie</span></p></td>
<td class="cl-7d2813b4"><p class="cl-7d28078c"><span class="cl-7d26b314">Biscoe</span></p></td>
<td class="cl-7d2813bc"><p class="cl-7d280796"><span class="cl-7d26b314">40.6</span></p></td>
<td class="cl-7d2813b4"><p class="cl-7d28078c"><span class="cl-7d26b314">male</span></p></td>
<td class="cl-7d2813bc"><p class="cl-7d280796"><span class="cl-7d26b314">2,008</span></p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>While we’re at it, let’s change the formatting of that <code>year</code> column. <code>colformat_num</code> targets numeric columns; the <code>j</code> argument narrows it down to specific columns if needed. <code>colformat_num</code> passes <code>...</code> to <code><a href="https://rdrr.io/r/base/format.html">format()</a></code>, so you can use most <code><a href="https://rdrr.io/r/base/format.html">format()</a></code> arguments—here I’ve just used <code>big.mark</code>.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-4_2c7dcb743a24581be07e10080f838c30">
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">palmerpenguins</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://allisonhorst.github.io/palmerpenguins/reference/penguins.html">penguins</a></span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">species</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">island</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bill_length_mm</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sex</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">year</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/slice.html">slice_sample</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/flextable.html">flextable</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/colformat_num.html">colformat_num</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>, big.mark <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_1</span></span></code></pre></div>
<div class="cell-output-display">

<div class="tabwid">
<style>.cl-16cc0cec{}.cl-16c8aeee{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-16ca11ee{margin:0;text-align:left;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-16ca11f8{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-16ca1bbc{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-16ca1bc6{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-16ca1bc7{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-16ca1bc8{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-16ca1bc9{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-16ca1bd0{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style>
<table data-quarto-disable-processing="true" class="cl-16cc0cec">
<thead><tr style="overflow-wrap:break-word;">
<th class="cl-16ca1bbc"><p class="cl-16ca11ee"><span class="cl-16c8aeee">species</span></p></th>
<th class="cl-16ca1bbc"><p class="cl-16ca11ee"><span class="cl-16c8aeee">island</span></p></th>
<th class="cl-16ca1bc6"><p class="cl-16ca11f8"><span class="cl-16c8aeee">bill_length_mm</span></p></th>
<th class="cl-16ca1bbc"><p class="cl-16ca11ee"><span class="cl-16c8aeee">sex</span></p></th>
<th class="cl-16ca1bc6"><p class="cl-16ca11f8"><span class="cl-16c8aeee">year</span></p></th>
</tr></thead>
<tbody>
<tr style="overflow-wrap:break-word;">
<td class="cl-16ca1bc7"><p class="cl-16ca11ee"><span class="cl-16c8aeee">Chinstrap</span></p></td>
<td class="cl-16ca1bc7"><p class="cl-16ca11ee"><span class="cl-16c8aeee">Dream</span></p></td>
<td class="cl-16ca1bc8"><p class="cl-16ca11f8"><span class="cl-16c8aeee">49.0</span></p></td>
<td class="cl-16ca1bc7"><p class="cl-16ca11ee"><span class="cl-16c8aeee">male</span></p></td>
<td class="cl-16ca1bc8"><p class="cl-16ca11f8"><span class="cl-16c8aeee">2008</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-16ca1bc7"><p class="cl-16ca11ee"><span class="cl-16c8aeee">Gentoo</span></p></td>
<td class="cl-16ca1bc7"><p class="cl-16ca11ee"><span class="cl-16c8aeee">Biscoe</span></p></td>
<td class="cl-16ca1bc8"><p class="cl-16ca11f8"><span class="cl-16c8aeee">52.2</span></p></td>
<td class="cl-16ca1bc7"><p class="cl-16ca11ee"><span class="cl-16c8aeee">male</span></p></td>
<td class="cl-16ca1bc8"><p class="cl-16ca11f8"><span class="cl-16c8aeee">2009</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-16ca1bc7"><p class="cl-16ca11ee"><span class="cl-16c8aeee">Adelie</span></p></td>
<td class="cl-16ca1bc7"><p class="cl-16ca11ee"><span class="cl-16c8aeee">Dream</span></p></td>
<td class="cl-16ca1bc8"><p class="cl-16ca11f8"><span class="cl-16c8aeee">42.2</span></p></td>
<td class="cl-16ca1bc7"><p class="cl-16ca11ee"><span class="cl-16c8aeee">female</span></p></td>
<td class="cl-16ca1bc8"><p class="cl-16ca11f8"><span class="cl-16c8aeee">2007</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-16ca1bc7"><p class="cl-16ca11ee"><span class="cl-16c8aeee">Gentoo</span></p></td>
<td class="cl-16ca1bc7"><p class="cl-16ca11ee"><span class="cl-16c8aeee">Biscoe</span></p></td>
<td class="cl-16ca1bc8"><p class="cl-16ca11f8"><span class="cl-16c8aeee">50.8</span></p></td>
<td class="cl-16ca1bc7"><p class="cl-16ca11ee"><span class="cl-16c8aeee">male</span></p></td>
<td class="cl-16ca1bc8"><p class="cl-16ca11f8"><span class="cl-16c8aeee">2009</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-16ca1bc9"><p class="cl-16ca11ee"><span class="cl-16c8aeee">Adelie</span></p></td>
<td class="cl-16ca1bc9"><p class="cl-16ca11ee"><span class="cl-16c8aeee">Dream</span></p></td>
<td class="cl-16ca1bd0"><p class="cl-16ca11f8"><span class="cl-16c8aeee">42.3</span></p></td>
<td class="cl-16ca1bc9"><p class="cl-16ca11ee"><span class="cl-16c8aeee">male</span></p></td>
<td class="cl-16ca1bd0"><p class="cl-16ca11f8"><span class="cl-16c8aeee">2007</span></p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>You can also format columns with a function using <code><a href="https://davidgohel.github.io/flextable/reference/set_formatter.html">set_formatter()</a></code>. We could, for example, make the <code>species</code> column lowercase and the <code>island</code> column uppercase:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-5_f6d0c791c17d91afb9c6c777ea523d28">
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/set_formatter.html">set_formatter</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>species <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">tolower</span>, island <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">toupper</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">

<div class="tabwid">
<style>.cl-72532cc2{}.cl-724f5ca0{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-72510a8c{margin:0;text-align:left;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-72510a8d{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-72511496{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-72511497{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-72511498{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-725114a0{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-725114a1{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-725114aa{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style>
<table data-quarto-disable-processing="true" class="cl-72532cc2">
<thead><tr style="overflow-wrap:break-word;">
<th class="cl-72511496"><p class="cl-72510a8c"><span class="cl-724f5ca0">species</span></p></th>
<th class="cl-72511496"><p class="cl-72510a8c"><span class="cl-724f5ca0">island</span></p></th>
<th class="cl-72511497"><p class="cl-72510a8d"><span class="cl-724f5ca0">bill_length_mm</span></p></th>
<th class="cl-72511496"><p class="cl-72510a8c"><span class="cl-724f5ca0">sex</span></p></th>
<th class="cl-72511497"><p class="cl-72510a8d"><span class="cl-724f5ca0">year</span></p></th>
</tr></thead>
<tbody>
<tr style="overflow-wrap:break-word;">
<td class="cl-72511498"><p class="cl-72510a8c"><span class="cl-724f5ca0">chinstrap</span></p></td>
<td class="cl-72511498"><p class="cl-72510a8c"><span class="cl-724f5ca0">DREAM</span></p></td>
<td class="cl-725114a0"><p class="cl-72510a8d"><span class="cl-724f5ca0">49.0</span></p></td>
<td class="cl-72511498"><p class="cl-72510a8c"><span class="cl-724f5ca0">male</span></p></td>
<td class="cl-725114a0"><p class="cl-72510a8d"><span class="cl-724f5ca0">2008</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-72511498"><p class="cl-72510a8c"><span class="cl-724f5ca0">gentoo</span></p></td>
<td class="cl-72511498"><p class="cl-72510a8c"><span class="cl-724f5ca0">BISCOE</span></p></td>
<td class="cl-725114a0"><p class="cl-72510a8d"><span class="cl-724f5ca0">52.2</span></p></td>
<td class="cl-72511498"><p class="cl-72510a8c"><span class="cl-724f5ca0">male</span></p></td>
<td class="cl-725114a0"><p class="cl-72510a8d"><span class="cl-724f5ca0">2009</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-72511498"><p class="cl-72510a8c"><span class="cl-724f5ca0">adelie</span></p></td>
<td class="cl-72511498"><p class="cl-72510a8c"><span class="cl-724f5ca0">DREAM</span></p></td>
<td class="cl-725114a0"><p class="cl-72510a8d"><span class="cl-724f5ca0">42.2</span></p></td>
<td class="cl-72511498"><p class="cl-72510a8c"><span class="cl-724f5ca0">female</span></p></td>
<td class="cl-725114a0"><p class="cl-72510a8d"><span class="cl-724f5ca0">2007</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-72511498"><p class="cl-72510a8c"><span class="cl-724f5ca0">gentoo</span></p></td>
<td class="cl-72511498"><p class="cl-72510a8c"><span class="cl-724f5ca0">BISCOE</span></p></td>
<td class="cl-725114a0"><p class="cl-72510a8d"><span class="cl-724f5ca0">50.8</span></p></td>
<td class="cl-72511498"><p class="cl-72510a8c"><span class="cl-724f5ca0">male</span></p></td>
<td class="cl-725114a0"><p class="cl-72510a8d"><span class="cl-724f5ca0">2009</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-725114a1"><p class="cl-72510a8c"><span class="cl-724f5ca0">adelie</span></p></td>
<td class="cl-725114a1"><p class="cl-72510a8c"><span class="cl-724f5ca0">DREAM</span></p></td>
<td class="cl-725114aa"><p class="cl-72510a8d"><span class="cl-724f5ca0">42.3</span></p></td>
<td class="cl-725114a1"><p class="cl-72510a8c"><span class="cl-724f5ca0">male</span></p></td>
<td class="cl-725114aa"><p class="cl-72510a8d"><span class="cl-724f5ca0">2007</span></p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>You can also pass a anonymous function if you need to specify arguments:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-6_f434c4241fec5a5c1db51d9cdd449f03">
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/set_formatter.html">set_formatter</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>sex <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> \<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/ifelse.html">ifelse</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"male"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"m"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"f"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> </span></code></pre></div>
<div class="cell-output-display">

<div class="tabwid">
<style>.cl-7261dd94{}.cl-725ecba4{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-725ff538{margin:0;text-align:left;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-725ff542{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-725ffe70{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-725ffe7a{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-725ffe7b{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-725ffe7c{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-725ffe7d{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-725ffe84{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style>
<table data-quarto-disable-processing="true" class="cl-7261dd94">
<thead><tr style="overflow-wrap:break-word;">
<th class="cl-725ffe70"><p class="cl-725ff538"><span class="cl-725ecba4">species</span></p></th>
<th class="cl-725ffe70"><p class="cl-725ff538"><span class="cl-725ecba4">island</span></p></th>
<th class="cl-725ffe7a"><p class="cl-725ff542"><span class="cl-725ecba4">bill_length_mm</span></p></th>
<th class="cl-725ffe70"><p class="cl-725ff538"><span class="cl-725ecba4">sex</span></p></th>
<th class="cl-725ffe7a"><p class="cl-725ff542"><span class="cl-725ecba4">year</span></p></th>
</tr></thead>
<tbody>
<tr style="overflow-wrap:break-word;">
<td class="cl-725ffe7b"><p class="cl-725ff538"><span class="cl-725ecba4">Chinstrap</span></p></td>
<td class="cl-725ffe7b"><p class="cl-725ff538"><span class="cl-725ecba4">Dream</span></p></td>
<td class="cl-725ffe7c"><p class="cl-725ff542"><span class="cl-725ecba4">49.0</span></p></td>
<td class="cl-725ffe7b"><p class="cl-725ff538"><span class="cl-725ecba4">m</span></p></td>
<td class="cl-725ffe7c"><p class="cl-725ff542"><span class="cl-725ecba4">2008</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-725ffe7b"><p class="cl-725ff538"><span class="cl-725ecba4">Gentoo</span></p></td>
<td class="cl-725ffe7b"><p class="cl-725ff538"><span class="cl-725ecba4">Biscoe</span></p></td>
<td class="cl-725ffe7c"><p class="cl-725ff542"><span class="cl-725ecba4">52.2</span></p></td>
<td class="cl-725ffe7b"><p class="cl-725ff538"><span class="cl-725ecba4">m</span></p></td>
<td class="cl-725ffe7c"><p class="cl-725ff542"><span class="cl-725ecba4">2009</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-725ffe7b"><p class="cl-725ff538"><span class="cl-725ecba4">Adelie</span></p></td>
<td class="cl-725ffe7b"><p class="cl-725ff538"><span class="cl-725ecba4">Dream</span></p></td>
<td class="cl-725ffe7c"><p class="cl-725ff542"><span class="cl-725ecba4">42.2</span></p></td>
<td class="cl-725ffe7b"><p class="cl-725ff538"><span class="cl-725ecba4">f</span></p></td>
<td class="cl-725ffe7c"><p class="cl-725ff542"><span class="cl-725ecba4">2007</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-725ffe7b"><p class="cl-725ff538"><span class="cl-725ecba4">Gentoo</span></p></td>
<td class="cl-725ffe7b"><p class="cl-725ff538"><span class="cl-725ecba4">Biscoe</span></p></td>
<td class="cl-725ffe7c"><p class="cl-725ff542"><span class="cl-725ecba4">50.8</span></p></td>
<td class="cl-725ffe7b"><p class="cl-725ff538"><span class="cl-725ecba4">m</span></p></td>
<td class="cl-725ffe7c"><p class="cl-725ff542"><span class="cl-725ecba4">2009</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-725ffe7d"><p class="cl-725ff538"><span class="cl-725ecba4">Adelie</span></p></td>
<td class="cl-725ffe7d"><p class="cl-725ff538"><span class="cl-725ecba4">Dream</span></p></td>
<td class="cl-725ffe84"><p class="cl-725ff542"><span class="cl-725ecba4">42.3</span></p></td>
<td class="cl-725ffe7d"><p class="cl-725ff538"><span class="cl-725ecba4">m</span></p></td>
<td class="cl-725ffe84"><p class="cl-725ff542"><span class="cl-725ecba4">2007</span></p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>A particularly good use of this is using one of the labeller functions from <code>scales</code>, e.g.&nbsp;if you want to format currency:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-7_74bd0fd1f5da3828583d640040e89b38">
<div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/data.frame.html">data.frame</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>A <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">12.1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">21.56</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.64</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, B <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">44.0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">54.44</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/flextable.html">flextable</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/set_formatter.html">set_formatter</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>A <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scales</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://scales.r-lib.org/reference/dollar_format.html">label_dollar</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">

<div class="tabwid">
<style>.cl-6e298ada{}.cl-6e25e1a0{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-6e278244{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-6e278ed8{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e278ed9{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e278ee2{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style>
<table data-quarto-disable-processing="true" class="cl-6e298ada">
<thead><tr style="overflow-wrap:break-word;">
<th class="cl-6e278ed8"><p class="cl-6e278244"><span class="cl-6e25e1a0">A</span></p></th>
<th class="cl-6e278ed8"><p class="cl-6e278244"><span class="cl-6e25e1a0">B</span></p></th>
</tr></thead>
<tbody>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e278ed9"><p class="cl-6e278244"><span class="cl-6e25e1a0">$12.10</span></p></td>
<td class="cl-6e278ed9"><p class="cl-6e278244"><span class="cl-6e25e1a0">44.00</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e278ed9"><p class="cl-6e278244"><span class="cl-6e25e1a0">$21.56</span></p></td>
<td class="cl-6e278ed9"><p class="cl-6e278244"><span class="cl-6e25e1a0">54.44</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e278ee2"><p class="cl-6e278244"><span class="cl-6e25e1a0">$3.64</span></p></td>
<td class="cl-6e278ee2"><p class="cl-6e278244"><span class="cl-6e25e1a0">6.00</span></p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<section id="multiple-heading-levelsgrouping" class="level3"><h3 class="anchored" data-anchor-id="multiple-heading-levelsgrouping">Multiple heading levels/grouping</h3>
<p>You can also make fairly nice tables with a grouping structure in the header using <code><a href="https://davidgohel.github.io/flextable/reference/separate_header.html">separate_header()</a></code>. This function will interpret column names with a separator (e.g.&nbsp;“_” as groups and sub-groups.</p>
<p>Consider the following (unremarkable) dataframe which summarizes penguin bill length by <code>species</code> and <code>sex</code>:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-8_35ce7332206388a0c0f180a290487905">
<div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_data</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">palmerpenguins</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://allisonhorst.github.io/palmerpenguins/reference/penguins.html">penguins</a></span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">species</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sex</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bill_length_mm</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">year</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://tidyr.tidyverse.org/reference/drop_na.html">drop_na</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sex</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">species</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sex</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">year</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/summarise.html">summarize</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>bill.length <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/mean.html">mean</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bill_length_mm</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, .groups <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_data</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/slice.html">slice_sample</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="kable-table">
<table class="table table-sm table-striped small">
<thead><tr class="header">
<th style="text-align: left;">species</th>
<th style="text-align: left;">sex</th>
<th style="text-align: right;">year</th>
<th style="text-align: right;">bill.length</th>
</tr></thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Adelie</td>
<td style="text-align: left;">female</td>
<td style="text-align: right;">2008</td>
<td style="text-align: right;">36.51600</td>
</tr>
<tr class="even">
<td style="text-align: left;">Gentoo</td>
<td style="text-align: left;">female</td>
<td style="text-align: right;">2009</td>
<td style="text-align: right;">46.26000</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Chinstrap</td>
<td style="text-align: left;">female</td>
<td style="text-align: right;">2008</td>
<td style="text-align: right;">46.00000</td>
</tr>
<tr class="even">
<td style="text-align: left;">Gentoo</td>
<td style="text-align: left;">male</td>
<td style="text-align: right;">2008</td>
<td style="text-align: right;">48.53913</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Chinstrap</td>
<td style="text-align: left;">male</td>
<td style="text-align: right;">2009</td>
<td style="text-align: right;">51.10000</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Let’s pipe that into <code>flextable</code>, repeat the <code>year</code> column formatting from before, and also round the <code>bill.length</code> column to 2 digits.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-9_a2ab1e8f468e72b4e2cd1eba640e0ce1">
<div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_data</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/slice.html">slice_sample</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/flextable.html">flextable</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/colformat_num.html">colformat_num</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>, big.mark <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/colformat_double.html">colformat_double</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>digits <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_2</span></span></code></pre></div>
<div class="cell-output-display">

<div class="tabwid">
<style>.cl-6e4e94b0{}.cl-6e4b7e56{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-6e4cbe38{margin:0;text-align:left;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-6e4cbe60{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-6e4cc680{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e4cc681{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e4cc68a{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e4cc68b{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e4cc68c{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e4cc694{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style>
<table data-quarto-disable-processing="true" class="cl-6e4e94b0">
<thead><tr style="overflow-wrap:break-word;">
<th class="cl-6e4cc680"><p class="cl-6e4cbe38"><span class="cl-6e4b7e56">species</span></p></th>
<th class="cl-6e4cc680"><p class="cl-6e4cbe38"><span class="cl-6e4b7e56">sex</span></p></th>
<th class="cl-6e4cc681"><p class="cl-6e4cbe60"><span class="cl-6e4b7e56">year</span></p></th>
<th class="cl-6e4cc681"><p class="cl-6e4cbe60"><span class="cl-6e4b7e56">bill.length</span></p></th>
</tr></thead>
<tbody>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e4cc68a"><p class="cl-6e4cbe38"><span class="cl-6e4b7e56">Chinstrap</span></p></td>
<td class="cl-6e4cc68a"><p class="cl-6e4cbe38"><span class="cl-6e4b7e56">male</span></p></td>
<td class="cl-6e4cc68b"><p class="cl-6e4cbe60"><span class="cl-6e4b7e56">2008</span></p></td>
<td class="cl-6e4cc68b"><p class="cl-6e4cbe60"><span class="cl-6e4b7e56">51.40</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e4cc68a"><p class="cl-6e4cbe38"><span class="cl-6e4b7e56">Gentoo</span></p></td>
<td class="cl-6e4cc68a"><p class="cl-6e4cbe38"><span class="cl-6e4b7e56">female</span></p></td>
<td class="cl-6e4cc68b"><p class="cl-6e4cbe60"><span class="cl-6e4b7e56">2009</span></p></td>
<td class="cl-6e4cc68b"><p class="cl-6e4cbe60"><span class="cl-6e4b7e56">46.26</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e4cc68a"><p class="cl-6e4cbe38"><span class="cl-6e4b7e56">Chinstrap</span></p></td>
<td class="cl-6e4cc68a"><p class="cl-6e4cbe38"><span class="cl-6e4b7e56">female</span></p></td>
<td class="cl-6e4cc68b"><p class="cl-6e4cbe60"><span class="cl-6e4b7e56">2009</span></p></td>
<td class="cl-6e4cc68b"><p class="cl-6e4cbe60"><span class="cl-6e4b7e56">47.01</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e4cc68a"><p class="cl-6e4cbe38"><span class="cl-6e4b7e56">Gentoo</span></p></td>
<td class="cl-6e4cc68a"><p class="cl-6e4cbe38"><span class="cl-6e4b7e56">male</span></p></td>
<td class="cl-6e4cc68b"><p class="cl-6e4cbe60"><span class="cl-6e4b7e56">2007</span></p></td>
<td class="cl-6e4cc68b"><p class="cl-6e4cbe60"><span class="cl-6e4b7e56">49.00</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e4cc68c"><p class="cl-6e4cbe38"><span class="cl-6e4b7e56">Chinstrap</span></p></td>
<td class="cl-6e4cc68c"><p class="cl-6e4cbe38"><span class="cl-6e4b7e56">female</span></p></td>
<td class="cl-6e4cc694"><p class="cl-6e4cbe60"><span class="cl-6e4b7e56">2008</span></p></td>
<td class="cl-6e4cc694"><p class="cl-6e4cbe60"><span class="cl-6e4b7e56">46.00</span></p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>We can make this a lot easier to read if we have species and island as header rows. We’ll start by <code>pivot_wider</code>-ing these two columns. Note that <code>pivot_wider</code> defaults to combining <code>species</code> and <code>island</code> with an underscore (this becomes important momentarily):</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-10_26d88fe3d4a991c9d8ee46d3416739bf">
<div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_data</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://tidyr.tidyverse.org/reference/pivot_wider.html">pivot_wider</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>names_from <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"species"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, values_from <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bill.length"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/flextable.html">flextable</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/colformat_num.html">colformat_num</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>, big.mark <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># reapply our formatting from before</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/colformat_double.html">colformat_double</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>digits <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_3</span></span></code></pre></div>
<div class="cell-output-display">

<div class="tabwid">
<style>.cl-6e61e9fc{}.cl-6e5ec830{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-6e601f78{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-6e602748{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e602752{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e602753{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style>
<table data-quarto-disable-processing="true" class="cl-6e61e9fc">
<thead><tr style="overflow-wrap:break-word;">
<th class="cl-6e602748"><p class="cl-6e601f78"><span class="cl-6e5ec830">year</span></p></th>
<th class="cl-6e602748"><p class="cl-6e601f78"><span class="cl-6e5ec830">Adelie_female</span></p></th>
<th class="cl-6e602748"><p class="cl-6e601f78"><span class="cl-6e5ec830">Adelie_male</span></p></th>
<th class="cl-6e602748"><p class="cl-6e601f78"><span class="cl-6e5ec830">Chinstrap_female</span></p></th>
<th class="cl-6e602748"><p class="cl-6e601f78"><span class="cl-6e5ec830">Chinstrap_male</span></p></th>
<th class="cl-6e602748"><p class="cl-6e601f78"><span class="cl-6e5ec830">Gentoo_female</span></p></th>
<th class="cl-6e602748"><p class="cl-6e601f78"><span class="cl-6e5ec830">Gentoo_male</span></p></th>
</tr></thead>
<tbody>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e602752"><p class="cl-6e601f78"><span class="cl-6e5ec830">2007</span></p></td>
<td class="cl-6e602752"><p class="cl-6e601f78"><span class="cl-6e5ec830">37.92</span></p></td>
<td class="cl-6e602752"><p class="cl-6e601f78"><span class="cl-6e5ec830">39.95</span></p></td>
<td class="cl-6e602752"><p class="cl-6e601f78"><span class="cl-6e5ec830">46.57</span></p></td>
<td class="cl-6e602752"><p class="cl-6e601f78"><span class="cl-6e5ec830">50.88</span></p></td>
<td class="cl-6e602752"><p class="cl-6e601f78"><span class="cl-6e5ec830">45.06</span></p></td>
<td class="cl-6e602752"><p class="cl-6e601f78"><span class="cl-6e5ec830">49.00</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e602752"><p class="cl-6e601f78"><span class="cl-6e5ec830">2008</span></p></td>
<td class="cl-6e602752"><p class="cl-6e601f78"><span class="cl-6e5ec830">36.52</span></p></td>
<td class="cl-6e602752"><p class="cl-6e601f78"><span class="cl-6e5ec830">40.60</span></p></td>
<td class="cl-6e602752"><p class="cl-6e601f78"><span class="cl-6e5ec830">46.00</span></p></td>
<td class="cl-6e602752"><p class="cl-6e601f78"><span class="cl-6e5ec830">51.40</span></p></td>
<td class="cl-6e602752"><p class="cl-6e601f78"><span class="cl-6e5ec830">45.30</span></p></td>
<td class="cl-6e602752"><p class="cl-6e601f78"><span class="cl-6e5ec830">48.54</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e602753"><p class="cl-6e601f78"><span class="cl-6e5ec830">2009</span></p></td>
<td class="cl-6e602753"><p class="cl-6e601f78"><span class="cl-6e5ec830">37.41</span></p></td>
<td class="cl-6e602753"><p class="cl-6e601f78"><span class="cl-6e5ec830">40.56</span></p></td>
<td class="cl-6e602753"><p class="cl-6e601f78"><span class="cl-6e5ec830">47.01</span></p></td>
<td class="cl-6e602753"><p class="cl-6e601f78"><span class="cl-6e5ec830">51.10</span></p></td>
<td class="cl-6e602753"><p class="cl-6e601f78"><span class="cl-6e5ec830">46.26</span></p></td>
<td class="cl-6e602753"><p class="cl-6e601f78"><span class="cl-6e5ec830">50.88</span></p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p><code><a href="https://davidgohel.github.io/flextable/reference/separate_header.html">separate_header()</a></code> parses the column names using the underscore, and makes two header levels:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-11_18a495bb65bda38be594534b856a24c5">
<div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/separate_header.html">separate_header</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_4</span></span></code></pre></div>
<div class="cell-output-display">

<div class="tabwid">
<style>.cl-6e716f26{}.cl-6e6ddb36{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-6e6f88f0{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-6e6f88fa{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-6e6f8904{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-6e6f9192{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e6f919c{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e6f919d{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e6f919e{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e6f91a6{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e6f91a7{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e6f91a8{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style>
<table data-quarto-disable-processing="true" class="cl-6e716f26">
<thead>
<tr style="overflow-wrap:break-word;">
<th rowspan="2" class="cl-6e6f9192"><p class="cl-6e6f88f0"><span class="cl-6e6ddb36">year</span></p></th>
<th colspan="2" class="cl-6e6f919c"><p class="cl-6e6f88fa"><span class="cl-6e6ddb36">Adelie</span></p></th>
<th colspan="2" class="cl-6e6f919c"><p class="cl-6e6f88fa"><span class="cl-6e6ddb36">Chinstrap</span></p></th>
<th colspan="2" class="cl-6e6f919c"><p class="cl-6e6f88fa"><span class="cl-6e6ddb36">Gentoo</span></p></th>
</tr>
<tr style="overflow-wrap:break-word;">
<th class="cl-6e6f91a6"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">female</span></p></th>
<th class="cl-6e6f91a6"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">male</span></p></th>
<th class="cl-6e6f91a6"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">female</span></p></th>
<th class="cl-6e6f91a6"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">male</span></p></th>
<th class="cl-6e6f91a6"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">female</span></p></th>
<th class="cl-6e6f91a6"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">male</span></p></th>
</tr>
</thead>
<tbody>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e6f91a7"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">2007</span></p></td>
<td class="cl-6e6f91a7"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">37.92</span></p></td>
<td class="cl-6e6f91a7"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">39.95</span></p></td>
<td class="cl-6e6f91a7"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">46.57</span></p></td>
<td class="cl-6e6f91a7"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">50.88</span></p></td>
<td class="cl-6e6f91a7"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">45.06</span></p></td>
<td class="cl-6e6f91a7"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">49.00</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e6f91a7"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">2008</span></p></td>
<td class="cl-6e6f91a7"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">36.52</span></p></td>
<td class="cl-6e6f91a7"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">40.60</span></p></td>
<td class="cl-6e6f91a7"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">46.00</span></p></td>
<td class="cl-6e6f91a7"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">51.40</span></p></td>
<td class="cl-6e6f91a7"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">45.30</span></p></td>
<td class="cl-6e6f91a7"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">48.54</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e6f91a8"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">2009</span></p></td>
<td class="cl-6e6f91a8"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">37.41</span></p></td>
<td class="cl-6e6f91a8"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">40.56</span></p></td>
<td class="cl-6e6f91a8"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">47.01</span></p></td>
<td class="cl-6e6f91a8"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">51.10</span></p></td>
<td class="cl-6e6f91a8"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">46.26</span></p></td>
<td class="cl-6e6f91a8"><p class="cl-6e6f8904"><span class="cl-6e6ddb36">50.88</span></p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>You can change separator with `separate_header(…, split = “…regex…”). This is useful if your variable names already use underscore as a separator.</p>
<p>Note that since in the combined column names, <code>species</code> comes before <code>sex</code> (e.g.&nbsp;<code>Adelie_male</code>), it’s been used as the top header row. If you switch the order of the <code>names_from</code> argument in <code>pivot_wider</code>, you get <code>sex</code> as the top row. This gives a slightly unexpected result: why are female/male repeated across each category?</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-12_b222db54dbc72aec5b566121329a5c46">
<div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_data</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://tidyr.tidyverse.org/reference/pivot_wider.html">pivot_wider</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>names_from <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"species"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, values_from <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bill.length"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/flextable.html">flextable</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/separate_header.html">separate_header</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/colformat_num.html">colformat_num</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>, big.mark <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># reapply our formatting from before</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/colformat_double.html">colformat_double</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>digits <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">

<div class="tabwid">
<style>.cl-6e851f12{}.cl-6e824076{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-6e836e38{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-6e836e42{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-6e83763a{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e837644{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e837645{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e837646{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e83764e{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e83764f{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style>
<table data-quarto-disable-processing="true" class="cl-6e851f12">
<thead>
<tr style="overflow-wrap:break-word;">
<th rowspan="2" class="cl-6e83763a"><p class="cl-6e836e38"><span class="cl-6e824076">year</span></p></th>
<th class="cl-6e837644"><p class="cl-6e836e42"><span class="cl-6e824076">female</span></p></th>
<th class="cl-6e837644"><p class="cl-6e836e42"><span class="cl-6e824076">male</span></p></th>
<th class="cl-6e837644"><p class="cl-6e836e42"><span class="cl-6e824076">female</span></p></th>
<th class="cl-6e837644"><p class="cl-6e836e42"><span class="cl-6e824076">male</span></p></th>
<th class="cl-6e837644"><p class="cl-6e836e42"><span class="cl-6e824076">female</span></p></th>
<th class="cl-6e837644"><p class="cl-6e836e42"><span class="cl-6e824076">male</span></p></th>
</tr>
<tr style="overflow-wrap:break-word;">
<th class="cl-6e837646"><p class="cl-6e836e42"><span class="cl-6e824076">Adelie</span></p></th>
<th class="cl-6e837646"><p class="cl-6e836e42"><span class="cl-6e824076">Adelie</span></p></th>
<th class="cl-6e837646"><p class="cl-6e836e42"><span class="cl-6e824076">Chinstrap</span></p></th>
<th class="cl-6e837646"><p class="cl-6e836e42"><span class="cl-6e824076">Chinstrap</span></p></th>
<th class="cl-6e837646"><p class="cl-6e836e42"><span class="cl-6e824076">Gentoo</span></p></th>
<th class="cl-6e837646"><p class="cl-6e836e42"><span class="cl-6e824076">Gentoo</span></p></th>
</tr>
</thead>
<tbody>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e83764e"><p class="cl-6e836e42"><span class="cl-6e824076">2007</span></p></td>
<td class="cl-6e83764e"><p class="cl-6e836e42"><span class="cl-6e824076">37.92</span></p></td>
<td class="cl-6e83764e"><p class="cl-6e836e42"><span class="cl-6e824076">39.95</span></p></td>
<td class="cl-6e83764e"><p class="cl-6e836e42"><span class="cl-6e824076">46.57</span></p></td>
<td class="cl-6e83764e"><p class="cl-6e836e42"><span class="cl-6e824076">50.88</span></p></td>
<td class="cl-6e83764e"><p class="cl-6e836e42"><span class="cl-6e824076">45.06</span></p></td>
<td class="cl-6e83764e"><p class="cl-6e836e42"><span class="cl-6e824076">49.00</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e83764e"><p class="cl-6e836e42"><span class="cl-6e824076">2008</span></p></td>
<td class="cl-6e83764e"><p class="cl-6e836e42"><span class="cl-6e824076">36.52</span></p></td>
<td class="cl-6e83764e"><p class="cl-6e836e42"><span class="cl-6e824076">40.60</span></p></td>
<td class="cl-6e83764e"><p class="cl-6e836e42"><span class="cl-6e824076">46.00</span></p></td>
<td class="cl-6e83764e"><p class="cl-6e836e42"><span class="cl-6e824076">51.40</span></p></td>
<td class="cl-6e83764e"><p class="cl-6e836e42"><span class="cl-6e824076">45.30</span></p></td>
<td class="cl-6e83764e"><p class="cl-6e836e42"><span class="cl-6e824076">48.54</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e83764f"><p class="cl-6e836e42"><span class="cl-6e824076">2009</span></p></td>
<td class="cl-6e83764f"><p class="cl-6e836e42"><span class="cl-6e824076">37.41</span></p></td>
<td class="cl-6e83764f"><p class="cl-6e836e42"><span class="cl-6e824076">40.56</span></p></td>
<td class="cl-6e83764f"><p class="cl-6e836e42"><span class="cl-6e824076">47.01</span></p></td>
<td class="cl-6e83764f"><p class="cl-6e836e42"><span class="cl-6e824076">51.10</span></p></td>
<td class="cl-6e83764f"><p class="cl-6e836e42"><span class="cl-6e824076">46.26</span></p></td>
<td class="cl-6e83764f"><p class="cl-6e836e42"><span class="cl-6e824076">50.88</span></p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p><code><a href="https://davidgohel.github.io/flextable/reference/separate_header.html">separate_header()</a></code> doesn’t rearrange columns to put relevant groups next to each other. If you want a spanning column, you’ll need to reorder the columns manually with <code><a href="https://dplyr.tidyverse.org/reference/relocate.html">relocate()</a></code>:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-13_037a7e5490e1d3bf6c2fcaa57fad599e">
<div class="sourceCode" id="cb13" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_data</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://tidyr.tidyverse.org/reference/pivot_wider.html">pivot_wider</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>names_from <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sex"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"species"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, values_from <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bill.length"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/relocate.html">relocate</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://tidyselect.r-lib.org/reference/starts_with.html">starts_with</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"female"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/flextable.html">flextable</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/separate_header.html">separate_header</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/colformat_num.html">colformat_num</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>, big.mark <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># reapply our formatting from before</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/colformat_double.html">colformat_double</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>digits <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">

<div class="tabwid">
<style>.cl-6e9a6fb6{}.cl-6e973378{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-6e98c51c{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-6e98c51d{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-6e98c526{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-6e98ccce{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e98ccd8{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e98ccd9{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e98ccda{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e98cce2{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e98cce3{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6e98cce4{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style>
<table data-quarto-disable-processing="true" class="cl-6e9a6fb6">
<thead>
<tr style="overflow-wrap:break-word;">
<th colspan="3" class="cl-6e98ccce"><p class="cl-6e98c51c"><span class="cl-6e973378">female</span></p></th>
<th rowspan="2" class="cl-6e98ccd9"><p class="cl-6e98c526"><span class="cl-6e973378">year</span></p></th>
<th colspan="3" class="cl-6e98ccce"><p class="cl-6e98c51c"><span class="cl-6e973378">male</span></p></th>
</tr>
<tr style="overflow-wrap:break-word;">
<th class="cl-6e98ccda"><p class="cl-6e98c51d"><span class="cl-6e973378">Adelie</span></p></th>
<th class="cl-6e98ccda"><p class="cl-6e98c51d"><span class="cl-6e973378">Chinstrap</span></p></th>
<th class="cl-6e98ccda"><p class="cl-6e98c51d"><span class="cl-6e973378">Gentoo</span></p></th>
<th class="cl-6e98ccda"><p class="cl-6e98c51d"><span class="cl-6e973378">Adelie</span></p></th>
<th class="cl-6e98ccda"><p class="cl-6e98c51d"><span class="cl-6e973378">Chinstrap</span></p></th>
<th class="cl-6e98ccda"><p class="cl-6e98c51d"><span class="cl-6e973378">Gentoo</span></p></th>
</tr>
</thead>
<tbody>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e98cce3"><p class="cl-6e98c51d"><span class="cl-6e973378">37.92</span></p></td>
<td class="cl-6e98cce3"><p class="cl-6e98c51d"><span class="cl-6e973378">46.57</span></p></td>
<td class="cl-6e98cce3"><p class="cl-6e98c51d"><span class="cl-6e973378">45.06</span></p></td>
<td class="cl-6e98cce3"><p class="cl-6e98c51d"><span class="cl-6e973378">2007</span></p></td>
<td class="cl-6e98cce3"><p class="cl-6e98c51d"><span class="cl-6e973378">39.95</span></p></td>
<td class="cl-6e98cce3"><p class="cl-6e98c51d"><span class="cl-6e973378">50.88</span></p></td>
<td class="cl-6e98cce3"><p class="cl-6e98c51d"><span class="cl-6e973378">49.00</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e98cce3"><p class="cl-6e98c51d"><span class="cl-6e973378">36.52</span></p></td>
<td class="cl-6e98cce3"><p class="cl-6e98c51d"><span class="cl-6e973378">46.00</span></p></td>
<td class="cl-6e98cce3"><p class="cl-6e98c51d"><span class="cl-6e973378">45.30</span></p></td>
<td class="cl-6e98cce3"><p class="cl-6e98c51d"><span class="cl-6e973378">2008</span></p></td>
<td class="cl-6e98cce3"><p class="cl-6e98c51d"><span class="cl-6e973378">40.60</span></p></td>
<td class="cl-6e98cce3"><p class="cl-6e98c51d"><span class="cl-6e973378">51.40</span></p></td>
<td class="cl-6e98cce3"><p class="cl-6e98c51d"><span class="cl-6e973378">48.54</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-6e98cce4"><p class="cl-6e98c51d"><span class="cl-6e973378">37.41</span></p></td>
<td class="cl-6e98cce4"><p class="cl-6e98c51d"><span class="cl-6e973378">47.01</span></p></td>
<td class="cl-6e98cce4"><p class="cl-6e98c51d"><span class="cl-6e973378">46.26</span></p></td>
<td class="cl-6e98cce4"><p class="cl-6e98c51d"><span class="cl-6e973378">2009</span></p></td>
<td class="cl-6e98cce4"><p class="cl-6e98c51d"><span class="cl-6e973378">40.56</span></p></td>
<td class="cl-6e98cce4"><p class="cl-6e98c51d"><span class="cl-6e973378">51.10</span></p></td>
<td class="cl-6e98cce4"><p class="cl-6e98c51d"><span class="cl-6e973378">50.88</span></p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>With savvy use of <code>pivot_wider(names_from = ...)</code> combined with <code>relocate</code>, you can the ordering of header rows and spanning columns you’re after.</p>
</section><section id="change-labels" class="level3"><h3 class="anchored" data-anchor-id="change-labels">Change labels</h3>
<p>We can edit text/values with <code><a href="https://davidgohel.github.io/flextable/reference/labelizor.html">labelizor()</a></code>. The example below changes all instances of female/male to f/m:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-14_770566dd03fd8e036a45814405e227eb">
<div class="sourceCode" id="cb14" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/labelizor.html">labelizor</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>labels <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"female"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"f"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"male"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"m"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">

<div class="tabwid">
<style>.cl-6ea9e46e{}.cl-6ea6d530{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-6ea812f6{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-6ea8130a{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-6ea8130b{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-6ea81ecc{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6ea81ecd{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6ea81ece{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6ea81ed6{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6ea81ed7{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6ea81ee0{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6ea81ee1{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style>
<table data-quarto-disable-processing="true" class="cl-6ea9e46e">
<thead>
<tr style="overflow-wrap:break-word;">
<th rowspan="2" class="cl-6ea81ecc"><p class="cl-6ea812f6"><span class="cl-6ea6d530">year</span></p></th>
<th colspan="2" class="cl-6ea81ecd"><p class="cl-6ea8130a"><span class="cl-6ea6d530">Adelie</span></p></th>
<th colspan="2" class="cl-6ea81ecd"><p class="cl-6ea8130a"><span class="cl-6ea6d530">Chinstrap</span></p></th>
<th colspan="2" class="cl-6ea81ecd"><p class="cl-6ea8130a"><span class="cl-6ea6d530">Gentoo</span></p></th>
</tr>
<tr style="overflow-wrap:break-word;">
<th class="cl-6ea81ed7"><p class="cl-6ea8130b"><span class="cl-6ea6d530">f</span></p></th>
<th class="cl-6ea81ed7"><p class="cl-6ea8130b"><span class="cl-6ea6d530">m</span></p></th>
<th class="cl-6ea81ed7"><p class="cl-6ea8130b"><span class="cl-6ea6d530">f</span></p></th>
<th class="cl-6ea81ed7"><p class="cl-6ea8130b"><span class="cl-6ea6d530">m</span></p></th>
<th class="cl-6ea81ed7"><p class="cl-6ea8130b"><span class="cl-6ea6d530">f</span></p></th>
<th class="cl-6ea81ed7"><p class="cl-6ea8130b"><span class="cl-6ea6d530">m</span></p></th>
</tr>
</thead>
<tbody>
<tr style="overflow-wrap:break-word;">
<td class="cl-6ea81ee0"><p class="cl-6ea8130b"><span class="cl-6ea6d530">2007</span></p></td>
<td class="cl-6ea81ee0"><p class="cl-6ea8130b"><span class="cl-6ea6d530">37.92</span></p></td>
<td class="cl-6ea81ee0"><p class="cl-6ea8130b"><span class="cl-6ea6d530">39.95</span></p></td>
<td class="cl-6ea81ee0"><p class="cl-6ea8130b"><span class="cl-6ea6d530">46.57</span></p></td>
<td class="cl-6ea81ee0"><p class="cl-6ea8130b"><span class="cl-6ea6d530">50.88</span></p></td>
<td class="cl-6ea81ee0"><p class="cl-6ea8130b"><span class="cl-6ea6d530">45.06</span></p></td>
<td class="cl-6ea81ee0"><p class="cl-6ea8130b"><span class="cl-6ea6d530">49.00</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-6ea81ee0"><p class="cl-6ea8130b"><span class="cl-6ea6d530">2008</span></p></td>
<td class="cl-6ea81ee0"><p class="cl-6ea8130b"><span class="cl-6ea6d530">36.52</span></p></td>
<td class="cl-6ea81ee0"><p class="cl-6ea8130b"><span class="cl-6ea6d530">40.60</span></p></td>
<td class="cl-6ea81ee0"><p class="cl-6ea8130b"><span class="cl-6ea6d530">46.00</span></p></td>
<td class="cl-6ea81ee0"><p class="cl-6ea8130b"><span class="cl-6ea6d530">51.40</span></p></td>
<td class="cl-6ea81ee0"><p class="cl-6ea8130b"><span class="cl-6ea6d530">45.30</span></p></td>
<td class="cl-6ea81ee0"><p class="cl-6ea8130b"><span class="cl-6ea6d530">48.54</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-6ea81ee1"><p class="cl-6ea8130b"><span class="cl-6ea6d530">2009</span></p></td>
<td class="cl-6ea81ee1"><p class="cl-6ea8130b"><span class="cl-6ea6d530">37.41</span></p></td>
<td class="cl-6ea81ee1"><p class="cl-6ea8130b"><span class="cl-6ea6d530">40.56</span></p></td>
<td class="cl-6ea81ee1"><p class="cl-6ea8130b"><span class="cl-6ea6d530">47.01</span></p></td>
<td class="cl-6ea81ee1"><p class="cl-6ea8130b"><span class="cl-6ea6d530">51.10</span></p></td>
<td class="cl-6ea81ee1"><p class="cl-6ea8130b"><span class="cl-6ea6d530">46.26</span></p></td>
<td class="cl-6ea81ee1"><p class="cl-6ea8130b"><span class="cl-6ea6d530">50.88</span></p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Adding the <code>j</code> argument selects columns to restrict the changes to:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-15_a34603f605eeda6dbd05823efea9532a">
<div class="sourceCode" id="cb15" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/labelizor.html">labelizor</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Adelie_female"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Chinstrap_female"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, labels <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"female"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"f"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"male"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"m"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">

<div class="tabwid">
<style>.cl-6eb6d962{}.cl-6eb3617e{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-6eb50614{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-6eb5061e{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-6eb50628{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-6eb50efc{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6eb50efd{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6eb50efe{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6eb50f06{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6eb50f07{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6eb50f08{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-6eb50f09{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style>
<table data-quarto-disable-processing="true" class="cl-6eb6d962">
<thead>
<tr style="overflow-wrap:break-word;">
<th rowspan="2" class="cl-6eb50efc"><p class="cl-6eb50614"><span class="cl-6eb3617e">year</span></p></th>
<th colspan="2" class="cl-6eb50efd"><p class="cl-6eb5061e"><span class="cl-6eb3617e">Adelie</span></p></th>
<th colspan="2" class="cl-6eb50efd"><p class="cl-6eb5061e"><span class="cl-6eb3617e">Chinstrap</span></p></th>
<th colspan="2" class="cl-6eb50efd"><p class="cl-6eb5061e"><span class="cl-6eb3617e">Gentoo</span></p></th>
</tr>
<tr style="overflow-wrap:break-word;">
<th class="cl-6eb50f07"><p class="cl-6eb50628"><span class="cl-6eb3617e">f</span></p></th>
<th class="cl-6eb50f07"><p class="cl-6eb50628"><span class="cl-6eb3617e">male</span></p></th>
<th class="cl-6eb50f07"><p class="cl-6eb50628"><span class="cl-6eb3617e">f</span></p></th>
<th class="cl-6eb50f07"><p class="cl-6eb50628"><span class="cl-6eb3617e">male</span></p></th>
<th class="cl-6eb50f07"><p class="cl-6eb50628"><span class="cl-6eb3617e">female</span></p></th>
<th class="cl-6eb50f07"><p class="cl-6eb50628"><span class="cl-6eb3617e">male</span></p></th>
</tr>
</thead>
<tbody>
<tr style="overflow-wrap:break-word;">
<td class="cl-6eb50f08"><p class="cl-6eb50628"><span class="cl-6eb3617e">2007</span></p></td>
<td class="cl-6eb50f08"><p class="cl-6eb50628"><span class="cl-6eb3617e">37.92</span></p></td>
<td class="cl-6eb50f08"><p class="cl-6eb50628"><span class="cl-6eb3617e">39.95</span></p></td>
<td class="cl-6eb50f08"><p class="cl-6eb50628"><span class="cl-6eb3617e">46.57</span></p></td>
<td class="cl-6eb50f08"><p class="cl-6eb50628"><span class="cl-6eb3617e">50.88</span></p></td>
<td class="cl-6eb50f08"><p class="cl-6eb50628"><span class="cl-6eb3617e">45.06</span></p></td>
<td class="cl-6eb50f08"><p class="cl-6eb50628"><span class="cl-6eb3617e">49.00</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-6eb50f08"><p class="cl-6eb50628"><span class="cl-6eb3617e">2008</span></p></td>
<td class="cl-6eb50f08"><p class="cl-6eb50628"><span class="cl-6eb3617e">36.52</span></p></td>
<td class="cl-6eb50f08"><p class="cl-6eb50628"><span class="cl-6eb3617e">40.60</span></p></td>
<td class="cl-6eb50f08"><p class="cl-6eb50628"><span class="cl-6eb3617e">46.00</span></p></td>
<td class="cl-6eb50f08"><p class="cl-6eb50628"><span class="cl-6eb3617e">51.40</span></p></td>
<td class="cl-6eb50f08"><p class="cl-6eb50628"><span class="cl-6eb3617e">45.30</span></p></td>
<td class="cl-6eb50f08"><p class="cl-6eb50628"><span class="cl-6eb3617e">48.54</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-6eb50f09"><p class="cl-6eb50628"><span class="cl-6eb3617e">2009</span></p></td>
<td class="cl-6eb50f09"><p class="cl-6eb50628"><span class="cl-6eb3617e">37.41</span></p></td>
<td class="cl-6eb50f09"><p class="cl-6eb50628"><span class="cl-6eb3617e">40.56</span></p></td>
<td class="cl-6eb50f09"><p class="cl-6eb50628"><span class="cl-6eb3617e">47.01</span></p></td>
<td class="cl-6eb50f09"><p class="cl-6eb50628"><span class="cl-6eb3617e">51.10</span></p></td>
<td class="cl-6eb50f09"><p class="cl-6eb50628"><span class="cl-6eb3617e">46.26</span></p></td>
<td class="cl-6eb50f09"><p class="cl-6eb50628"><span class="cl-6eb3617e">50.88</span></p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Note that for the <code>j</code> argument, the rownames are based on the underlying <code>df</code>, not what you seen in the flextable. That’s why I have to refer to <code>Adelie_female</code>, which was one of the columns that resulted from out <code><a href="https://tidyr.tidyverse.org/reference/pivot_wider.html">pivot_wider()</a></code>ing. You can do a lot with <code>j</code> (and in other functions that support it, <code>i</code> for rows), including using logical expressions to filter columns. <a href="https://ardata-fr.github.io/flextable-book/table-design.html#usage">See here</a> for more details. The <code>labels</code> argument takes name-value pairs where the name is the value to replace and the value is the replacement value.</p>
</section><section id="conditional-formatting" class="level3"><h3 class="anchored" data-anchor-id="conditional-formatting">Conditional formatting</h3>
<p>You can target cells with specific values for various kinds of formatting. For example, <code><a href="https://davidgohel.github.io/flextable/reference/color.html">color()</a></code> sets the text color. The <code>color</code> argument takes either a vector of colors or a function which returns a vector of colors—here I’ve just used an anonymous function to color code based on whether a value is below or above 40:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-16_e29c45194f0902a1a0f53b6fd1aa10ea">
<div class="sourceCode" id="cb16" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/color.html">color</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> \<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/ifelse.html">ifelse</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">

<div class="tabwid">
<style>.cl-8af13e62{}.cl-8aedbf9e{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-8aedbfa8{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(255, 0, 0, 1.00);background-color:transparent;}.cl-8aef3522{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-8aef352c{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-8aef352d{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-8aef3fa4{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8aef3fa5{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8aef3fae{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8aef3faf{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8aef3fb0{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8aef3fb8{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8aef3fb9{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style>
<table data-quarto-disable-processing="true" class="cl-8af13e62">
<thead>
<tr style="overflow-wrap:break-word;">
<th rowspan="2" class="cl-8aef3fa4"><p class="cl-8aef3522"><span class="cl-8aedbf9e">year</span></p></th>
<th colspan="2" class="cl-8aef3fa5"><p class="cl-8aef352c"><span class="cl-8aedbf9e">Adelie</span></p></th>
<th colspan="2" class="cl-8aef3fa5"><p class="cl-8aef352c"><span class="cl-8aedbf9e">Chinstrap</span></p></th>
<th colspan="2" class="cl-8aef3fa5"><p class="cl-8aef352c"><span class="cl-8aedbf9e">Gentoo</span></p></th>
</tr>
<tr style="overflow-wrap:break-word;">
<th class="cl-8aef3fb0"><p class="cl-8aef352d"><span class="cl-8aedbf9e">female</span></p></th>
<th class="cl-8aef3fb0"><p class="cl-8aef352d"><span class="cl-8aedbf9e">male</span></p></th>
<th class="cl-8aef3fb0"><p class="cl-8aef352d"><span class="cl-8aedbf9e">female</span></p></th>
<th class="cl-8aef3fb0"><p class="cl-8aef352d"><span class="cl-8aedbf9e">male</span></p></th>
<th class="cl-8aef3fb0"><p class="cl-8aef352d"><span class="cl-8aedbf9e">female</span></p></th>
<th class="cl-8aef3fb0"><p class="cl-8aef352d"><span class="cl-8aedbf9e">male</span></p></th>
</tr>
</thead>
<tbody>
<tr style="overflow-wrap:break-word;">
<td class="cl-8aef3fb8"><p class="cl-8aef352d"><span class="cl-8aedbf9e">2007</span></p></td>
<td class="cl-8aef3fb8"><p class="cl-8aef352d"><span class="cl-8aedbfa8">37.92</span></p></td>
<td class="cl-8aef3fb8"><p class="cl-8aef352d"><span class="cl-8aedbfa8">39.95</span></p></td>
<td class="cl-8aef3fb8"><p class="cl-8aef352d"><span class="cl-8aedbf9e">46.57</span></p></td>
<td class="cl-8aef3fb8"><p class="cl-8aef352d"><span class="cl-8aedbf9e">50.88</span></p></td>
<td class="cl-8aef3fb8"><p class="cl-8aef352d"><span class="cl-8aedbf9e">45.06</span></p></td>
<td class="cl-8aef3fb8"><p class="cl-8aef352d"><span class="cl-8aedbf9e">49.00</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-8aef3fb8"><p class="cl-8aef352d"><span class="cl-8aedbf9e">2008</span></p></td>
<td class="cl-8aef3fb8"><p class="cl-8aef352d"><span class="cl-8aedbfa8">36.52</span></p></td>
<td class="cl-8aef3fb8"><p class="cl-8aef352d"><span class="cl-8aedbf9e">40.60</span></p></td>
<td class="cl-8aef3fb8"><p class="cl-8aef352d"><span class="cl-8aedbf9e">46.00</span></p></td>
<td class="cl-8aef3fb8"><p class="cl-8aef352d"><span class="cl-8aedbf9e">51.40</span></p></td>
<td class="cl-8aef3fb8"><p class="cl-8aef352d"><span class="cl-8aedbf9e">45.30</span></p></td>
<td class="cl-8aef3fb8"><p class="cl-8aef352d"><span class="cl-8aedbf9e">48.54</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-8aef3fb9"><p class="cl-8aef352d"><span class="cl-8aedbf9e">2009</span></p></td>
<td class="cl-8aef3fb9"><p class="cl-8aef352d"><span class="cl-8aedbfa8">37.41</span></p></td>
<td class="cl-8aef3fb9"><p class="cl-8aef352d"><span class="cl-8aedbf9e">40.56</span></p></td>
<td class="cl-8aef3fb9"><p class="cl-8aef352d"><span class="cl-8aedbf9e">47.01</span></p></td>
<td class="cl-8aef3fb9"><p class="cl-8aef352d"><span class="cl-8aedbf9e">51.10</span></p></td>
<td class="cl-8aef3fb9"><p class="cl-8aef352d"><span class="cl-8aedbf9e">46.26</span></p></td>
<td class="cl-8aef3fb9"><p class="cl-8aef352d"><span class="cl-8aedbf9e">50.88</span></p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>You can get more fancy and use a scale from the <code>scales</code> package:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-17_fc28493e9afd0ed3d5e77ef42f89a5ba">
<div class="sourceCode" id="cb17" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/color.html">color</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scales</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://scales.r-lib.org/reference/col_numeric.html">col_numeric</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>palette <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"viridis"</span>, domain <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">52</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning: Some values were outside the color scale and will be treated as NA</code></pre>
</div>
<div class="cell-output-display">

<div class="tabwid">
<style>.cl-8b02c3da{}.cl-8affcb08{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-8affcb12{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(128, 128, 128, 1.00);background-color:transparent;}.cl-8affcb13{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(46, 111, 142, 1.00);background-color:transparent;}.cl-8affcb14{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(37, 132, 142, 1.00);background-color:transparent;}.cl-8affcb1c{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(94, 201, 98, 1.00);background-color:transparent;}.cl-8affcb1d{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(221, 227, 24, 1.00);background-color:transparent;}.cl-8affcb1e{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(60, 188, 116, 1.00);background-color:transparent;}.cl-8affcb26{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(163, 218, 55, 1.00);background-color:transparent;}.cl-8affcb27{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(53, 95, 141, 1.00);background-color:transparent;}.cl-8affcb30{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(34, 140, 141, 1.00);background-color:transparent;}.cl-8affcb31{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(81, 196, 106, 1.00);background-color:transparent;}.cl-8affcb32{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(236, 229, 27, 1.00);background-color:transparent;}.cl-8affcb3a{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(65, 189, 114, 1.00);background-color:transparent;}.cl-8affcb3b{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(149, 216, 64, 1.00);background-color:transparent;}.cl-8affcb3c{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(48, 105, 142, 1.00);background-color:transparent;}.cl-8affcb3d{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(34, 139, 141, 1.00);background-color:transparent;}.cl-8affcb44{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(105, 205, 91, 1.00);background-color:transparent;}.cl-8affcb45{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(228, 228, 25, 1.00);background-color:transparent;}.cl-8affcb46{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(87, 198, 102, 1.00);background-color:transparent;}.cl-8b00f97e{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-8b00f988{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-8b00f992{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-8b010220{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b01022a{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b01022b{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b01022c{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b01022d{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b010234{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b010235{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style>
<table data-quarto-disable-processing="true" class="cl-8b02c3da">
<thead>
<tr style="overflow-wrap:break-word;">
<th rowspan="2" class="cl-8b010220"><p class="cl-8b00f97e"><span class="cl-8affcb08">year</span></p></th>
<th colspan="2" class="cl-8b01022a"><p class="cl-8b00f988"><span class="cl-8affcb08">Adelie</span></p></th>
<th colspan="2" class="cl-8b01022a"><p class="cl-8b00f988"><span class="cl-8affcb08">Chinstrap</span></p></th>
<th colspan="2" class="cl-8b01022a"><p class="cl-8b00f988"><span class="cl-8affcb08">Gentoo</span></p></th>
</tr>
<tr style="overflow-wrap:break-word;">
<th class="cl-8b01022d"><p class="cl-8b00f992"><span class="cl-8affcb08">female</span></p></th>
<th class="cl-8b01022d"><p class="cl-8b00f992"><span class="cl-8affcb08">male</span></p></th>
<th class="cl-8b01022d"><p class="cl-8b00f992"><span class="cl-8affcb08">female</span></p></th>
<th class="cl-8b01022d"><p class="cl-8b00f992"><span class="cl-8affcb08">male</span></p></th>
<th class="cl-8b01022d"><p class="cl-8b00f992"><span class="cl-8affcb08">female</span></p></th>
<th class="cl-8b01022d"><p class="cl-8b00f992"><span class="cl-8affcb08">male</span></p></th>
</tr>
</thead>
<tbody>
<tr style="overflow-wrap:break-word;">
<td class="cl-8b010234"><p class="cl-8b00f992"><span class="cl-8affcb12">2007</span></p></td>
<td class="cl-8b010234"><p class="cl-8b00f992"><span class="cl-8affcb13">37.92</span></p></td>
<td class="cl-8b010234"><p class="cl-8b00f992"><span class="cl-8affcb14">39.95</span></p></td>
<td class="cl-8b010234"><p class="cl-8b00f992"><span class="cl-8affcb1c">46.57</span></p></td>
<td class="cl-8b010234"><p class="cl-8b00f992"><span class="cl-8affcb1d">50.88</span></p></td>
<td class="cl-8b010234"><p class="cl-8b00f992"><span class="cl-8affcb1e">45.06</span></p></td>
<td class="cl-8b010234"><p class="cl-8b00f992"><span class="cl-8affcb26">49.00</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-8b010234"><p class="cl-8b00f992"><span class="cl-8affcb12">2008</span></p></td>
<td class="cl-8b010234"><p class="cl-8b00f992"><span class="cl-8affcb27">36.52</span></p></td>
<td class="cl-8b010234"><p class="cl-8b00f992"><span class="cl-8affcb30">40.60</span></p></td>
<td class="cl-8b010234"><p class="cl-8b00f992"><span class="cl-8affcb31">46.00</span></p></td>
<td class="cl-8b010234"><p class="cl-8b00f992"><span class="cl-8affcb32">51.40</span></p></td>
<td class="cl-8b010234"><p class="cl-8b00f992"><span class="cl-8affcb3a">45.30</span></p></td>
<td class="cl-8b010234"><p class="cl-8b00f992"><span class="cl-8affcb3b">48.54</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-8b010235"><p class="cl-8b00f992"><span class="cl-8affcb12">2009</span></p></td>
<td class="cl-8b010235"><p class="cl-8b00f992"><span class="cl-8affcb3c">37.41</span></p></td>
<td class="cl-8b010235"><p class="cl-8b00f992"><span class="cl-8affcb3d">40.56</span></p></td>
<td class="cl-8b010235"><p class="cl-8b00f992"><span class="cl-8affcb44">47.01</span></p></td>
<td class="cl-8b010235"><p class="cl-8b00f992"><span class="cl-8affcb45">51.10</span></p></td>
<td class="cl-8b010235"><p class="cl-8b00f992"><span class="cl-8affcb46">46.26</span></p></td>
<td class="cl-8b010235"><p class="cl-8b00f992"><span class="cl-8affcb1d">50.88</span></p></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="sourceCode" id="cb19" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/color.html">color</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scales</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://scales.r-lib.org/reference/col_numeric.html">col_bin</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>palette <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"viridis"</span>, domain <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, bins <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning: Some values were outside the color scale and will be treated as NA</code></pre>
</div>
<div class="cell-output-display">

<div class="tabwid">
<style>.cl-8b09f9f2{}.cl-8b067002{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-8b06700c{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(128, 128, 128, 1.00);background-color:transparent;}.cl-8b06700d{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(68, 1, 84, 1.00);background-color:transparent;}.cl-8b067016{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(33, 144, 141, 1.00);background-color:transparent;}.cl-8b067017{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(253, 231, 37, 1.00);background-color:transparent;}.cl-8b07b11a{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-8b07b11b{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-8b07b124{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-8b07ba02{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b07ba03{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b07ba0c{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b07ba0d{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b07ba0e{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b07ba16{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b07ba17{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style>
<table data-quarto-disable-processing="true" class="cl-8b09f9f2">
<thead>
<tr style="overflow-wrap:break-word;">
<th rowspan="2" class="cl-8b07ba02"><p class="cl-8b07b11a"><span class="cl-8b067002">year</span></p></th>
<th colspan="2" class="cl-8b07ba03"><p class="cl-8b07b11b"><span class="cl-8b067002">Adelie</span></p></th>
<th colspan="2" class="cl-8b07ba03"><p class="cl-8b07b11b"><span class="cl-8b067002">Chinstrap</span></p></th>
<th colspan="2" class="cl-8b07ba03"><p class="cl-8b07b11b"><span class="cl-8b067002">Gentoo</span></p></th>
</tr>
<tr style="overflow-wrap:break-word;">
<th class="cl-8b07ba0e"><p class="cl-8b07b124"><span class="cl-8b067002">female</span></p></th>
<th class="cl-8b07ba0e"><p class="cl-8b07b124"><span class="cl-8b067002">male</span></p></th>
<th class="cl-8b07ba0e"><p class="cl-8b07b124"><span class="cl-8b067002">female</span></p></th>
<th class="cl-8b07ba0e"><p class="cl-8b07b124"><span class="cl-8b067002">male</span></p></th>
<th class="cl-8b07ba0e"><p class="cl-8b07b124"><span class="cl-8b067002">female</span></p></th>
<th class="cl-8b07ba0e"><p class="cl-8b07b124"><span class="cl-8b067002">male</span></p></th>
</tr>
</thead>
<tbody>
<tr style="overflow-wrap:break-word;">
<td class="cl-8b07ba16"><p class="cl-8b07b124"><span class="cl-8b06700c">2007</span></p></td>
<td class="cl-8b07ba16"><p class="cl-8b07b124"><span class="cl-8b06700d">37.92</span></p></td>
<td class="cl-8b07ba16"><p class="cl-8b07b124"><span class="cl-8b06700d">39.95</span></p></td>
<td class="cl-8b07ba16"><p class="cl-8b07b124"><span class="cl-8b067016">46.57</span></p></td>
<td class="cl-8b07ba16"><p class="cl-8b07b124"><span class="cl-8b067017">50.88</span></p></td>
<td class="cl-8b07ba16"><p class="cl-8b07b124"><span class="cl-8b067016">45.06</span></p></td>
<td class="cl-8b07ba16"><p class="cl-8b07b124"><span class="cl-8b067016">49.00</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-8b07ba16"><p class="cl-8b07b124"><span class="cl-8b06700c">2008</span></p></td>
<td class="cl-8b07ba16"><p class="cl-8b07b124"><span class="cl-8b06700d">36.52</span></p></td>
<td class="cl-8b07ba16"><p class="cl-8b07b124"><span class="cl-8b067016">40.60</span></p></td>
<td class="cl-8b07ba16"><p class="cl-8b07b124"><span class="cl-8b067016">46.00</span></p></td>
<td class="cl-8b07ba16"><p class="cl-8b07b124"><span class="cl-8b067017">51.40</span></p></td>
<td class="cl-8b07ba16"><p class="cl-8b07b124"><span class="cl-8b067016">45.30</span></p></td>
<td class="cl-8b07ba16"><p class="cl-8b07b124"><span class="cl-8b067016">48.54</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-8b07ba17"><p class="cl-8b07b124"><span class="cl-8b06700c">2009</span></p></td>
<td class="cl-8b07ba17"><p class="cl-8b07b124"><span class="cl-8b06700d">37.41</span></p></td>
<td class="cl-8b07ba17"><p class="cl-8b07b124"><span class="cl-8b067016">40.56</span></p></td>
<td class="cl-8b07ba17"><p class="cl-8b07b124"><span class="cl-8b067016">47.01</span></p></td>
<td class="cl-8b07ba17"><p class="cl-8b07b124"><span class="cl-8b067017">51.10</span></p></td>
<td class="cl-8b07ba17"><p class="cl-8b07b124"><span class="cl-8b067016">46.26</span></p></td>
<td class="cl-8b07ba17"><p class="cl-8b07b124"><span class="cl-8b067017">50.88</span></p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>You can also select rows or columns with the <code>i</code> and <code>j</code> arguments, using formula syntax. To target rows, provide <code>i</code> with a formula to filter through the rows. Here we color in red rows for years greater than 2007:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-18_d1677b76b89cfa08237db81716401dad">
<div class="sourceCode" id="cb21" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/color.html">color</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">year</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2007</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">

<div class="tabwid">
<style>.cl-8b1f6422{}.cl-8b1c88ce{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-8b1c88d8{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(255, 0, 0, 1.00);background-color:transparent;}.cl-8b1da89e{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-8b1da8a8{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-8b1da8a9{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-8b1db10e{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b1db10f{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b1db118{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b1db119{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b1db11a{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b1db122{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b1db123{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style>
<table data-quarto-disable-processing="true" class="cl-8b1f6422">
<thead>
<tr style="overflow-wrap:break-word;">
<th rowspan="2" class="cl-8b1db10e"><p class="cl-8b1da89e"><span class="cl-8b1c88ce">year</span></p></th>
<th colspan="2" class="cl-8b1db10f"><p class="cl-8b1da8a8"><span class="cl-8b1c88ce">Adelie</span></p></th>
<th colspan="2" class="cl-8b1db10f"><p class="cl-8b1da8a8"><span class="cl-8b1c88ce">Chinstrap</span></p></th>
<th colspan="2" class="cl-8b1db10f"><p class="cl-8b1da8a8"><span class="cl-8b1c88ce">Gentoo</span></p></th>
</tr>
<tr style="overflow-wrap:break-word;">
<th class="cl-8b1db11a"><p class="cl-8b1da8a9"><span class="cl-8b1c88ce">female</span></p></th>
<th class="cl-8b1db11a"><p class="cl-8b1da8a9"><span class="cl-8b1c88ce">male</span></p></th>
<th class="cl-8b1db11a"><p class="cl-8b1da8a9"><span class="cl-8b1c88ce">female</span></p></th>
<th class="cl-8b1db11a"><p class="cl-8b1da8a9"><span class="cl-8b1c88ce">male</span></p></th>
<th class="cl-8b1db11a"><p class="cl-8b1da8a9"><span class="cl-8b1c88ce">female</span></p></th>
<th class="cl-8b1db11a"><p class="cl-8b1da8a9"><span class="cl-8b1c88ce">male</span></p></th>
</tr>
</thead>
<tbody>
<tr style="overflow-wrap:break-word;">
<td class="cl-8b1db122"><p class="cl-8b1da8a9"><span class="cl-8b1c88ce">2007</span></p></td>
<td class="cl-8b1db122"><p class="cl-8b1da8a9"><span class="cl-8b1c88ce">37.92</span></p></td>
<td class="cl-8b1db122"><p class="cl-8b1da8a9"><span class="cl-8b1c88ce">39.95</span></p></td>
<td class="cl-8b1db122"><p class="cl-8b1da8a9"><span class="cl-8b1c88ce">46.57</span></p></td>
<td class="cl-8b1db122"><p class="cl-8b1da8a9"><span class="cl-8b1c88ce">50.88</span></p></td>
<td class="cl-8b1db122"><p class="cl-8b1da8a9"><span class="cl-8b1c88ce">45.06</span></p></td>
<td class="cl-8b1db122"><p class="cl-8b1da8a9"><span class="cl-8b1c88ce">49.00</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-8b1db122"><p class="cl-8b1da8a9"><span class="cl-8b1c88d8">2008</span></p></td>
<td class="cl-8b1db122"><p class="cl-8b1da8a9"><span class="cl-8b1c88d8">36.52</span></p></td>
<td class="cl-8b1db122"><p class="cl-8b1da8a9"><span class="cl-8b1c88d8">40.60</span></p></td>
<td class="cl-8b1db122"><p class="cl-8b1da8a9"><span class="cl-8b1c88d8">46.00</span></p></td>
<td class="cl-8b1db122"><p class="cl-8b1da8a9"><span class="cl-8b1c88d8">51.40</span></p></td>
<td class="cl-8b1db122"><p class="cl-8b1da8a9"><span class="cl-8b1c88d8">45.30</span></p></td>
<td class="cl-8b1db122"><p class="cl-8b1da8a9"><span class="cl-8b1c88d8">48.54</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-8b1db123"><p class="cl-8b1da8a9"><span class="cl-8b1c88d8">2009</span></p></td>
<td class="cl-8b1db123"><p class="cl-8b1da8a9"><span class="cl-8b1c88d8">37.41</span></p></td>
<td class="cl-8b1db123"><p class="cl-8b1da8a9"><span class="cl-8b1c88d8">40.56</span></p></td>
<td class="cl-8b1db123"><p class="cl-8b1da8a9"><span class="cl-8b1c88d8">47.01</span></p></td>
<td class="cl-8b1db123"><p class="cl-8b1da8a9"><span class="cl-8b1c88d8">51.10</span></p></td>
<td class="cl-8b1db123"><p class="cl-8b1da8a9"><span class="cl-8b1c88d8">46.26</span></p></td>
<td class="cl-8b1db123"><p class="cl-8b1da8a9"><span class="cl-8b1c88d8">50.88</span></p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>You can restrict this to specific columns with the <code>j</code> argument:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-19_f1de822af156b78afc5c48bbd27b0bae">
<div class="sourceCode" id="cb22" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/color.html">color</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">year</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2007</span>, j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Adelie_female"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">

<div class="tabwid">
<style>.cl-8b2aca56{}.cl-8b27f650{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-8b27f65a{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(255, 0, 0, 1.00);background-color:transparent;}.cl-8b29106c{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-8b291076{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-8b291077{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-8b2918be{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b2918c8{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b2918c9{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(102, 102, 102, 1.00);border-top: 1.5pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b2918ca{width:0.75in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b2918d2{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b2918d3{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-8b2918d4{width:0.75in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style>
<table data-quarto-disable-processing="true" class="cl-8b2aca56">
<thead>
<tr style="overflow-wrap:break-word;">
<th rowspan="2" class="cl-8b2918be"><p class="cl-8b29106c"><span class="cl-8b27f650">year</span></p></th>
<th colspan="2" class="cl-8b2918c8"><p class="cl-8b291076"><span class="cl-8b27f650">Adelie</span></p></th>
<th colspan="2" class="cl-8b2918c8"><p class="cl-8b291076"><span class="cl-8b27f650">Chinstrap</span></p></th>
<th colspan="2" class="cl-8b2918c8"><p class="cl-8b291076"><span class="cl-8b27f650">Gentoo</span></p></th>
</tr>
<tr style="overflow-wrap:break-word;">
<th class="cl-8b2918d2"><p class="cl-8b291077"><span class="cl-8b27f650">female</span></p></th>
<th class="cl-8b2918d2"><p class="cl-8b291077"><span class="cl-8b27f650">male</span></p></th>
<th class="cl-8b2918d2"><p class="cl-8b291077"><span class="cl-8b27f650">female</span></p></th>
<th class="cl-8b2918d2"><p class="cl-8b291077"><span class="cl-8b27f650">male</span></p></th>
<th class="cl-8b2918d2"><p class="cl-8b291077"><span class="cl-8b27f650">female</span></p></th>
<th class="cl-8b2918d2"><p class="cl-8b291077"><span class="cl-8b27f650">male</span></p></th>
</tr>
</thead>
<tbody>
<tr style="overflow-wrap:break-word;">
<td class="cl-8b2918d3"><p class="cl-8b291077"><span class="cl-8b27f650">2007</span></p></td>
<td class="cl-8b2918d3"><p class="cl-8b291077"><span class="cl-8b27f650">37.92</span></p></td>
<td class="cl-8b2918d3"><p class="cl-8b291077"><span class="cl-8b27f650">39.95</span></p></td>
<td class="cl-8b2918d3"><p class="cl-8b291077"><span class="cl-8b27f650">46.57</span></p></td>
<td class="cl-8b2918d3"><p class="cl-8b291077"><span class="cl-8b27f650">50.88</span></p></td>
<td class="cl-8b2918d3"><p class="cl-8b291077"><span class="cl-8b27f650">45.06</span></p></td>
<td class="cl-8b2918d3"><p class="cl-8b291077"><span class="cl-8b27f650">49.00</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-8b2918d3"><p class="cl-8b291077"><span class="cl-8b27f65a">2008</span></p></td>
<td class="cl-8b2918d3"><p class="cl-8b291077"><span class="cl-8b27f65a">36.52</span></p></td>
<td class="cl-8b2918d3"><p class="cl-8b291077"><span class="cl-8b27f650">40.60</span></p></td>
<td class="cl-8b2918d3"><p class="cl-8b291077"><span class="cl-8b27f650">46.00</span></p></td>
<td class="cl-8b2918d3"><p class="cl-8b291077"><span class="cl-8b27f650">51.40</span></p></td>
<td class="cl-8b2918d3"><p class="cl-8b291077"><span class="cl-8b27f650">45.30</span></p></td>
<td class="cl-8b2918d3"><p class="cl-8b291077"><span class="cl-8b27f650">48.54</span></p></td>
</tr>
<tr style="overflow-wrap:break-word;">
<td class="cl-8b2918d4"><p class="cl-8b291077"><span class="cl-8b27f65a">2009</span></p></td>
<td class="cl-8b2918d4"><p class="cl-8b291077"><span class="cl-8b27f65a">37.41</span></p></td>
<td class="cl-8b2918d4"><p class="cl-8b291077"><span class="cl-8b27f650">40.56</span></p></td>
<td class="cl-8b2918d4"><p class="cl-8b291077"><span class="cl-8b27f650">47.01</span></p></td>
<td class="cl-8b2918d4"><p class="cl-8b291077"><span class="cl-8b27f650">51.10</span></p></td>
<td class="cl-8b2918d4"><p class="cl-8b291077"><span class="cl-8b27f650">46.26</span></p></td>
<td class="cl-8b2918d4"><p class="cl-8b291077"><span class="cl-8b27f650">50.88</span></p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section><section id="getting-flextables-into-word" class="level3"><h3 class="anchored" data-anchor-id="getting-flextables-into-word">Getting <code>flextable</code>s into Word</h3>
<p>There are three main ways to get a <code>flextable</code> into Word: open a temporary preview file that you can copy from with <code>print(preview = "docx")</code>, save to a Word file with <code><a href="https://davidgohel.github.io/flextable/reference/save_as_docx.html">save_as_docx()</a></code>, or insert into an existing Word document with the <code>officer</code> package.</p>
<section id="temporary-word-file" class="level4"><h4 class="anchored" data-anchor-id="temporary-word-file">Temporary Word file</h4>
<p>This is probably the easiest method. The following code opens a new temporary document in Word (assuming it’s installed on your computer) that contains the <code>flextable</code> object.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-20_b72233f92727c34570515ce90c53616a">
<div class="sourceCode" id="cb23" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/print.html">print</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>preview <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"docx"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</div>
<p>That’s it! You can now copy and paste that table wherever you need. NB: this creates a <em>temporary file</em> which will be deleted when your R session closes, so save any output you want in a separate document.</p>
</section><section id="save-to-a-new-word-file" class="level4"><h4 class="anchored" data-anchor-id="save-to-a-new-word-file">Save to a new Word file</h4>
<p><code>save_as_docx</code> will do as the name suggests—insert the <code>flextable</code> into a new .docx file whose location you specify:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-21_0315c8fcb2723853bd262339c6869ee3">
<div class="sourceCode" id="cb24" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/save_as_docx.html">save_as_docx</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>path <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"penguin_table.docx"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># I find it necessary to explicitly name the path argument</span></span></code></pre></div>
</div>
</section><section id="import-into-an-existing-word-file." class="level4"><h4 class="anchored" data-anchor-id="import-into-an-existing-word-file.">Import into an existing Word file.</h4>
<p>The package <code>officer</code> lets you read a Word document into R, manipulate it, and save it again with any additions or changes.</p>
<p>Read in an existing Word document with <code><a href="https://davidgohel.github.io/officer/reference/read_docx.html">officer::read_docx()</a></code>. Here I’ll read the <code>penguin_table.docx</code> document we created above.:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-22_1755dd840246a6502c2e60d118527343">
<div class="sourceCode" id="cb25" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_doc</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">officer</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/officer/reference/read_docx.html">read_docx</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"penguin_table.docx"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</div>
<p>Now add your <code>flextable</code> with <code><a href="https://davidgohel.github.io/flextable/reference/body_add_flextable.html">flextable::body_add_flextable()</a></code>:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-23_b3faecde7a49e3a93f63b78dacee4cab">
<div class="sourceCode" id="cb26" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_doc</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flextable</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/flextable/reference/body_add_flextable.html">body_add_flextable</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_doc</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_flextable_4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</div>
<p>And finally, save this Word object as a Word document:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-24_cfa46f028034ebad593f7092463786ff">
<div class="sourceCode" id="cb27" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguin_doc</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/print.html">print</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>target <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"penguin_table.docx"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</div>
</section></section></section><section id="conclusion" class="level2"><h2 class="anchored" data-anchor-id="conclusion">Conclusion</h2>
<p>That’s it! <code>flextable</code> has a bunch more functionality, but these are the things I find myself using regularly. Check out <a href="https://davidgohel.github.io/flextable/">the <code>flextable</code> page</a> or <a href="https://ardata-fr.github.io/flextable-book/">the <code>flextable</code> book</a> (free online).</p>
<!-- End content -->
<div id="footer-session-info">
<details><summary>
Session info and package versions
</summary><div class="cell" data-hash="index_cache/html/unnamed-chunk-26_dfcf0a79facc89701596347f92e73150">
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code> setting  value
 version  R version 4.4.0 (2024-04-24)
 os       macOS Sonoma 14.4.1
 system   aarch64, darwin20
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Chicago
 date     2024-05-17
 pandoc   3.2 @ /opt/homebrew/bin/ (via rmarkdown)</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Packages ───────────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>           package loadedversion       date         source
           askpass         1.2.0 2023-09-03 CRAN (R 4.4.0)
               cli         3.6.2 2023-12-11 CRAN (R 4.4.0)
         codetools        0.2-20 2024-03-31 CRAN (R 4.4.0)
        colorspace         2.1-0 2023-01-23 CRAN (R 4.4.0)
            crayon         1.5.2 2022-09-29 CRAN (R 4.4.0)
              crul         1.4.2 2024-04-09 CRAN (R 4.4.0)
              curl         5.2.1 2024-03-01 CRAN (R 4.4.0)
        data.table        1.15.4 2024-03-30 CRAN (R 4.4.0)
            digest        0.6.35 2024-03-11 CRAN (R 4.4.0)
             dplyr         1.1.4 2023-11-17 CRAN (R 4.4.0)
          evaluate          0.23 2023-11-01 CRAN (R 4.4.0)
             fansi         1.0.6 2023-12-08 CRAN (R 4.4.0)
           fastmap         1.1.1 2023-02-24 CRAN (R 4.4.0)
         flextable         0.9.6 2024-05-05 CRAN (R 4.4.0)
 fontBitstreamVera         0.1.1 2017-02-01 CRAN (R 4.4.0)
    fontLiberation         0.1.0 2016-10-15 CRAN (R 4.4.0)
        fontquiver         0.2.1 2017-02-01 CRAN (R 4.4.0)
           forcats         1.0.0 2023-01-29 CRAN (R 4.4.0)
           gdtools         0.3.7 2024-03-05 CRAN (R 4.4.0)
          generics         0.1.3 2022-07-05 CRAN (R 4.4.0)
            gfonts         0.2.0 2023-01-08 CRAN (R 4.4.0)
           ggplot2         3.5.1 2024-04-23 CRAN (R 4.4.0)
              glue         1.7.0 2024-01-09 CRAN (R 4.4.0)
                gt        0.10.1 2024-01-17 CRAN (R 4.4.0)
            gtable         0.3.5 2024-04-22 CRAN (R 4.4.0)
               hms         1.1.3 2023-03-21 CRAN (R 4.4.0)
         htmltools       0.5.8.1 2024-04-04 CRAN (R 4.4.0)
       htmlwidgets         1.6.4 2023-12-06 CRAN (R 4.4.0)
          httpcode         0.3.0 2020-04-10 CRAN (R 4.4.0)
            httpuv        1.6.15 2024-03-26 CRAN (R 4.4.0)
          jsonlite         1.8.8 2023-12-04 CRAN (R 4.4.0)
             knitr          1.46 2024-04-06 CRAN (R 4.4.0)
             later         1.3.2 2023-12-06 CRAN (R 4.4.0)
         lifecycle         1.0.4 2023-11-07 CRAN (R 4.4.0)
         lubridate         1.9.3 2023-09-27 CRAN (R 4.4.0)
          magrittr         2.0.3 2022-03-30 CRAN (R 4.4.0)
              mime          0.12 2021-09-28 CRAN (R 4.4.0)
           munsell         0.5.1 2024-04-01 CRAN (R 4.4.0)
           officer         0.6.6 2024-05-05 CRAN (R 4.4.0)
           openssl         2.1.2 2024-04-21 CRAN (R 4.4.0)
    palmerpenguins         0.1.1 2022-08-15 CRAN (R 4.4.0)
            pillar         1.9.0 2023-03-22 CRAN (R 4.4.0)
         pkgconfig         2.0.3 2019-09-22 CRAN (R 4.4.0)
          promises         1.3.0 2024-04-05 CRAN (R 4.4.0)
             purrr         1.0.2 2023-08-10 CRAN (R 4.4.0)
                R6         2.5.1 2021-08-19 CRAN (R 4.4.0)
              ragg         1.3.1 2024-05-06 CRAN (R 4.4.0)
              Rcpp        1.0.12 2024-01-09 CRAN (R 4.4.0)
             readr         2.1.5 2024-01-10 CRAN (R 4.4.0)
              renv        0.17.3 2023-04-06 CRAN (R 4.4.0)
             rlang         1.1.3 2024-01-10 CRAN (R 4.4.0)
         rmarkdown          2.26 2024-03-05 CRAN (R 4.4.0)
        rstudioapi        0.16.0 2024-03-24 CRAN (R 4.4.0)
            scales         1.3.0 2023-11-28 CRAN (R 4.4.0)
       sessioninfo         1.2.2 2021-12-06 CRAN (R 4.4.0)
             shiny       1.8.1.1 2024-04-02 CRAN (R 4.4.0)
           stringi         1.8.4 2024-05-06 CRAN (R 4.4.0)
           stringr         1.5.1 2023-11-14 CRAN (R 4.4.0)
       systemfonts         1.0.6 2024-03-07 CRAN (R 4.4.0)
       textshaping         0.3.7 2023-10-09 CRAN (R 4.4.0)
            tibble         3.2.1 2023-03-20 CRAN (R 4.4.0)
             tidyr         1.3.1 2024-01-24 CRAN (R 4.4.0)
        tidyselect         1.2.1 2024-03-11 CRAN (R 4.4.0)
         tidyverse         2.0.0 2023-02-22 CRAN (R 4.4.0)
        timechange         0.3.0 2024-01-18 CRAN (R 4.4.0)
              tzdb         0.4.0 2023-05-12 CRAN (R 4.4.0)
              utf8         1.2.4 2023-10-22 CRAN (R 4.4.0)
              uuid         1.2-0 2024-01-14 CRAN (R 4.4.0)
             vctrs         0.6.5 2023-12-01 CRAN (R 4.4.0)
             withr         3.0.0 2024-01-16 CRAN (R 4.4.0)
              xfun          0.43 2024-03-25 CRAN (R 4.4.0)
              xml2         1.3.6 2023-12-04 CRAN (R 4.4.0)
            xtable         1.8-4 2019-04-21 CRAN (R 4.4.0)
              yaml         2.3.8 2023-12-11 CRAN (R 4.4.0)
               zip         2.3.1 2024-01-27 CRAN (R 4.4.0)</code></pre>
</div>
</div>
</details>
</div>


</section><div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>
<ol>
<li id="fn1"><p>If you’re reading this some time in the future, it might be worth checking that issue to see if it’s been resolved.↩︎</p></li>
</ol></section></div> ]]></description>
  <category>tables</category>
  <guid>https://abraver.github.io/usefulRstuff/posts/tables_for_word_flextable/index.html</guid>
  <pubDate>Fri, 17 May 2024 05:00:00 GMT</pubDate>
</item>
<item>
  <title>Sort numbered strings (or factor levels, or filenames) correctly even without zero-padding</title>
  <dc:creator>Aaron Braver</dc:creator>
  <link>https://abraver.github.io/usefulRstuff/posts/naturalsort/index.html</link>
  <description><![CDATA[ <script src="../../jquery-3.7.0.min.js"></script><script src="../../fold.js"></script><script src="../../move_session_info.js"></script><!-- begin content --><div class="cell" data-hash="index_cache/html/setup_f406cc97a1aa210701afcdb775ee775a">
<details><summary>Setup</summary><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://tidyverse.tidyverse.org">tidyverse</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">naturalsort</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</details>
</div>
<p>It’s quite common to see lists of items (data, files, etc) that are numbered, such as the hypothetical list of files below:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-2_bd9dd4dbb3bfff83779d3ac5a56dbdc6">
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">filenames</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"file2.csv"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"file1.csv"</span>,  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"file3.csv"</span>,</span>
<span>               <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"file11.csv"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"file10.csv"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"file20.csv"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/print.html">print</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">filenames</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "file2.csv"  "file1.csv"  "file3.csv"  "file11.csv" "file10.csv"
[6] "file20.csv"</code></pre>
</div>
</div>
<p>If you want to <code>sort</code> these by number, you run into a problem, since the filenames are strings: <code>1</code> is followed by <code>10</code>, which is followed by <code>2</code>, since <code>10</code> precedes <code>2</code> “alphabetically”:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-3_041c9c0d4b41f8bc3fab0cf3149e0567">
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">filenames</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/sort.html">sort</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "file1.csv"  "file10.csv" "file11.csv" "file2.csv"  "file20.csv"
[6] "file3.csv" </code></pre>
</div>
</div>
<p>One solution is to rename your items such that they are zero-padded. A kludge with <code>stringr</code>’s <code><a href="https://stringr.tidyverse.org/reference/str_replace.html">str_replace()</a></code>and<code><a href="https://stringr.tidyverse.org/reference/str_pad.html">str_pad()</a></code>can get the job done. Because of the leading zeros,<code><a href="https://rdrr.io/r/base/sort.html">sort()</a></code> will get the result you expect:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-4_0b4ad8819d1e1b35e8d6a984bcca9a93">
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">padded</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://stringr.tidyverse.org/reference/str_replace.html">str_replace</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">filenames</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"[0-9]+"</span>, \<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://stringr.tidyverse.org/reference/str_pad.html">str_pad</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, pad<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">padded</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/sort.html">sort</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "file01.csv" "file02.csv" "file03.csv" "file10.csv" "file11.csv"
[6] "file20.csv"</code></pre>
</div>
</div>
<p>Rather than renaming your items, <code><a href="https://rdrr.io/pkg/naturalsort/man/naturalsort.html">naturalsort::naturalsort()</a></code> orders your items in “human natural” order:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-5_0ca3619554f2ea02482c4f4aca9499f4">
<div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">filenames</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">naturalsort</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/naturalsort/man/naturalsort.html">naturalsort</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "file1.csv"  "file2.csv"  "file3.csv"  "file10.csv" "file11.csv"
[6] "file20.csv"</code></pre>
</div>
</div>
<p>The <code>naturalsort</code> package also comes with the command <code><a href="https://rdrr.io/pkg/naturalsort/man/naturalfactor.html">naturalfactor()</a></code>, which can reorder a factor in the same way, or turn an unordered list of strings into a factor:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-6_02ca9ab89d76ed58f675613caba487ab">
<div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">my_factor</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/factor.html">factor</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"level_1"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"level_10"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"level_2"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">naturalsort</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/naturalsort/man/naturalfactor.html">naturalfactor</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">my_factor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] level_1  level_10 level_2 
Levels: level_1 &lt; level_2 &lt; level_10</code></pre>
</div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-7_cace4774e7df13b8b92442d44f676478">
<div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"level1"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"level10"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"level2"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/naturalsort/man/naturalfactor.html">naturalfactor</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] level1  level10 level2 
Levels: level1 &lt; level2 &lt; level10</code></pre>
</div>
</div>
<!-- End content -->
<div id="footer-session-info">
<details><summary>
Session info and package versions
</summary><div class="cell" data-hash="index_cache/html/unnamed-chunk-9_e9175bd67460e15c5615e5268fb63de0">
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code> setting  value
 version  R version 4.3.2 (2023-10-31)
 os       macOS Sonoma 14.2.1
 system   aarch64, darwin20
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Chicago
 date     2024-01-12
 pandoc   3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Packages ───────────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>     package loadedversion       date         source
         cli         3.6.1 2023-03-23 CRAN (R 4.3.2)
   codetools        0.2-19 2023-02-01 CRAN (R 4.3.2)
  colorspace         2.1-0 2023-01-23 CRAN (R 4.3.0)
      digest        0.6.31 2022-12-11 CRAN (R 4.3.0)
       dplyr         1.1.2 2023-04-20 CRAN (R 4.3.2)
    evaluate          0.21 2023-05-05 CRAN (R 4.3.2)
       fansi         1.0.4 2023-01-22 CRAN (R 4.3.2)
     fastmap         1.1.1 2023-02-24 CRAN (R 4.3.0)
     forcats         1.0.0 2023-01-29 CRAN (R 4.3.0)
    generics         0.1.3 2022-07-05 CRAN (R 4.3.0)
     ggplot2         3.4.2 2023-04-03 CRAN (R 4.3.2)
        glue         1.6.2 2022-02-24 CRAN (R 4.3.2)
      gtable         0.3.3 2023-03-21 CRAN (R 4.3.2)
         hms         1.1.3 2023-03-21 CRAN (R 4.3.0)
   htmltools         0.5.7 2023-11-03 CRAN (R 4.3.1)
 htmlwidgets         1.6.2 2023-03-17 CRAN (R 4.3.2)
    jsonlite         1.8.8 2023-12-04 CRAN (R 4.3.1)
       knitr          1.43 2023-05-25 CRAN (R 4.3.2)
   lifecycle         1.0.3 2022-10-07 CRAN (R 4.3.2)
   lubridate         1.9.2 2023-02-10 CRAN (R 4.3.2)
    magrittr         2.0.3 2022-03-30 CRAN (R 4.3.0)
     munsell         0.5.0 2018-06-12 CRAN (R 4.3.0)
 naturalsort         0.1.3 2016-08-30 CRAN (R 4.3.0)
      pillar         1.9.0 2023-03-22 CRAN (R 4.3.0)
   pkgconfig         2.0.3 2019-09-22 CRAN (R 4.3.0)
       purrr         1.0.1 2023-01-10 CRAN (R 4.3.2)
          R6         2.5.1 2021-08-19 CRAN (R 4.3.0)
        ragg         1.2.5 2023-01-12 CRAN (R 4.3.2)
       readr         2.1.4 2023-02-10 CRAN (R 4.3.2)
        renv        0.17.3 2023-04-06 CRAN (R 4.3.0)
       rlang         1.1.1 2023-04-28 CRAN (R 4.3.2)
   rmarkdown          2.21 2023-03-26 CRAN (R 4.3.2)
  rstudioapi          0.14 2022-08-22 CRAN (R 4.3.2)
      scales         1.2.1 2022-08-20 CRAN (R 4.3.2)
 sessioninfo         1.2.2 2021-12-06 CRAN (R 4.3.0)
     stringi        1.7.12 2023-01-11 CRAN (R 4.3.2)
     stringr         1.5.0 2022-12-02 CRAN (R 4.3.2)
 systemfonts         1.0.4 2022-02-11 CRAN (R 4.3.2)
 textshaping         0.3.6 2021-10-13 CRAN (R 4.3.2)
      tibble         3.2.1 2023-03-20 CRAN (R 4.3.0)
       tidyr         1.3.0 2023-01-24 CRAN (R 4.3.0)
  tidyselect         1.2.0 2022-10-10 CRAN (R 4.3.0)
   tidyverse         2.0.0 2023-02-22 CRAN (R 4.3.0)
  timechange         0.2.0 2023-01-11 CRAN (R 4.3.0)
        tzdb         0.4.0 2023-05-12 CRAN (R 4.3.0)
        utf8         1.2.3 2023-01-31 CRAN (R 4.3.2)
       vctrs         0.6.2 2023-04-19 CRAN (R 4.3.2)
       withr         2.5.0 2022-03-03 CRAN (R 4.3.2)
        xfun          0.39 2023-04-20 CRAN (R 4.3.2)
        yaml         2.3.7 2023-01-23 CRAN (R 4.3.2)</code></pre>
</div>
</div>
</details>
</div>



 ]]></description>
  <category>data cleaning</category>
  <category>sorting</category>
  <guid>https://abraver.github.io/usefulRstuff/posts/naturalsort/index.html</guid>
  <pubDate>Fri, 12 Jan 2024 06:00:00 GMT</pubDate>
</item>
<item>
  <title>View the structure of deeply nested objects or complex function calls with lobstr and listviewer
</title>
  <dc:creator>Aaron Braver</dc:creator>
  <link>https://abraver.github.io/usefulRstuff/posts/lobstr/index.html</link>
  <description><![CDATA[ <script src="../../jquery-3.7.0.min.js"></script><script src="../../fold.js"></script><script src="../../move_session_info.js"></script><div class="cell" data-hash="index_cache/html/unnamed-chunk-2_8d15c2dbbec57d32db3fa8103cbc00c1">
<style type="text/css">
.scroll::-webkit-scrollbar {
    -webkit-appearance: none;
}

.scroll::-webkit-scrollbar:vertical {
    width: 12px;
}


.scroll::-webkit-scrollbar-thumb {
    border-radius: 8px;
    border: 2px solid white; /* should match background, can't be transparent */
    background-color: rgba(0, 0, 0, .5);
}
</style>
</div>
<!-- begin content -->
<p>When working with deeply nested structures (either objects or function calls), sometimes it’s helpful to visualize what you’re working with. The <code>lobstr</code> package provides functions for viewing these structures in an easy-to-read way—I find it more intuitive to parse than <code><a href="https://rdrr.io/r/utils/str.html">str()</a></code>.</p>
<p>If you’re using RStudio you can, of course, use the viewer with <code><a href="https://rdrr.io/r/utils/View.html">View()</a></code>, but that works best for purely rectangular data with no hierarchical structure.</p>
<section id="tree-structure-for-nested-dataframes" class="level2"><h2 class="anchored" data-anchor-id="tree-structure-for-nested-dataframes">Tree structure for (nested) dataframes</h2>
<section id="lobstrtree" class="level3"><h3 class="anchored" data-anchor-id="lobstrtree"><code>lobstr::tree()</code></h3>
<p><code><a href="https://lobstr.r-lib.org/reference/tree.html">lobstr::tree()</a></code> provides a tree structure for data structures, and is particularly useful when you have nested structures.</p>
<p>We’ll start with the a subset of the <code>mpg</code> data provided in <code>ggplot2</code>. We nest by <code>cyl</code>, and then call <code><a href="https://lobstr.r-lib.org/reference/tree.html">tree()</a></code>, resulting in a handy representation of the structure (scroll to see full output).</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-3_6c2e414378f10c7f1a084ac3a8cbff5a">
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://tidyverse.tidyverse.org">tidyverse</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://lobstr.r-lib.org/">lobstr</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">mpg_subset</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span>  <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">mpg</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">class</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">cyl</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">manufacturer</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">hwy</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">cty</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">mpg_subset</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://tidyr.tidyverse.org/reference/nest.html">nest</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>.by <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">cyl</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lobstr</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://lobstr.r-lib.org/reference/tree.html">tree</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>S3&lt;tbl_df/tbl/data.frame&gt;
├─cyl&lt;int [4]&gt;: 4, 6, 8, 5
└─data: &lt;list&gt;
  ├─S3&lt;tbl_df/tbl/data.frame&gt;
  │ ├─class&lt;chr [81]&gt;: "compact", "compact", "compact", "compact", "compact", "compact", "compact", "compact", "midsize", "midsize", ...
  │ ├─manufacturer&lt;chr [81]&gt;: "audi", "audi", "audi", "audi", "audi", "audi", "audi", "audi", "chevrolet", "chevrolet", ...
  │ ├─hwy&lt;int [81]&gt;: 29, 29, 31, 30, 26, 25, 28, 27, 27, 30, ...
  │ └─cty&lt;int [81]&gt;: 18, 21, 20, 21, 18, 16, 20, 19, 19, 22, ...
  ├─S3&lt;tbl_df/tbl/data.frame&gt;
  │ ├─class&lt;chr [79]&gt;: "compact", "compact", "compact", "compact", "compact", "compact", "compact", "midsize", "midsize", "midsize", ...
  │ ├─manufacturer&lt;chr [79]&gt;: "audi", "audi", "audi", "audi", "audi", "audi", "audi", "audi", "audi", "chevrolet", ...
  │ ├─hwy&lt;int [79]&gt;: 26, 26, 27, 25, 25, 25, 25, 24, 25, 26, ...
  │ └─cty&lt;int [79]&gt;: 16, 18, 18, 15, 17, 17, 15, 15, 17, 18, ...
  ├─S3&lt;tbl_df/tbl/data.frame&gt;
  │ ├─class&lt;chr [70]&gt;: "midsize", "suv", "suv", "suv", "suv", "suv", "2seater", "2seater", "2seater", "2seater", ...
  │ ├─manufacturer&lt;chr [70]&gt;: "audi", "chevrolet", "chevrolet", "chevrolet", "chevrolet", "chevrolet", "chevrolet", "chevrolet", "chevrolet", "chevrolet", ...
  │ ├─hwy&lt;int [70]&gt;: 23, 20, 15, 20, 17, 17, 26, 23, 26, 25, ...
  │ └─cty&lt;int [70]&gt;: 16, 14, 11, 14, 13, 12, 16, 15, 16, 15, ...
  └─S3&lt;tbl_df/tbl/data.frame&gt;
    ├─class&lt;chr [4]&gt;: "compact", "compact", "subcompact", "subcompact"
    ├─manufacturer&lt;chr [4]&gt;: "volkswagen", "volkswagen", "volkswagen", "volkswagen"
    ├─hwy&lt;int [4]&gt;: 29, 29, 28, 29
    └─cty&lt;int [4]&gt;: 21, 21, 20, 20</code></pre>
</div>
</div>
<p>This works for multiply-nested objects as well—here we nest the <code>mpg</code> dataset by <code>cyl</code> and by <code>class</code>:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-4_441cbff49aba681cb1a1c5db6e1961d9">
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">mpg_subset</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://tidyr.tidyverse.org/reference/nest.html">nest</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>.by <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">cyl</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">class</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://tidyr.tidyverse.org/reference/nest.html">nest</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>.by <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">class</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/utils/head.html">head</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://lobstr.r-lib.org/reference/tree.html">tree</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>S3&lt;tbl_df/tbl/data.frame&gt;
├─class&lt;chr [2]&gt;: "compact", "midsize"
└─data: &lt;list&gt;
  ├─S3&lt;tbl_df/tbl/data.frame&gt;
  │ ├─cyl&lt;int [3]&gt;: 4, 6, 5
  │ └─data: &lt;list&gt;
  │   ├─S3&lt;tbl_df/tbl/data.frame&gt;
  │   │ ├─manufacturer&lt;chr [32]&gt;: "audi", "audi", "audi", "audi", "audi", "audi", "audi", "audi", "nissan", "nissan", ...
  │   │ ├─hwy&lt;int [32]&gt;: 29, 29, 31, 30, 26, 25, 28, 27, 29, 27, ...
  │   │ └─cty&lt;int [32]&gt;: 18, 21, 20, 21, 18, 16, 20, 19, 21, 19, ...
  │   ├─S3&lt;tbl_df/tbl/data.frame&gt;
  │   │ ├─manufacturer&lt;chr [13]&gt;: "audi", "audi", "audi", "audi", "audi", "audi", "audi", "toyota", "toyota", "toyota", ...
  │   │ ├─hwy&lt;int [13]&gt;: 26, 26, 27, 25, 25, 25, 25, 26, 26, 27, ...
  │   │ └─cty&lt;int [13]&gt;: 16, 18, 18, 15, 17, 17, 15, 18, 18, 18, ...
  │   └─S3&lt;tbl_df/tbl/data.frame&gt;
  │     ├─manufacturer&lt;chr [2]&gt;: "volkswagen", "volkswagen"
  │     ├─hwy&lt;int [2]&gt;: 29, 29
  │     └─cty&lt;int [2]&gt;: 21, 21
  └─S3&lt;tbl_df/tbl/data.frame&gt;
    ├─cyl&lt;int [3]&gt;: 6, 8, 4
    └─data: &lt;list&gt;
      ├─S3&lt;tbl_df/tbl/data.frame&gt;
      │ ├─manufacturer&lt;chr [23]&gt;: "audi", "audi", "chevrolet", "chevrolet", "chevrolet", "hyundai", "hyundai", "hyundai", "nissan", "nissan", ...
      │ ├─hwy&lt;int [23]&gt;: 24, 25, 26, 29, 26, 26, 26, 28, 27, 26, ...
      │ └─cty&lt;int [23]&gt;: 15, 17, 18, 18, 17, 18, 18, 19, 19, 19, ...
      ├─S3&lt;tbl_df/tbl/data.frame&gt;
      │ ├─manufacturer&lt;chr [2]&gt;: "audi", "pontiac"
      │ ├─hwy&lt;int [2]&gt;: 23, 25
      │ └─cty&lt;int [2]&gt;: 16, 16
      └─S3&lt;tbl_df/tbl/data.frame&gt;
        ├─manufacturer&lt;chr [16]&gt;: "chevrolet", "chevrolet", "hyundai", "hyundai", "hyundai", "hyundai", "nissan", "nissan", "toyota", "toyota", ...
        ├─hwy&lt;int [16]&gt;: 27, 30, 26, 27, 30, 31, 31, 32, 29, 27, ...
        └─cty&lt;int [16]&gt;: 19, 22, 18, 18, 21, 21, 23, 23, 21, 21, ...</code></pre>
</div>
</div>
<p>If the output is a bit overwhelming with all of the values being printed, you can specify the <code>val_printer</code> argument—here we give it an empty anonymous function so that no values are printed. This helps to see the structure a little bit more clearly:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-5_e1d3c9ff4026f154350a1fb4d129b71d">
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">mpg_subset</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://tidyr.tidyverse.org/reference/nest.html">nest</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>.by <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">cyl</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">class</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://tidyr.tidyverse.org/reference/nest.html">nest</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>.by <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">class</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/utils/head.html">head</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://lobstr.r-lib.org/reference/tree.html">tree</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>val_printer <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> \<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>S3&lt;tbl_df/tbl/data.frame&gt;
├─class&lt;chr [2]&gt;: 
└─data: &lt;list&gt;
  ├─S3&lt;tbl_df/tbl/data.frame&gt;
  │ ├─cyl&lt;int [3]&gt;: 
  │ └─data: &lt;list&gt;
  │   ├─S3&lt;tbl_df/tbl/data.frame&gt;
  │   │ ├─manufacturer&lt;chr [32]&gt;: 
  │   │ ├─hwy&lt;int [32]&gt;: 
  │   │ └─cty&lt;int [32]&gt;: 
  │   ├─S3&lt;tbl_df/tbl/data.frame&gt;
  │   │ ├─manufacturer&lt;chr [13]&gt;: 
  │   │ ├─hwy&lt;int [13]&gt;: 
  │   │ └─cty&lt;int [13]&gt;: 
  │   └─S3&lt;tbl_df/tbl/data.frame&gt;
  │     ├─manufacturer&lt;chr [2]&gt;: 
  │     ├─hwy&lt;int [2]&gt;: 
  │     └─cty&lt;int [2]&gt;: 
  └─S3&lt;tbl_df/tbl/data.frame&gt;
    ├─cyl&lt;int [3]&gt;: 
    └─data: &lt;list&gt;
      ├─S3&lt;tbl_df/tbl/data.frame&gt;
      │ ├─manufacturer&lt;chr [23]&gt;: 
      │ ├─hwy&lt;int [23]&gt;: 
      │ └─cty&lt;int [23]&gt;: 
      ├─S3&lt;tbl_df/tbl/data.frame&gt;
      │ ├─manufacturer&lt;chr [2]&gt;: 
      │ ├─hwy&lt;int [2]&gt;: 
      │ └─cty&lt;int [2]&gt;: 
      └─S3&lt;tbl_df/tbl/data.frame&gt;
        ├─manufacturer&lt;chr [16]&gt;: 
        ├─hwy&lt;int [16]&gt;: 
        └─cty&lt;int [16]&gt;: </code></pre>
</div>
</div>
<p><code>tree</code> is also handy for list-columns that have complex objects like models:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-6_820d10137a6a6e90bf12d36db2f43680">
<div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">mpg_subset</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://tidyr.tidyverse.org/reference/nest.html">nest</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>.by <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">class</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/utils/head.html">head</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Get a subset of the data so output is manageable</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://purrr.tidyverse.org/reference/map.html">map</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">data</span>, \<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/stats/lm.html">lm</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">cty</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">manufacturer</span>, data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://lobstr.r-lib.org/reference/tree.html">tree</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>S3&lt;tbl_df/tbl/data.frame&gt;
├─class&lt;chr [2]&gt;: "compact", "midsize"
└─data: &lt;list&gt;
  ├─S3&lt;lm&gt;
  │ ├─coefficients&lt;dbl [5]&gt;: 17.9333333333333, 2.06666666666666, 1.81666666666667, 4.31666666666667, 2.85238095238095
  │ ├─residuals&lt;dbl [47]&gt;: 0.066666666666665, 3.06666666666667, 2.06666666666666, 3.06666666666667, -1.93333333333334, 0.0666666666666665, 0.0666666666666665, 0.0666666666666665, -1.93333333333333, 2.06666666666667, ...
  │ ├─effects&lt;dbl [47]&gt;: -137.988281957008, -0.184506241605778, -0.803194840135016, 8.56434361157096, 7.67570324864425, -0.0407824196725389, -0.0407824196725389, -0.0407824196725389, -2.04078241967254, 1.95921758032746, ...
  │ ├─rank: 5
  │ ├─fitted.values&lt;dbl [47]&gt;: 17.9333333333333, 17.9333333333333, 17.9333333333333, 17.9333333333333, 17.9333333333333, 17.9333333333333, 17.9333333333333, 17.9333333333333, 17.9333333333333, 17.9333333333333, ...
  │ ├─assign&lt;int [5]&gt;: 0, 1, 1, 1, 1
  │ ├─qr: S3&lt;qr&gt;
  │ │ ├─qr&lt;dbl [235]&gt;: -6.85565460040104, 0.145864991497895, 0.145864991497895, 0.145864991497895, 0.145864991497895, 0.145864991497895, 0.145864991497895, 0.145864991497895, 0.145864991497895, 0.145864991497895, ...
  │ │ ├─qraux&lt;dbl [5]&gt;: 1.14586499149789, 1.02683653004132, 1.03957282449068, 1.08213154946517, 1.13553443533542
  │ │ ├─pivot&lt;int [5]&gt;: 1, 2, 3, 4, 5
  │ │ ├─tol: 1e-07
  │ │ └─rank: 5
  │ ├─df.residual: 42
  │ ├─contrasts: &lt;list&gt;
  │ │ └─manufacturer: "contr.treatment"
  │ ├─xlevels: &lt;list&gt;
  │ │ └─manufacturer&lt;chr [5]&gt;: "audi", "nissan", "subaru", "toyota", "volkswagen"
  │ ├─call: &lt;language&gt; lm(formula = cty ~ manufacturer, data = x)
  │ ├─terms: S3&lt;terms/formula&gt; cty ~ manufacturer
  │ └─model: S3&lt;data.frame&gt;
  │   ├─cty&lt;int [47]&gt;: 18, 21, 20, 21, 16, 18, 18, 18, 16, 20, ...
  │   └─manufacturer&lt;chr [47]&gt;: "audi", "audi", "audi", "audi", "audi", "audi", "audi", "audi", "audi", "audi", ...
  └─S3&lt;lm&gt;
    ├─coefficients&lt;dbl [7]&gt;: 16, 2.80000000000001, 3.00000000000001, 4.00000000000001, 1.00000000000001, 3.85714285714287, 2.57142857142858
    ├─residuals&lt;dbl [41]&gt;: -1.00000000000003, 1.00000000000001, 1.05208052500074e-14, 0.200000000000008, 3.2, -0.800000000000004, -0.8, -1.8, -1, -1, ...
    ├─effects&lt;dbl [41]&gt;: -120.097622892338, 0.10476454436544, 0.736955526660781, 3.98035930389303, -3.23748103044015, 4.17435145669764, 3.72635402044873, -1.27026155514514, -0.923635942390468, -0.923635942390468, ...
    ├─rank: 7
    ├─fitted.values&lt;dbl [41]&gt;: 16, 16, 16, 18.8, 18.8, 18.8, 18.8, 18.8, 19, 19, ...
    ├─assign&lt;int [7]&gt;: 0, 1, 1, 1, 1, 1, 1
    ├─qr: S3&lt;qr&gt;
    │ ├─qr&lt;dbl [287]&gt;: -6.40312423743285, 0.156173761888606, 0.156173761888606, 0.156173761888606, 0.156173761888606, 0.156173761888606, 0.156173761888606, 0.156173761888606, 0.156173761888606, 0.156173761888606, ...
    │ ├─qraux&lt;dbl [7]&gt;: 1.15617376188861, 1.0503406378574, 1.06742880959931, 1.02124277862812, 1.02296110820256, 1.03939209519442, 1.09021806425183
    │ ├─pivot&lt;int [7]&gt;: 1, 2, 3, 4, 5, 6, 7
    │ ├─tol: 1e-07
    │ └─rank: 7
    ├─df.residual: 34
    ├─contrasts: &lt;list&gt;
    │ └─manufacturer: "contr.treatment"
    ├─xlevels: &lt;list&gt;
    │ └─manufacturer&lt;chr [7]&gt;: "audi", "chevrolet", "hyundai", "nissan", "pontiac", "toyota", "volkswagen"
    ├─call: &lt;language&gt; lm(formula = cty ~ manufacturer, data = x)
    ├─terms: S3&lt;terms/formula&gt; cty ~ manufacturer
    └─model: S3&lt;data.frame&gt;
      ├─cty&lt;int [41]&gt;: 15, 17, 16, 19, 22, 18, 18, 17, 18, 18, ...
      └─manufacturer&lt;chr [41]&gt;: "audi", "audi", "audi", "chevrolet", "chevrolet", "chevrolet", "chevrolet", "chevrolet", "hyundai", "hyundai", ...</code></pre>
</div>
</div>
</section><section id="listviewer" class="level3"><h3 class="anchored" data-anchor-id="listviewer"><code>listviewer</code></h3>
<p>If you’re looking for a more GUI-type visualization of nested <code>df</code>s, consider <code><a href="https://rdrr.io/pkg/listviewer/man/reactjson.html">listviewer::reactjson()</a></code>:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-7_67e794ab0254f1818fe07e82e2eca75b">
<style type="text/css">
.reactjson.html-widget {
font-size: 14px;
}
</style>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-8_47a75b51dc603622e741aee6a7c86819">
<div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">mpg_subset</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://tidyr.tidyverse.org/reference/nest.html">nest</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>.by <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">cyl</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">class</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://tidyr.tidyverse.org/reference/nest.html">nest</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>.by <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">class</span>, .key <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"class_data"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">listviewer</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/listviewer/man/reactjson.html">reactjson</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>collapsed <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># collapse after 4 levels deep</span></span></code></pre></div>
<div class="cell-output-display">
<div class="reactjson html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-b5ad9e0573facd6db7af" style="width:100%;height:464px;"></div>
<script type="application/json" data-for="htmlwidget-b5ad9e0573facd6db7af">{"x":{"data":{"class":["compact","midsize","suv","2seater","minivan","pickup","subcompact"],"class_data":[{"cyl":[4,6,5],"data":[{"manufacturer":["audi","audi","audi","audi","audi","audi","audi","audi","nissan","nissan","subaru","subaru","subaru","subaru","toyota","toyota","toyota","toyota","toyota","toyota","toyota","toyota","toyota","volkswagen","volkswagen","volkswagen","volkswagen","volkswagen","volkswagen","volkswagen","volkswagen","volkswagen"],"hwy":[29,29,31,30,26,25,28,27,29,27,25,27,25,27,27,29,31,31,30,33,35,37,35,29,26,29,29,44,29,26,29,29],"cty":[18,21,20,21,18,16,20,19,21,19,20,20,19,20,21,21,21,22,24,24,26,28,26,21,19,21,22,33,21,19,22,21]},{"manufacturer":["audi","audi","audi","audi","audi","audi","audi","toyota","toyota","toyota","volkswagen","volkswagen","volkswagen"],"hwy":[26,26,27,25,25,25,25,26,26,27,24,23,24],"cty":[16,18,18,15,17,17,15,18,18,18,17,16,17]},{"manufacturer":["volkswagen","volkswagen"],"hwy":[29,29],"cty":[21,21]}]},{"cyl":[6,8,4],"data":[{"manufacturer":["audi","audi","chevrolet","chevrolet","chevrolet","hyundai","hyundai","hyundai","nissan","nissan","nissan","nissan","nissan","pontiac","pontiac","pontiac","pontiac","toyota","toyota","toyota","volkswagen","volkswagen","volkswagen"],"hwy":[24,25,26,29,26,26,26,28,27,26,26,25,25,26,26,27,28,26,26,28,26,26,26],"cty":[15,17,18,18,17,18,18,19,19,19,18,19,19,18,16,17,18,18,18,19,16,18,17]},{"manufacturer":["audi","pontiac"],"hwy":[23,25],"cty":[16,16]},{"manufacturer":["chevrolet","chevrolet","hyundai","hyundai","hyundai","hyundai","nissan","nissan","toyota","toyota","toyota","toyota","volkswagen","volkswagen","volkswagen","volkswagen"],"hwy":[27,30,26,27,30,31,31,32,29,27,31,31,29,29,28,29],"cty":[19,22,18,18,21,21,23,23,21,21,21,21,21,18,19,21]}]},{"cyl":[8,6,4],"data":[{"manufacturer":["chevrolet","chevrolet","chevrolet","chevrolet","chevrolet","chevrolet","chevrolet","chevrolet","chevrolet","dodge","dodge","dodge","dodge","dodge","dodge","ford","ford","ford","ford","ford","jeep","jeep","jeep","jeep","jeep","land rover","land rover","land rover","land rover","lincoln","lincoln","lincoln","mercury","mercury","nissan","toyota","toyota","toyota"],"hwy":[20,15,20,17,17,19,14,15,17,17,12,17,16,18,15,17,17,18,19,17,17,12,19,18,14,15,18,18,15,17,16,18,19,17,18,17,15,18],"cty":[14,11,14,13,12,14,11,11,14,13,9,13,11,13,11,11,11,12,13,13,14,9,14,13,11,11,12,12,11,11,11,12,13,13,12,14,11,13]},{"manufacturer":["dodge","ford","ford","ford","ford","jeep","jeep","jeep","mercury","mercury","nissan","nissan","nissan","toyota","toyota","toyota"],"hwy":[17,17,19,17,19,22,19,20,17,19,17,17,20,19,17,20],"cty":[13,14,15,14,13,17,15,15,14,13,14,15,14,15,15,16]},{"manufacturer":["subaru","subaru","subaru","subaru","subaru","subaru","toyota","toyota"],"hwy":[25,24,27,25,26,23,20,20],"cty":[18,18,20,19,20,18,15,16]}]},{"cyl":[8],"data":[{"manufacturer":["chevrolet","chevrolet","chevrolet","chevrolet","chevrolet"],"hwy":[26,23,26,25,24],"cty":[16,15,16,15,15]}]},{"cyl":[4,6],"data":[{"manufacturer":["dodge"],"hwy":[24],"cty":[18]},{"manufacturer":["dodge","dodge","dodge","dodge","dodge","dodge","dodge","dodge","dodge","dodge"],"hwy":[24,22,22,24,24,17,22,21,23,23],"cty":[17,16,16,17,17,11,15,15,16,16]}]},{"cyl":[6,8,4],"data":[{"manufacturer":["dodge","dodge","dodge","dodge","ford","ford","toyota","toyota","toyota","toyota"],"hwy":[19,18,17,17,17,17,17,19,18,20],"cty":[15,14,13,14,14,14,15,15,15,16]},{"manufacturer":["dodge","dodge","dodge","dodge","dodge","dodge","dodge","dodge","dodge","dodge","dodge","dodge","dodge","dodge","dodge","ford","ford","ford","ford","ford"],"hwy":[19,19,12,17,15,16,12,17,17,16,12,15,16,17,15,16,16,17,15,17],"cty":[14,14,9,11,11,12,9,13,13,12,9,11,11,13,11,13,13,13,11,13]},{"manufacturer":["toyota","toyota","toyota"],"hwy":[20,20,22],"cty":[15,16,17]}]},{"cyl":[6,8,4,5],"data":[{"manufacturer":["ford","ford","ford","ford","hyundai","hyundai","hyundai"],"hwy":[26,25,26,24,24,24,24],"cty":[18,18,17,16,17,16,17]},{"manufacturer":["ford","ford","ford","ford","ford"],"hwy":[21,22,23,22,20],"cty":[15,15,15,15,14]},{"manufacturer":["honda","honda","honda","honda","honda","honda","honda","honda","honda","hyundai","hyundai","hyundai","hyundai","subaru","subaru","subaru","subaru","volkswagen","volkswagen","volkswagen","volkswagen"],"hwy":[33,32,32,29,32,34,36,36,29,26,29,28,27,26,26,26,26,44,41,29,26],"cty":[28,24,25,23,24,26,25,24,21,19,19,20,20,21,19,19,19,35,29,21,19]},{"manufacturer":["volkswagen","volkswagen"],"hwy":[28,29],"cty":[20,20]}]}]},"name":"root","theme":"rjv-default","iconStyle":"circle","indentWidth":4,"collapsed":4,"collapseStringsAfterLength":false,"groupArraysAfterLength":100,"enableClipboard":true,"displayObjectSize":true,"displayDataTypes":true,"onEdit":true,"onAdd":true,"onDelete":true,"onSelect":true,"sortKeys":false},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p><br></p>
<p><code>reactjson</code> gives essentially the same view as <code>tree</code>: each column of the <code>df</code> is its own node. You can, though, get a more row-wise view which I sometimes find more intuitive by first converting to JSON—here each level of <code>class</code> is its own node:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-9_e396b7f1d66079bf77b315f5fe69cfc1">
<div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">mpg_subset</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://tidyr.tidyverse.org/reference/nest.html">nest</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>.by <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">cyl</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">class</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://tidyr.tidyverse.org/reference/nest.html">nest</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>.by <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">class</span>, .key <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"class_data"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">jsonlite</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/jsonlite/man/fromJSON.html">toJSON</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">listviewer</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/listviewer/man/reactjson.html">reactjson</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>collapsed <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># collapse after 4 levels deep</span></span></code></pre></div>
<div class="cell-output-display">
<div class="reactjson html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-394dde6841a184436040" style="width:100%;height:464px;"></div>
<script type="application/json" data-for="htmlwidget-394dde6841a184436040">{"x":{"data":[{"class":"compact","class_data":[{"cyl":4,"data":[{"manufacturer":"audi","hwy":29,"cty":18},{"manufacturer":"audi","hwy":29,"cty":21},{"manufacturer":"audi","hwy":31,"cty":20},{"manufacturer":"audi","hwy":30,"cty":21},{"manufacturer":"audi","hwy":26,"cty":18},{"manufacturer":"audi","hwy":25,"cty":16},{"manufacturer":"audi","hwy":28,"cty":20},{"manufacturer":"audi","hwy":27,"cty":19},{"manufacturer":"nissan","hwy":29,"cty":21},{"manufacturer":"nissan","hwy":27,"cty":19},{"manufacturer":"subaru","hwy":25,"cty":20},{"manufacturer":"subaru","hwy":27,"cty":20},{"manufacturer":"subaru","hwy":25,"cty":19},{"manufacturer":"subaru","hwy":27,"cty":20},{"manufacturer":"toyota","hwy":27,"cty":21},{"manufacturer":"toyota","hwy":29,"cty":21},{"manufacturer":"toyota","hwy":31,"cty":21},{"manufacturer":"toyota","hwy":31,"cty":22},{"manufacturer":"toyota","hwy":30,"cty":24},{"manufacturer":"toyota","hwy":33,"cty":24},{"manufacturer":"toyota","hwy":35,"cty":26},{"manufacturer":"toyota","hwy":37,"cty":28},{"manufacturer":"toyota","hwy":35,"cty":26},{"manufacturer":"volkswagen","hwy":29,"cty":21},{"manufacturer":"volkswagen","hwy":26,"cty":19},{"manufacturer":"volkswagen","hwy":29,"cty":21},{"manufacturer":"volkswagen","hwy":29,"cty":22},{"manufacturer":"volkswagen","hwy":44,"cty":33},{"manufacturer":"volkswagen","hwy":29,"cty":21},{"manufacturer":"volkswagen","hwy":26,"cty":19},{"manufacturer":"volkswagen","hwy":29,"cty":22},{"manufacturer":"volkswagen","hwy":29,"cty":21}]},{"cyl":6,"data":[{"manufacturer":"audi","hwy":26,"cty":16},{"manufacturer":"audi","hwy":26,"cty":18},{"manufacturer":"audi","hwy":27,"cty":18},{"manufacturer":"audi","hwy":25,"cty":15},{"manufacturer":"audi","hwy":25,"cty":17},{"manufacturer":"audi","hwy":25,"cty":17},{"manufacturer":"audi","hwy":25,"cty":15},{"manufacturer":"toyota","hwy":26,"cty":18},{"manufacturer":"toyota","hwy":26,"cty":18},{"manufacturer":"toyota","hwy":27,"cty":18},{"manufacturer":"volkswagen","hwy":24,"cty":17},{"manufacturer":"volkswagen","hwy":23,"cty":16},{"manufacturer":"volkswagen","hwy":24,"cty":17}]},{"cyl":5,"data":[{"manufacturer":"volkswagen","hwy":29,"cty":21},{"manufacturer":"volkswagen","hwy":29,"cty":21}]}]},{"class":"midsize","class_data":[{"cyl":6,"data":[{"manufacturer":"audi","hwy":24,"cty":15},{"manufacturer":"audi","hwy":25,"cty":17},{"manufacturer":"chevrolet","hwy":26,"cty":18},{"manufacturer":"chevrolet","hwy":29,"cty":18},{"manufacturer":"chevrolet","hwy":26,"cty":17},{"manufacturer":"hyundai","hwy":26,"cty":18},{"manufacturer":"hyundai","hwy":26,"cty":18},{"manufacturer":"hyundai","hwy":28,"cty":19},{"manufacturer":"nissan","hwy":27,"cty":19},{"manufacturer":"nissan","hwy":26,"cty":19},{"manufacturer":"nissan","hwy":26,"cty":18},{"manufacturer":"nissan","hwy":25,"cty":19},{"manufacturer":"nissan","hwy":25,"cty":19},{"manufacturer":"pontiac","hwy":26,"cty":18},{"manufacturer":"pontiac","hwy":26,"cty":16},{"manufacturer":"pontiac","hwy":27,"cty":17},{"manufacturer":"pontiac","hwy":28,"cty":18},{"manufacturer":"toyota","hwy":26,"cty":18},{"manufacturer":"toyota","hwy":26,"cty":18},{"manufacturer":"toyota","hwy":28,"cty":19},{"manufacturer":"volkswagen","hwy":26,"cty":16},{"manufacturer":"volkswagen","hwy":26,"cty":18},{"manufacturer":"volkswagen","hwy":26,"cty":17}]},{"cyl":8,"data":[{"manufacturer":"audi","hwy":23,"cty":16},{"manufacturer":"pontiac","hwy":25,"cty":16}]},{"cyl":4,"data":[{"manufacturer":"chevrolet","hwy":27,"cty":19},{"manufacturer":"chevrolet","hwy":30,"cty":22},{"manufacturer":"hyundai","hwy":26,"cty":18},{"manufacturer":"hyundai","hwy":27,"cty":18},{"manufacturer":"hyundai","hwy":30,"cty":21},{"manufacturer":"hyundai","hwy":31,"cty":21},{"manufacturer":"nissan","hwy":31,"cty":23},{"manufacturer":"nissan","hwy":32,"cty":23},{"manufacturer":"toyota","hwy":29,"cty":21},{"manufacturer":"toyota","hwy":27,"cty":21},{"manufacturer":"toyota","hwy":31,"cty":21},{"manufacturer":"toyota","hwy":31,"cty":21},{"manufacturer":"volkswagen","hwy":29,"cty":21},{"manufacturer":"volkswagen","hwy":29,"cty":18},{"manufacturer":"volkswagen","hwy":28,"cty":19},{"manufacturer":"volkswagen","hwy":29,"cty":21}]}]},{"class":"suv","class_data":[{"cyl":8,"data":[{"manufacturer":"chevrolet","hwy":20,"cty":14},{"manufacturer":"chevrolet","hwy":15,"cty":11},{"manufacturer":"chevrolet","hwy":20,"cty":14},{"manufacturer":"chevrolet","hwy":17,"cty":13},{"manufacturer":"chevrolet","hwy":17,"cty":12},{"manufacturer":"chevrolet","hwy":19,"cty":14},{"manufacturer":"chevrolet","hwy":14,"cty":11},{"manufacturer":"chevrolet","hwy":15,"cty":11},{"manufacturer":"chevrolet","hwy":17,"cty":14},{"manufacturer":"dodge","hwy":17,"cty":13},{"manufacturer":"dodge","hwy":12,"cty":9},{"manufacturer":"dodge","hwy":17,"cty":13},{"manufacturer":"dodge","hwy":16,"cty":11},{"manufacturer":"dodge","hwy":18,"cty":13},{"manufacturer":"dodge","hwy":15,"cty":11},{"manufacturer":"ford","hwy":17,"cty":11},{"manufacturer":"ford","hwy":17,"cty":11},{"manufacturer":"ford","hwy":18,"cty":12},{"manufacturer":"ford","hwy":19,"cty":13},{"manufacturer":"ford","hwy":17,"cty":13},{"manufacturer":"jeep","hwy":17,"cty":14},{"manufacturer":"jeep","hwy":12,"cty":9},{"manufacturer":"jeep","hwy":19,"cty":14},{"manufacturer":"jeep","hwy":18,"cty":13},{"manufacturer":"jeep","hwy":14,"cty":11},{"manufacturer":"land rover","hwy":15,"cty":11},{"manufacturer":"land rover","hwy":18,"cty":12},{"manufacturer":"land rover","hwy":18,"cty":12},{"manufacturer":"land rover","hwy":15,"cty":11},{"manufacturer":"lincoln","hwy":17,"cty":11},{"manufacturer":"lincoln","hwy":16,"cty":11},{"manufacturer":"lincoln","hwy":18,"cty":12},{"manufacturer":"mercury","hwy":19,"cty":13},{"manufacturer":"mercury","hwy":17,"cty":13},{"manufacturer":"nissan","hwy":18,"cty":12},{"manufacturer":"toyota","hwy":17,"cty":14},{"manufacturer":"toyota","hwy":15,"cty":11},{"manufacturer":"toyota","hwy":18,"cty":13}]},{"cyl":6,"data":[{"manufacturer":"dodge","hwy":17,"cty":13},{"manufacturer":"ford","hwy":17,"cty":14},{"manufacturer":"ford","hwy":19,"cty":15},{"manufacturer":"ford","hwy":17,"cty":14},{"manufacturer":"ford","hwy":19,"cty":13},{"manufacturer":"jeep","hwy":22,"cty":17},{"manufacturer":"jeep","hwy":19,"cty":15},{"manufacturer":"jeep","hwy":20,"cty":15},{"manufacturer":"mercury","hwy":17,"cty":14},{"manufacturer":"mercury","hwy":19,"cty":13},{"manufacturer":"nissan","hwy":17,"cty":14},{"manufacturer":"nissan","hwy":17,"cty":15},{"manufacturer":"nissan","hwy":20,"cty":14},{"manufacturer":"toyota","hwy":19,"cty":15},{"manufacturer":"toyota","hwy":17,"cty":15},{"manufacturer":"toyota","hwy":20,"cty":16}]},{"cyl":4,"data":[{"manufacturer":"subaru","hwy":25,"cty":18},{"manufacturer":"subaru","hwy":24,"cty":18},{"manufacturer":"subaru","hwy":27,"cty":20},{"manufacturer":"subaru","hwy":25,"cty":19},{"manufacturer":"subaru","hwy":26,"cty":20},{"manufacturer":"subaru","hwy":23,"cty":18},{"manufacturer":"toyota","hwy":20,"cty":15},{"manufacturer":"toyota","hwy":20,"cty":16}]}]},{"class":"2seater","class_data":[{"cyl":8,"data":[{"manufacturer":"chevrolet","hwy":26,"cty":16},{"manufacturer":"chevrolet","hwy":23,"cty":15},{"manufacturer":"chevrolet","hwy":26,"cty":16},{"manufacturer":"chevrolet","hwy":25,"cty":15},{"manufacturer":"chevrolet","hwy":24,"cty":15}]}]},{"class":"minivan","class_data":[{"cyl":4,"data":[{"manufacturer":"dodge","hwy":24,"cty":18}]},{"cyl":6,"data":[{"manufacturer":"dodge","hwy":24,"cty":17},{"manufacturer":"dodge","hwy":22,"cty":16},{"manufacturer":"dodge","hwy":22,"cty":16},{"manufacturer":"dodge","hwy":24,"cty":17},{"manufacturer":"dodge","hwy":24,"cty":17},{"manufacturer":"dodge","hwy":17,"cty":11},{"manufacturer":"dodge","hwy":22,"cty":15},{"manufacturer":"dodge","hwy":21,"cty":15},{"manufacturer":"dodge","hwy":23,"cty":16},{"manufacturer":"dodge","hwy":23,"cty":16}]}]},{"class":"pickup","class_data":[{"cyl":6,"data":[{"manufacturer":"dodge","hwy":19,"cty":15},{"manufacturer":"dodge","hwy":18,"cty":14},{"manufacturer":"dodge","hwy":17,"cty":13},{"manufacturer":"dodge","hwy":17,"cty":14},{"manufacturer":"ford","hwy":17,"cty":14},{"manufacturer":"ford","hwy":17,"cty":14},{"manufacturer":"toyota","hwy":17,"cty":15},{"manufacturer":"toyota","hwy":19,"cty":15},{"manufacturer":"toyota","hwy":18,"cty":15},{"manufacturer":"toyota","hwy":20,"cty":16}]},{"cyl":8,"data":[{"manufacturer":"dodge","hwy":19,"cty":14},{"manufacturer":"dodge","hwy":19,"cty":14},{"manufacturer":"dodge","hwy":12,"cty":9},{"manufacturer":"dodge","hwy":17,"cty":11},{"manufacturer":"dodge","hwy":15,"cty":11},{"manufacturer":"dodge","hwy":16,"cty":12},{"manufacturer":"dodge","hwy":12,"cty":9},{"manufacturer":"dodge","hwy":17,"cty":13},{"manufacturer":"dodge","hwy":17,"cty":13},{"manufacturer":"dodge","hwy":16,"cty":12},{"manufacturer":"dodge","hwy":12,"cty":9},{"manufacturer":"dodge","hwy":15,"cty":11},{"manufacturer":"dodge","hwy":16,"cty":11},{"manufacturer":"dodge","hwy":17,"cty":13},{"manufacturer":"dodge","hwy":15,"cty":11},{"manufacturer":"ford","hwy":16,"cty":13},{"manufacturer":"ford","hwy":16,"cty":13},{"manufacturer":"ford","hwy":17,"cty":13},{"manufacturer":"ford","hwy":15,"cty":11},{"manufacturer":"ford","hwy":17,"cty":13}]},{"cyl":4,"data":[{"manufacturer":"toyota","hwy":20,"cty":15},{"manufacturer":"toyota","hwy":20,"cty":16},{"manufacturer":"toyota","hwy":22,"cty":17}]}]},{"class":"subcompact","class_data":[{"cyl":6,"data":[{"manufacturer":"ford","hwy":26,"cty":18},{"manufacturer":"ford","hwy":25,"cty":18},{"manufacturer":"ford","hwy":26,"cty":17},{"manufacturer":"ford","hwy":24,"cty":16},{"manufacturer":"hyundai","hwy":24,"cty":17},{"manufacturer":"hyundai","hwy":24,"cty":16},{"manufacturer":"hyundai","hwy":24,"cty":17}]},{"cyl":8,"data":[{"manufacturer":"ford","hwy":21,"cty":15},{"manufacturer":"ford","hwy":22,"cty":15},{"manufacturer":"ford","hwy":23,"cty":15},{"manufacturer":"ford","hwy":22,"cty":15},{"manufacturer":"ford","hwy":20,"cty":14}]},{"cyl":4,"data":[{"manufacturer":"honda","hwy":33,"cty":28},{"manufacturer":"honda","hwy":32,"cty":24},{"manufacturer":"honda","hwy":32,"cty":25},{"manufacturer":"honda","hwy":29,"cty":23},{"manufacturer":"honda","hwy":32,"cty":24},{"manufacturer":"honda","hwy":34,"cty":26},{"manufacturer":"honda","hwy":36,"cty":25},{"manufacturer":"honda","hwy":36,"cty":24},{"manufacturer":"honda","hwy":29,"cty":21},{"manufacturer":"hyundai","hwy":26,"cty":19},{"manufacturer":"hyundai","hwy":29,"cty":19},{"manufacturer":"hyundai","hwy":28,"cty":20},{"manufacturer":"hyundai","hwy":27,"cty":20},{"manufacturer":"subaru","hwy":26,"cty":21},{"manufacturer":"subaru","hwy":26,"cty":19},{"manufacturer":"subaru","hwy":26,"cty":19},{"manufacturer":"subaru","hwy":26,"cty":19},{"manufacturer":"volkswagen","hwy":44,"cty":35},{"manufacturer":"volkswagen","hwy":41,"cty":29},{"manufacturer":"volkswagen","hwy":29,"cty":21},{"manufacturer":"volkswagen","hwy":26,"cty":19}]},{"cyl":5,"data":[{"manufacturer":"volkswagen","hwy":28,"cty":20},{"manufacturer":"volkswagen","hwy":29,"cty":20}]}]}],"name":"root","theme":"rjv-default","iconStyle":"circle","indentWidth":4,"collapsed":4,"collapseStringsAfterLength":false,"groupArraysAfterLength":100,"enableClipboard":true,"displayObjectSize":true,"displayDataTypes":true,"onEdit":true,"onAdd":true,"onDelete":true,"onSelect":true,"sortKeys":false},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p><br></p>
<p>The <code>listviewer</code> package also provides an alternative JSON viewer, <code>jsonedit()</code>:</p>
<div class="fold o">
<div class="cell" data-hash="index_cache/html/unnamed-chunk-10_6af6ef5264c8d65c1d542ba700120654">
<div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">mpg_subset</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://tidyr.tidyverse.org/reference/nest.html">nest</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>.by <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">cyl</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">class</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://tidyr.tidyverse.org/reference/nest.html">nest</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>.by <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">class</span>, .key <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"class_data"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">jsonlite</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/jsonlite/man/fromJSON.html">toJSON</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># convert df to JSON</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">listviewer</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/listviewer/man/jsonedit.html">jsonedit</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="jsonedit html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-b5ad9e0573facd6db7af" style="width:100%;height:464px;"></div>
<script type="application/json" data-for="htmlwidget-b5ad9e0573facd6db7af">{"x":{"data":[{"class":"compact","class_data":[{"cyl":4,"data":[{"manufacturer":"audi","hwy":29,"cty":18},{"manufacturer":"audi","hwy":29,"cty":21},{"manufacturer":"audi","hwy":31,"cty":20},{"manufacturer":"audi","hwy":30,"cty":21},{"manufacturer":"audi","hwy":26,"cty":18},{"manufacturer":"audi","hwy":25,"cty":16},{"manufacturer":"audi","hwy":28,"cty":20},{"manufacturer":"audi","hwy":27,"cty":19},{"manufacturer":"nissan","hwy":29,"cty":21},{"manufacturer":"nissan","hwy":27,"cty":19},{"manufacturer":"subaru","hwy":25,"cty":20},{"manufacturer":"subaru","hwy":27,"cty":20},{"manufacturer":"subaru","hwy":25,"cty":19},{"manufacturer":"subaru","hwy":27,"cty":20},{"manufacturer":"toyota","hwy":27,"cty":21},{"manufacturer":"toyota","hwy":29,"cty":21},{"manufacturer":"toyota","hwy":31,"cty":21},{"manufacturer":"toyota","hwy":31,"cty":22},{"manufacturer":"toyota","hwy":30,"cty":24},{"manufacturer":"toyota","hwy":33,"cty":24},{"manufacturer":"toyota","hwy":35,"cty":26},{"manufacturer":"toyota","hwy":37,"cty":28},{"manufacturer":"toyota","hwy":35,"cty":26},{"manufacturer":"volkswagen","hwy":29,"cty":21},{"manufacturer":"volkswagen","hwy":26,"cty":19},{"manufacturer":"volkswagen","hwy":29,"cty":21},{"manufacturer":"volkswagen","hwy":29,"cty":22},{"manufacturer":"volkswagen","hwy":44,"cty":33},{"manufacturer":"volkswagen","hwy":29,"cty":21},{"manufacturer":"volkswagen","hwy":26,"cty":19},{"manufacturer":"volkswagen","hwy":29,"cty":22},{"manufacturer":"volkswagen","hwy":29,"cty":21}]},{"cyl":6,"data":[{"manufacturer":"audi","hwy":26,"cty":16},{"manufacturer":"audi","hwy":26,"cty":18},{"manufacturer":"audi","hwy":27,"cty":18},{"manufacturer":"audi","hwy":25,"cty":15},{"manufacturer":"audi","hwy":25,"cty":17},{"manufacturer":"audi","hwy":25,"cty":17},{"manufacturer":"audi","hwy":25,"cty":15},{"manufacturer":"toyota","hwy":26,"cty":18},{"manufacturer":"toyota","hwy":26,"cty":18},{"manufacturer":"toyota","hwy":27,"cty":18},{"manufacturer":"volkswagen","hwy":24,"cty":17},{"manufacturer":"volkswagen","hwy":23,"cty":16},{"manufacturer":"volkswagen","hwy":24,"cty":17}]},{"cyl":5,"data":[{"manufacturer":"volkswagen","hwy":29,"cty":21},{"manufacturer":"volkswagen","hwy":29,"cty":21}]}]},{"class":"midsize","class_data":[{"cyl":6,"data":[{"manufacturer":"audi","hwy":24,"cty":15},{"manufacturer":"audi","hwy":25,"cty":17},{"manufacturer":"chevrolet","hwy":26,"cty":18},{"manufacturer":"chevrolet","hwy":29,"cty":18},{"manufacturer":"chevrolet","hwy":26,"cty":17},{"manufacturer":"hyundai","hwy":26,"cty":18},{"manufacturer":"hyundai","hwy":26,"cty":18},{"manufacturer":"hyundai","hwy":28,"cty":19},{"manufacturer":"nissan","hwy":27,"cty":19},{"manufacturer":"nissan","hwy":26,"cty":19},{"manufacturer":"nissan","hwy":26,"cty":18},{"manufacturer":"nissan","hwy":25,"cty":19},{"manufacturer":"nissan","hwy":25,"cty":19},{"manufacturer":"pontiac","hwy":26,"cty":18},{"manufacturer":"pontiac","hwy":26,"cty":16},{"manufacturer":"pontiac","hwy":27,"cty":17},{"manufacturer":"pontiac","hwy":28,"cty":18},{"manufacturer":"toyota","hwy":26,"cty":18},{"manufacturer":"toyota","hwy":26,"cty":18},{"manufacturer":"toyota","hwy":28,"cty":19},{"manufacturer":"volkswagen","hwy":26,"cty":16},{"manufacturer":"volkswagen","hwy":26,"cty":18},{"manufacturer":"volkswagen","hwy":26,"cty":17}]},{"cyl":8,"data":[{"manufacturer":"audi","hwy":23,"cty":16},{"manufacturer":"pontiac","hwy":25,"cty":16}]},{"cyl":4,"data":[{"manufacturer":"chevrolet","hwy":27,"cty":19},{"manufacturer":"chevrolet","hwy":30,"cty":22},{"manufacturer":"hyundai","hwy":26,"cty":18},{"manufacturer":"hyundai","hwy":27,"cty":18},{"manufacturer":"hyundai","hwy":30,"cty":21},{"manufacturer":"hyundai","hwy":31,"cty":21},{"manufacturer":"nissan","hwy":31,"cty":23},{"manufacturer":"nissan","hwy":32,"cty":23},{"manufacturer":"toyota","hwy":29,"cty":21},{"manufacturer":"toyota","hwy":27,"cty":21},{"manufacturer":"toyota","hwy":31,"cty":21},{"manufacturer":"toyota","hwy":31,"cty":21},{"manufacturer":"volkswagen","hwy":29,"cty":21},{"manufacturer":"volkswagen","hwy":29,"cty":18},{"manufacturer":"volkswagen","hwy":28,"cty":19},{"manufacturer":"volkswagen","hwy":29,"cty":21}]}]},{"class":"suv","class_data":[{"cyl":8,"data":[{"manufacturer":"chevrolet","hwy":20,"cty":14},{"manufacturer":"chevrolet","hwy":15,"cty":11},{"manufacturer":"chevrolet","hwy":20,"cty":14},{"manufacturer":"chevrolet","hwy":17,"cty":13},{"manufacturer":"chevrolet","hwy":17,"cty":12},{"manufacturer":"chevrolet","hwy":19,"cty":14},{"manufacturer":"chevrolet","hwy":14,"cty":11},{"manufacturer":"chevrolet","hwy":15,"cty":11},{"manufacturer":"chevrolet","hwy":17,"cty":14},{"manufacturer":"dodge","hwy":17,"cty":13},{"manufacturer":"dodge","hwy":12,"cty":9},{"manufacturer":"dodge","hwy":17,"cty":13},{"manufacturer":"dodge","hwy":16,"cty":11},{"manufacturer":"dodge","hwy":18,"cty":13},{"manufacturer":"dodge","hwy":15,"cty":11},{"manufacturer":"ford","hwy":17,"cty":11},{"manufacturer":"ford","hwy":17,"cty":11},{"manufacturer":"ford","hwy":18,"cty":12},{"manufacturer":"ford","hwy":19,"cty":13},{"manufacturer":"ford","hwy":17,"cty":13},{"manufacturer":"jeep","hwy":17,"cty":14},{"manufacturer":"jeep","hwy":12,"cty":9},{"manufacturer":"jeep","hwy":19,"cty":14},{"manufacturer":"jeep","hwy":18,"cty":13},{"manufacturer":"jeep","hwy":14,"cty":11},{"manufacturer":"land rover","hwy":15,"cty":11},{"manufacturer":"land rover","hwy":18,"cty":12},{"manufacturer":"land rover","hwy":18,"cty":12},{"manufacturer":"land rover","hwy":15,"cty":11},{"manufacturer":"lincoln","hwy":17,"cty":11},{"manufacturer":"lincoln","hwy":16,"cty":11},{"manufacturer":"lincoln","hwy":18,"cty":12},{"manufacturer":"mercury","hwy":19,"cty":13},{"manufacturer":"mercury","hwy":17,"cty":13},{"manufacturer":"nissan","hwy":18,"cty":12},{"manufacturer":"toyota","hwy":17,"cty":14},{"manufacturer":"toyota","hwy":15,"cty":11},{"manufacturer":"toyota","hwy":18,"cty":13}]},{"cyl":6,"data":[{"manufacturer":"dodge","hwy":17,"cty":13},{"manufacturer":"ford","hwy":17,"cty":14},{"manufacturer":"ford","hwy":19,"cty":15},{"manufacturer":"ford","hwy":17,"cty":14},{"manufacturer":"ford","hwy":19,"cty":13},{"manufacturer":"jeep","hwy":22,"cty":17},{"manufacturer":"jeep","hwy":19,"cty":15},{"manufacturer":"jeep","hwy":20,"cty":15},{"manufacturer":"mercury","hwy":17,"cty":14},{"manufacturer":"mercury","hwy":19,"cty":13},{"manufacturer":"nissan","hwy":17,"cty":14},{"manufacturer":"nissan","hwy":17,"cty":15},{"manufacturer":"nissan","hwy":20,"cty":14},{"manufacturer":"toyota","hwy":19,"cty":15},{"manufacturer":"toyota","hwy":17,"cty":15},{"manufacturer":"toyota","hwy":20,"cty":16}]},{"cyl":4,"data":[{"manufacturer":"subaru","hwy":25,"cty":18},{"manufacturer":"subaru","hwy":24,"cty":18},{"manufacturer":"subaru","hwy":27,"cty":20},{"manufacturer":"subaru","hwy":25,"cty":19},{"manufacturer":"subaru","hwy":26,"cty":20},{"manufacturer":"subaru","hwy":23,"cty":18},{"manufacturer":"toyota","hwy":20,"cty":15},{"manufacturer":"toyota","hwy":20,"cty":16}]}]},{"class":"2seater","class_data":[{"cyl":8,"data":[{"manufacturer":"chevrolet","hwy":26,"cty":16},{"manufacturer":"chevrolet","hwy":23,"cty":15},{"manufacturer":"chevrolet","hwy":26,"cty":16},{"manufacturer":"chevrolet","hwy":25,"cty":15},{"manufacturer":"chevrolet","hwy":24,"cty":15}]}]},{"class":"minivan","class_data":[{"cyl":4,"data":[{"manufacturer":"dodge","hwy":24,"cty":18}]},{"cyl":6,"data":[{"manufacturer":"dodge","hwy":24,"cty":17},{"manufacturer":"dodge","hwy":22,"cty":16},{"manufacturer":"dodge","hwy":22,"cty":16},{"manufacturer":"dodge","hwy":24,"cty":17},{"manufacturer":"dodge","hwy":24,"cty":17},{"manufacturer":"dodge","hwy":17,"cty":11},{"manufacturer":"dodge","hwy":22,"cty":15},{"manufacturer":"dodge","hwy":21,"cty":15},{"manufacturer":"dodge","hwy":23,"cty":16},{"manufacturer":"dodge","hwy":23,"cty":16}]}]},{"class":"pickup","class_data":[{"cyl":6,"data":[{"manufacturer":"dodge","hwy":19,"cty":15},{"manufacturer":"dodge","hwy":18,"cty":14},{"manufacturer":"dodge","hwy":17,"cty":13},{"manufacturer":"dodge","hwy":17,"cty":14},{"manufacturer":"ford","hwy":17,"cty":14},{"manufacturer":"ford","hwy":17,"cty":14},{"manufacturer":"toyota","hwy":17,"cty":15},{"manufacturer":"toyota","hwy":19,"cty":15},{"manufacturer":"toyota","hwy":18,"cty":15},{"manufacturer":"toyota","hwy":20,"cty":16}]},{"cyl":8,"data":[{"manufacturer":"dodge","hwy":19,"cty":14},{"manufacturer":"dodge","hwy":19,"cty":14},{"manufacturer":"dodge","hwy":12,"cty":9},{"manufacturer":"dodge","hwy":17,"cty":11},{"manufacturer":"dodge","hwy":15,"cty":11},{"manufacturer":"dodge","hwy":16,"cty":12},{"manufacturer":"dodge","hwy":12,"cty":9},{"manufacturer":"dodge","hwy":17,"cty":13},{"manufacturer":"dodge","hwy":17,"cty":13},{"manufacturer":"dodge","hwy":16,"cty":12},{"manufacturer":"dodge","hwy":12,"cty":9},{"manufacturer":"dodge","hwy":15,"cty":11},{"manufacturer":"dodge","hwy":16,"cty":11},{"manufacturer":"dodge","hwy":17,"cty":13},{"manufacturer":"dodge","hwy":15,"cty":11},{"manufacturer":"ford","hwy":16,"cty":13},{"manufacturer":"ford","hwy":16,"cty":13},{"manufacturer":"ford","hwy":17,"cty":13},{"manufacturer":"ford","hwy":15,"cty":11},{"manufacturer":"ford","hwy":17,"cty":13}]},{"cyl":4,"data":[{"manufacturer":"toyota","hwy":20,"cty":15},{"manufacturer":"toyota","hwy":20,"cty":16},{"manufacturer":"toyota","hwy":22,"cty":17}]}]},{"class":"subcompact","class_data":[{"cyl":6,"data":[{"manufacturer":"ford","hwy":26,"cty":18},{"manufacturer":"ford","hwy":25,"cty":18},{"manufacturer":"ford","hwy":26,"cty":17},{"manufacturer":"ford","hwy":24,"cty":16},{"manufacturer":"hyundai","hwy":24,"cty":17},{"manufacturer":"hyundai","hwy":24,"cty":16},{"manufacturer":"hyundai","hwy":24,"cty":17}]},{"cyl":8,"data":[{"manufacturer":"ford","hwy":21,"cty":15},{"manufacturer":"ford","hwy":22,"cty":15},{"manufacturer":"ford","hwy":23,"cty":15},{"manufacturer":"ford","hwy":22,"cty":15},{"manufacturer":"ford","hwy":20,"cty":14}]},{"cyl":4,"data":[{"manufacturer":"honda","hwy":33,"cty":28},{"manufacturer":"honda","hwy":32,"cty":24},{"manufacturer":"honda","hwy":32,"cty":25},{"manufacturer":"honda","hwy":29,"cty":23},{"manufacturer":"honda","hwy":32,"cty":24},{"manufacturer":"honda","hwy":34,"cty":26},{"manufacturer":"honda","hwy":36,"cty":25},{"manufacturer":"honda","hwy":36,"cty":24},{"manufacturer":"honda","hwy":29,"cty":21},{"manufacturer":"hyundai","hwy":26,"cty":19},{"manufacturer":"hyundai","hwy":29,"cty":19},{"manufacturer":"hyundai","hwy":28,"cty":20},{"manufacturer":"hyundai","hwy":27,"cty":20},{"manufacturer":"subaru","hwy":26,"cty":21},{"manufacturer":"subaru","hwy":26,"cty":19},{"manufacturer":"subaru","hwy":26,"cty":19},{"manufacturer":"subaru","hwy":26,"cty":19},{"manufacturer":"volkswagen","hwy":44,"cty":35},{"manufacturer":"volkswagen","hwy":41,"cty":29},{"manufacturer":"volkswagen","hwy":29,"cty":21},{"manufacturer":"volkswagen","hwy":26,"cty":19}]},{"cyl":5,"data":[{"manufacturer":"volkswagen","hwy":28,"cty":20},{"manufacturer":"volkswagen","hwy":29,"cty":20}]}]}],"options":{"mode":"tree","modes":["code","form","text","tree","view"]}},"evals":[],"jsHooks":[]}</script>
</div>
</div>
</div>
<p><br></p>
<p>(A quick note: <code>toJSON()</code> only converts a limited selection of objects; it can’t, for example, convert an <code>lm</code> model to visualize like we did with the <code>midwest_data</code> data above.)</p>
</section></section><section id="abstract-syntax-trees-for-complex-function-calls" class="level2"><h2 class="anchored" data-anchor-id="abstract-syntax-trees-for-complex-function-calls">Abstract syntax trees for complex function calls</h2>
<p><code>lobstr</code> also provides the function <code><a href="https://lobstr.r-lib.org/reference/ast.html">ast()</a></code> which gives a visual representation of complex function calls, letting you see the order in which the functions are being evaluated. Here we see that our unnamed function calls <code>+</code> on <code>x</code> and <code>y</code>.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-11_f0e2b18b303ee26f56d8340a69a06177">
<div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://lobstr.r-lib.org/reference/ast.html">ast</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">y</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">y</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>█─`function` 
├─█─x = 1 
│ └─y = 2 
├─█─`{` 
│ └─█─`+` 
│   ├─x 
│   └─y 
└─&lt;inline srcref&gt; </code></pre>
</div>
</div>
<p>This is particularly useful when using pipes, where the linear order of the code is actually the reverse of what it would be without piping. Here, for example, we can see that <code>mutate</code> is applying to a <code>group</code>ed df, which itself was <code>filter</code>ed.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-12_c3ab7263aa3a98298875fd78fc760055">
<div class="sourceCode" id="cb14" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">mpg</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">manufacturer</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"honda"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">cyl</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>mean_hwy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/mean.html">mean</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">hwy</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://lobstr.r-lib.org/reference/ast.html">ast</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>█─mutate 
├─█─group_by 
│ ├─█─filter 
│ │ ├─mpg 
│ │ └─█─`==` 
│ │   ├─manufacturer 
│ │   └─"honda" 
│ └─cyl 
└─mean_hwy = █─mean 
             └─hwy </code></pre>
</div>
</div>
<!-- End content -->
<div id="footer-session-info">
<details><summary>
Session info and package versions
</summary><div class="cell" data-hash="index_cache/html/unnamed-chunk-14_ffd0d53bc988d71991616b9c9e4ae71c">
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code> setting  value
 version  R version 4.3.1 (2023-06-16)
 os       macOS Ventura 13.4.1
 system   aarch64, darwin20
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Chicago
 date     2023-07-10
 pandoc   3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Packages ───────────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>     package loadedversion       date         source
         cli         3.6.1 2023-03-23 CRAN (R 4.3.0)
   codetools        0.2-19 2023-02-01 CRAN (R 4.3.1)
  colorspace         2.1-0 2023-01-23 CRAN (R 4.3.0)
      crayon         1.5.2 2022-09-29 CRAN (R 4.3.0)
      digest        0.6.31 2022-12-11 CRAN (R 4.3.0)
       dplyr         1.1.2 2023-04-20 CRAN (R 4.3.0)
    ellipsis         0.3.2 2021-04-29 CRAN (R 4.3.0)
    evaluate          0.21 2023-05-05 CRAN (R 4.3.0)
       fansi         1.0.4 2023-01-22 CRAN (R 4.3.0)
     fastmap         1.1.1 2023-02-24 CRAN (R 4.3.0)
     forcats         1.0.0 2023-01-29 CRAN (R 4.3.0)
    generics         0.1.3 2022-07-05 CRAN (R 4.3.0)
     ggplot2         3.4.2 2023-04-03 CRAN (R 4.3.0)
        glue         1.6.2 2022-02-24 CRAN (R 4.3.0)
      gtable         0.3.3 2023-03-21 CRAN (R 4.3.0)
         hms         1.1.3 2023-03-21 CRAN (R 4.3.0)
   htmltools         0.5.5 2023-03-23 CRAN (R 4.3.0)
 htmlwidgets         1.6.2 2023-03-17 CRAN (R 4.3.0)
    jsonlite         1.8.7 2023-06-29 CRAN (R 4.3.0)
       knitr          1.43 2023-05-25 CRAN (R 4.3.0)
   lifecycle         1.0.3 2022-10-07 CRAN (R 4.3.0)
  listviewer         3.0.0 2019-11-02 CRAN (R 4.3.0)
      lobstr         1.1.2 2022-06-22 CRAN (R 4.3.0)
   lubridate         1.9.2 2023-02-10 CRAN (R 4.3.0)
    magrittr         2.0.3 2022-03-30 CRAN (R 4.3.0)
     munsell         0.5.0 2018-06-12 CRAN (R 4.3.0)
      pillar         1.9.0 2023-03-22 CRAN (R 4.3.0)
   pkgconfig         2.0.3 2019-09-22 CRAN (R 4.3.0)
       purrr         1.0.1 2023-01-10 CRAN (R 4.3.0)
          R6         2.5.1 2021-08-19 CRAN (R 4.3.0)
        ragg         1.2.5 2023-01-12 CRAN (R 4.3.0)
      reactR         0.4.4 2021-02-22 CRAN (R 4.3.0)
       readr         2.1.4 2023-02-10 CRAN (R 4.3.0)
        renv        0.17.3 2023-04-06 CRAN (R 4.3.0)
       rlang         1.1.1 2023-04-28 CRAN (R 4.3.0)
   rmarkdown          2.22 2023-06-01 CRAN (R 4.3.0)
  rstudioapi          0.14 2022-08-22 CRAN (R 4.3.0)
      scales         1.2.1 2022-08-20 CRAN (R 4.3.0)
 sessioninfo         1.2.2 2021-12-06 CRAN (R 4.3.0)
     stringi        1.7.12 2023-01-11 CRAN (R 4.3.0)
     stringr         1.5.0 2022-12-02 CRAN (R 4.3.0)
 systemfonts         1.0.4 2022-02-11 CRAN (R 4.3.0)
 textshaping         0.3.6 2021-10-13 CRAN (R 4.3.0)
      tibble         3.2.1 2023-03-20 CRAN (R 4.3.0)
       tidyr         1.3.0 2023-01-24 CRAN (R 4.3.0)
  tidyselect         1.2.0 2022-10-10 CRAN (R 4.3.0)
   tidyverse         2.0.0 2023-02-22 CRAN (R 4.3.0)
  timechange         0.2.0 2023-01-11 CRAN (R 4.3.0)
        tzdb         0.4.0 2023-05-12 CRAN (R 4.3.0)
        utf8         1.2.3 2023-01-31 CRAN (R 4.3.0)
       vctrs         0.6.3 2023-06-14 CRAN (R 4.3.0)
       withr         2.5.0 2022-03-03 CRAN (R 4.3.0)
        xfun          0.39 2023-04-20 CRAN (R 4.3.0)
        yaml         2.3.7 2023-01-23 CRAN (R 4.3.0)</code></pre>
</div>
</div>
</details>
</div>


</section> ]]></description>
  <category>misc</category>
  <guid>https://abraver.github.io/usefulRstuff/posts/lobstr/index.html</guid>
  <pubDate>Mon, 10 Jul 2023 05:00:00 GMT</pubDate>
</item>
<item>
  <title>Composing multiple plots with patchwork
</title>
  <dc:creator>Aaron Braver</dc:creator>
  <link>https://abraver.github.io/usefulRstuff/posts/patchwork/index.html</link>
  <description><![CDATA[ <script src="../../jquery-3.7.0.min.js"></script><script src="../../fold.js"></script><script src="../../move_session_info.js"></script><!-- begin content --><div class="cell" data-hash="index_cache/html/setup_cb31195c19eac84c71d9aa9101dafdf1">
<details><summary>Setup</summary><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org">ggplot2</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</details>
</div>
<section id="patchwork" class="level2"><h2 class="anchored" data-anchor-id="patchwork"><code>patchwork</code></h2>
<p>It’s often useful to compose multiple plots together into a single image. There are ways of doing this in base R, e.g., by using <code>par(mfrow=...)</code>, but i’ve always found this unintuitive and finicky. <code>patchwork</code> makes composing <code>ggplot</code>s simple, while allowing for a high degree of customization. (<a href="https://patchwork.data-imaginist.com">The <code>patchwork</code> documentation</a> is very good, and this post will borrow liberally from it, but it’s worth browsing for more details.) (For those looking for an alternative to <code>patchwork</code>, check out <code><a href="https://wilkelab.org/cowplot/reference/plot_grid.html">cowplot::plot_grid()</a></code>.)</p>
<p>Let’s start with 4 simple plots, and look at various ways of composing them. (These plots are nicely arranged in a grid by Quarto for the purposes of this page if your browser window is big enough, but note that they are each a separate image.)</p>
<div>
<details><summary>Code</summary><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">palmerpenguins</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://allisonhorst.github.io/palmerpenguins/reference/penguins.html">penguins</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/geom_point.html">geom_point</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bill_length_mm</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bill_depth_mm</span>,</span>
<span>                 color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">species</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/labs.html">ggtitle</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Plot 1"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">palmerpenguins</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://allisonhorst.github.io/palmerpenguins/reference/penguins.html">penguins</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/geom_boxplot.html">geom_boxplot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bill_length_mm</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">species</span>,</span>
<span>                 color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">species</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/labs.html">ggtitle</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Plot 2"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">palmerpenguins</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://allisonhorst.github.io/palmerpenguins/reference/penguins.html">penguins</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/geom_point.html">geom_point</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bill_length_mm</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">body_mass_g</span>,</span>
<span>                 color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">species</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/labs.html">ggtitle</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Plot 3"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">palmerpenguins</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://allisonhorst.github.io/palmerpenguins/reference/penguins.html">penguins</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/geom_bar.html">geom_bar</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bill_length_mm</span>, fill <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">species</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/labs.html">ggtitle</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Plot 4"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span>; <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span>; <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span>; <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p4</span></span></code></pre></div>
</details><div class="cell quarto-layout-panel" data-hash="index_cache/html/unnamed-chunk-3_92c72a4e16d6b31a75d1d8348ae7e9cc">
<div class="quarto-layout-row quarto-layout-valign-top">
<div class="quarto-figure quarto-figure-center" style="flex-basis: 50.0%;justify-content: center;">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-3-1.png" class="lightbox" data-gallery="boop"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/unnamed-chunk-3-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
<div class="quarto-figure quarto-figure-center" style="flex-basis: 50.0%;justify-content: center;">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-3-2.png" class="lightbox" data-gallery="boop"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/unnamed-chunk-3-2.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
<div class="quarto-layout-row quarto-layout-valign-top">
<div class="quarto-figure quarto-figure-center" style="flex-basis: 50.0%;justify-content: center;">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-3-3.png" class="lightbox" data-gallery="boop"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/unnamed-chunk-3-3.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
<div class="quarto-figure quarto-figure-center" style="flex-basis: 50.0%;justify-content: center;">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-3-4.png" class="lightbox" data-gallery="boop"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/unnamed-chunk-3-4.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
</div>
<p>The simplest operation provided by <code>patchwork</code> is the <code>+</code> operator. Adding two plots together with <code>+</code> glues them together into a single image, side by side. You can do this with as many plots as you like–it will try to give a nice grid if possible. Note that all plots below are combined into a single image.</p>
<div class="tabset-margin-container"></div><div class="panel-tabset">
<ul class="nav nav-tabs">
<li class="nav-item"><a class="nav-link active" id="tabset-1-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-1" aria-controls="tabset-1-1" aria-selected="true">Two plots</a></li>
<li class="nav-item"><a class="nav-link" id="tabset-1-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-2" aria-controls="tabset-1-2" aria-selected="false">Four plots</a></li>
</ul>
<div class="tab-content">
<div id="tabset-1-1" class="tab-pane active" aria-labelledby="tabset-1-1-tab">
<div class="cell" data-fig.asp="0.5">
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://patchwork.data-imaginist.com">patchwork</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-4-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-18"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid figure-img" style="width:100.0%"></a></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-1-2" class="tab-pane" aria-labelledby="tabset-1-2-tab">
<div class="cell" data-hash="index_cache/html/unnamed-chunk-5_517c6e6d78c6b0c66fe0845021695c84">
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://patchwork.data-imaginist.com">patchwork</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p4</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-5-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-19"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/unnamed-chunk-5-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
</div>
</div>
</div>
<p>You can specify the number of rows or columns in your composed plot with <code>plot_layout(nrow=..., ncol=...)</code>. Setting <code>byrow</code> to false fills by column, rather than by row (so the left column below has plots 1, 2, and 3). (Click image to embiggen.)</p>
<div class="cell" data-hash="index_cache/html/byrow_05b63ac03f57d43372c2b4847f85a4b1">
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://patchwork.data-imaginist.com/reference/plot_layout.html">plot_layout</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>nrow <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, byrow <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/byrow-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-5"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/byrow-1.png" class="img-fluid figure-img" style="width:100.0%"></a></p>
</figure>
</div>
</div>
</div>
<p>See the section below on more complicated layouts and <code><a href="https://patchwork.data-imaginist.com/reference/plot_layout.html">?plot_layout</a></code> for more options.</p>
</section><section id="packing-and-stacking-the-and-operators" class="level2"><h2 class="anchored" data-anchor-id="packing-and-stacking-the-and-operators">Packing and stacking (the <code>|</code> and <code>/</code> operators)</h2>
<p>Composing two plots with the <code>|</code> operator works a lot like the <code>+</code> operator above, except it ensures that the plots will end up side-by-side (“packed”) rather than one on top of the other. The <code>/</code> operator does the opposite—it ensures that plots are stacked.”</p>
<div class="tabset-margin-container"></div><div class="panel-tabset">
<ul class="nav nav-tabs">
<li class="nav-item"><a class="nav-link active" id="tabset-2-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-2-1" aria-controls="tabset-2-1" aria-selected="true"><code>p1 | p2</code></a></li>
<li class="nav-item"><a class="nav-link" id="tabset-2-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-2-2" aria-controls="tabset-2-2" aria-selected="false"><code>p1 / p2</code></a></li>
</ul>
<div class="tab-content">
<div id="tabset-2-1" class="tab-pane active" aria-labelledby="tabset-2-1-tab">
<div class="cell" data-fig.asp="0.5" data-hash="index_cache/html/unnamed-chunk-6_ecb26e188dd7450091e48f617e83624d">
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-6-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-20"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/unnamed-chunk-6-1.png" class="img-fluid figure-img" style="width:100.0%"></a></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-2-2" class="tab-pane" aria-labelledby="tabset-2-2-tab">
<div class="cell" data-fig.asp="1.5" data-hash="index_cache/html/unnamed-chunk-7_6f152f2ebcf2d06547bdde96507b542d">
<div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-7-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-21"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/unnamed-chunk-7-1.png" class="img-fluid figure-img" style="width:50.0%"></a></p>
</figure>
</div>
</div>
</div>
</div>
</div>
</div>
<p>Parentheses can help to disambiguate possible layouts. (All of the operators work essentially like their arithmetic counterparts with respect to parentheses.) Without parentheses, as in the first tab below, the <code>/</code> operator takes precedence over the <code>|</code> operator:</p>
<div class="tabset-margin-container"></div><div class="panel-tabset">
<ul class="nav nav-tabs">
<li class="nav-item"><a class="nav-link active" id="tabset-3-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-3-1" aria-controls="tabset-3-1" aria-selected="true"><code>p1 / p2 | p3</code></a></li>
<li class="nav-item"><a class="nav-link" id="tabset-3-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-3-2" aria-controls="tabset-3-2" aria-selected="false"><code>p1 / (p2 | p3)</code></a></li>
</ul>
<div class="tab-content">
<div id="tabset-3-1" class="tab-pane active" aria-labelledby="tabset-3-1-tab">
<div class="cell" data-hash="index_cache/html/unnamed-chunk-8_41b714f3ec722196210cf86e7d1ef3ab">
<div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-8-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-22"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/unnamed-chunk-8-1.png" class="img-fluid figure-img" style="width:100.0%"></a></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-3-2" class="tab-pane" aria-labelledby="tabset-3-2-tab">
<div class="cell" data-hash="index_cache/html/unnamed-chunk-9_397b193eeeb3cf38a70dcb65f0e2d330">
<div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-9-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-23"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/unnamed-chunk-9-1.png" class="img-fluid figure-img" style="width:100.0%"></a></p>
</figure>
</div>
</div>
</div>
</div>
</div>
</div>
</section><section id="annotating-the-composed-plot" class="level2"><h2 class="anchored" data-anchor-id="annotating-the-composed-plot">Annotating the composed plot</h2>
<p><code><a href="https://patchwork.data-imaginist.com/reference/plot_annotation.html">plot_annotation()</a></code> will annotate the combined, composed plot. The <code>title</code> and <code>subtitle</code>, arguments work as you would expect. The <code>tag_levels</code> argument lets you specify one of <code>c('a', 'A', '1', 'i', 'I')</code> for various sub-plot numbering:</p>
<div class="cell" data-hash="index_cache/html/annotating_51f0e5e0ccb06344fb3048f2bdf50da1">
<div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://patchwork.data-imaginist.com/reference/plot_annotation.html">plot_annotation</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>title <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Lots of data about penguins'</span>,</span>
<span>    subtitle <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'There\'s never too much info about penguins'</span>,</span>
<span>    tag_levels <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>plot.title <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_text</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>hjust <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.5</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>,</span>
<span>        plot.tag <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_text</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>size <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/annotating-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-6"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/annotating-1.png" class="img-fluid figure-img" style="width:100.0%"></a></p>
</figure>
</div>
</div>
</div>
<p>(The <code>&amp;</code> operator applies the theme specification to all subplots within the composed plot (and overall things like the main title/subtitle); the <code>*</code> operator applies the theme specifications to all subplots in the current nesting. level.)</p>
<p>If you want a theme element to apply only to the overall plot, and not the subplots, use the <code>theme</code> argument to <code><a href="https://patchwork.data-imaginist.com/reference/plot_annotation.html">plot_annotation()</a></code> rather than <code>&amp; theme(...)</code>.</p>
<div class="cell" data-hash="index_cache/html/theme_argument_f00fe4daf9a4d2ff6676afc69f7db47f">
<div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://patchwork.data-imaginist.com/reference/plot_annotation.html">plot_annotation</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>title <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Lots of data about penguins'</span>,</span>
<span>    subtitle <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'There\'s never too much info about penguins'</span>, tag_levels <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span>,</span>
<span>    theme <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>plot.title <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_text</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>hjust <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.5</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>,</span>
<span>        plot.tag <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_text</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>size <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/theme_argument-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-7"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/theme_argument-1.png" class="img-fluid figure-img" style="width:100.0%"></a></p>
</figure>
</div>
</div>
</div>
</section><section id="more-complicated-layouts" class="level2"><h2 class="anchored" data-anchor-id="more-complicated-layouts">More complicated layouts</h2>
<p>We saw above that we can modify the layout with <code>plot_layout(ncol = ...)</code>. You can also specify relative <code>widths</code> and <code>heights</code> for the rows and columns. For example, you can provide <code>widths</code> with a vector of <em>n</em> columns to specify each.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-10_c306e3a4cb0c5d9a4dce647a6ec90aa4">
<details><summary>Some plot theme changes for visibility in the following examples</summary><div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>legend.position <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>, plot.background <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_rect</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, linewidth <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, fill <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>legend.position <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>, plot.background <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_rect</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>, linewidth <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, fill <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>legend.position <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>, plot.background <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_rect</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"green"</span>, linewidth <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, fill <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>legend.position <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>, plot.background <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_rect</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span>, linewidth <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, fill <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</details>
</div>
<div class="cell" data-hash="index_cache/html/widths_40d8ca9841e3f9ca1ae27e15a083dff2">
<div class="sourceCode" id="cb13" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://patchwork.data-imaginist.com/reference/plot_layout.html">plot_layout</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>widths <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, heights <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/widths-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-8"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/widths-1.png" class="img-fluid figure-img" style="width:75.0%"></a></p>
</figure>
</div>
</div>
</div>
<p>You can also specify quite complicated layouts with <code>plot_layout(design = ...)</code>, in two formats. The simplest is to use a textual representation, as below. Letters represent plots (in the order in which they appear), with <code>#</code>s representing empty spaces. You must specify a perfect rectangular shape.</p>
<div class="cell" data-hash="index_cache/html/letter_design_1637f49d0bbb97acd203e009a7bec9f1">
<div class="sourceCode" id="cb14" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">layout</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">##BBBB</span></span>
<span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">AACCDD</span></span>
<span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">##CCDD</span></span>
<span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://patchwork.data-imaginist.com/reference/plot_layout.html">plot_layout</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>design <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">layout</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/letter_design-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-9"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/letter_design-1.png" class="img-fluid figure-img" style="width:75.0%"></a></p>
</figure>
</div>
</div>
</div>
<p>Using <code>wrap_plots</code>, you can specify which plot is represented by which letter, rather than letting that be handled automatically:</p>
<div class="cell" data-hash="index_cache/html/wrap_plots_5875dfc5c750f7863250bed79bc37ebe">
<div class="sourceCode" id="cb15" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">layout</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span></span>
<span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">A#B</span></span>
<span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">#C#</span></span>
<span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">D#E</span></span>
<span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span></span>
<span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://patchwork.data-imaginist.com/reference/wrap_plots.html">wrap_plots</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>D <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span>, C <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span>, B <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span>, design <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">layout</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/wrap_plots-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-10"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/wrap_plots-1.png" class="img-fluid figure-img" style="width:75.0%"></a></p>
</figure>
</div>
</div>
</div>
<p>The alternative way to specify a layout is with one or more <code><a href="https://patchwork.data-imaginist.com/reference/area.html">area()</a></code>s, which take arguments for the <code>t</code>op, <code>l</code>eft, <code>b</code>ottom, and <code>r</code>ight bounds of a grid.<sup>1</sup> The grid is specified in rows and columns, with row 1 column 1 being the top left, and numbers increasing as you go down and right. You can have plots overlap with this type of specification.</p>
<div class="cell" data-hash="index_cache/html/area_a2f3b50761465ff266b78708e6893047">
<div class="sourceCode" id="cb16" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">layout</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://patchwork.data-imaginist.com/reference/area.html">area</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, l <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, b <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># This will be p1</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://patchwork.data-imaginist.com/reference/area.html">area</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, l <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, b <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># this will be p2</span></span>
<span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://patchwork.data-imaginist.com/reference/plot_layout.html">plot_layout</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>design <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">layout</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/area-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-11"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/area-1.png" class="img-fluid figure-img" style="width:75.0%"></a></p>
</figure>
</div>
</div>
</div>
<section id="insets" class="level3"><h3 class="anchored" data-anchor-id="insets">Insets</h3>
<p>It’s also possible to specify insets using <code><a href="https://patchwork.data-imaginist.com/reference/inset_element.html">inset_element()</a></code>. Here, the position arguments should be relative to 1, with (0, 0) being bottom left and (1, 1) being top right. The <code>align_to</code> argument defaults to <code>panel</code>, but accepts values <code>plot</code> or <code>full</code> as well.</p>
<div class="cell" data-hash="index_cache/html/inset_fc89adb30e37d71598c2f003cf7f0e8a">
<div class="sourceCode" id="cb17" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://patchwork.data-imaginist.com/reference/inset_element.html">inset_element</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span>, top <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, right <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, bottom <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.5</span>,</span>
<span>                   left <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.5</span>, align_to <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"full"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/inset-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-12"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/inset-1.png" class="img-fluid figure-img" style="width:75.0%"></a></p>
</figure>
</div>
</div>
</div>
</section></section><section id="controlling-legends" class="level2"><h2 class="anchored" data-anchor-id="controlling-legends">Controlling legends</h2>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-11_4952d7ca1b5c43836b4644e6d4ac30fc">
<details><summary>Reset plots to their original theme</summary><div class="sourceCode" id="cb18" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>legend.position <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>, plot.background <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_blank</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>legend.position <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>, plot.background <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_blank</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>legend.position <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>, plot.background <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_blank</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>legend.position <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>, plot.background <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_blank</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</details>
</div>
<p><code>plot_layout(guides = "collect")</code> will collect all of the legends and put them in the same location. Legends that are identical between multiple subplots are collapsed, as with plots 1 and 3 below:</p>
<div class="tabset-margin-container"></div><div class="panel-tabset">
<ul class="nav nav-tabs">
<li class="nav-item"><a class="nav-link active" id="tabset-4-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-4-1" aria-controls="tabset-4-1" aria-selected="true"><code>guides</code> = “collect”</a></li>
<li class="nav-item"><a class="nav-link" id="tabset-4-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-4-2" aria-controls="tabset-4-2" aria-selected="false"><code>guides</code> = “keep”</a></li>
</ul>
<div class="tab-content">
<div id="tabset-4-1" class="tab-pane active" aria-labelledby="tabset-4-1-tab">
<div class="cell" data-hash="index_cache/html/collect_4834e1d868337837b957181223eb720f">
<div class="sourceCode" id="cb19" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://patchwork.data-imaginist.com/reference/plot_layout.html">plot_layout</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>guides <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"collect"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/collect-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-24"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/collect-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-4-2" class="tab-pane" aria-labelledby="tabset-4-2-tab">
<div class="cell" data-hash="index_cache/html/unnamed-chunk-12_84e54800ac1bd2255babeeaa765312cc">
<div class="sourceCode" id="cb20" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://patchwork.data-imaginist.com/reference/plot_layout.html">plot_layout</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>guides <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"keep"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-12-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-25"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/unnamed-chunk-12-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
</div>
</div>
</div>
<p>You can influence where the collected legends show up by including <code><a href="https://patchwork.data-imaginist.com/reference/guide_area.html">guide_area()</a></code> in your layout specification:</p>
<div class="cell" data-hash="index_cache/html/collect-area_162e1fe901609b6799a237e4ce6d6635">
<div class="sourceCode" id="cb21" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://patchwork.data-imaginist.com/reference/guide_area.html">guide_area</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://patchwork.data-imaginist.com/reference/plot_layout.html">plot_layout</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>guides <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"collect"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/collect-area-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-13"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/collect-area-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
</section><section id="nesting" class="level2"><h2 class="anchored" data-anchor-id="nesting">Nesting</h2>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-13_98bed90f96aa74c5d6227f71bc827c90">
<details><summary>Some plot theme changes for visibility in the following examples</summary><div class="sourceCode" id="cb22" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>legend.position <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>, plot.background <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_rect</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, linewidth <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, fill <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>legend.position <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>, plot.background <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_rect</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>, linewidth <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, fill <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>legend.position <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>, plot.background <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_rect</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"green"</span>, linewidth <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, fill <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>legend.position <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>, plot.background <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_rect</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span>, linewidth <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, fill <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</details>
</div>
<p>Plots can be nested at multiple levels. Compare the following plots: in the first we use <code><a href="https://patchwork.data-imaginist.com/reference/wrap_plots.html">wrap_plots()</a></code> to combine <code>p1</code> and <code>p2</code> into a single unit (which is then added to plot 3); in the second we don’t do any nesting.</p>
<div class="tabset-margin-container"></div><div class="panel-tabset">
<ul class="nav nav-tabs">
<li class="nav-item"><a class="nav-link active" id="tabset-5-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-5-1" aria-controls="tabset-5-1" aria-selected="true">Nesting <code>p1</code> and <code>p2</code></a></li>
<li class="nav-item"><a class="nav-link" id="tabset-5-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-5-2" aria-controls="tabset-5-2" aria-selected="false">No nesting</a></li>
</ul>
<div class="tab-content">
<div id="tabset-5-1" class="tab-pane active" aria-labelledby="tabset-5-1-tab">
<div class="cell" data-fig.asp="0.5" data-hash="index_cache/html/nesting_d23e9ffd8039d5b02e46fc02e0661b97">
<div class="sourceCode" id="cb23" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://patchwork.data-imaginist.com/reference/wrap_plots.html">wrap_plots</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/nesting-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-26"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/nesting-1.png" class="img-fluid figure-img" style="width:100.0%"></a></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-5-2" class="tab-pane" aria-labelledby="tabset-5-2-tab">
<div class="cell" data-fig.asp="0.5" data-hash="index_cache/html/no_nesting_4b2cadfa87a49c2ef74db78c1be224ec">
<div class="sourceCode" id="cb24" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Parens are vacuous here</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/no_nesting-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-27"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/no_nesting-1.png" class="img-fluid figure-img" style="width:100.0%"></a></p>
</figure>
</div>
</div>
</div>
</div>
</div>
</div>
<p>If you don’t use <code><a href="https://patchwork.data-imaginist.com/reference/wrap_plots.html">wrap_plots()</a></code>, the nesting behavior with <code>+</code> is a little unintuitive. With a single plot on the left of <code>+</code> and a composite plot on the right, you get the expected nesting, with the composite plot taking up <em>half</em> of the whole plot:</p>
<div class="cell" data-fig.asp="0.5" data-hash="index_cache/html/unnamed-chunk-14_9b36fb61ffd4f9845ad4819046d37700">
<div class="sourceCode" id="cb25" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">composite</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">composite</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-14-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-14"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/unnamed-chunk-14-1.png" class="img-fluid figure-img" style="width:100.0%"></a></p>
</figure>
</div>
</div>
</div>
<p>So far, so good. But, what if we change the order of arguments around <code>+</code>? All of a sudden, the plot is divided into 3 equal panels!</p>
<div class="cell" data-fig.asp="0.5" data-hash="index_cache/html/unnamed-chunk-15_fcba2d1b1f57e9c9febf7606f3ba5764">
<div class="sourceCode" id="cb26" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">composite</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-15-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-15"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/unnamed-chunk-15-1.png" class="img-fluid figure-img" style="width:100.0%"></a></p>
</figure>
</div>
</div>
</div>
<p>So, <code>+</code> will nest a composite on the right, but will not nest a composite on the left. You can force the reverse of this by using the <code>-</code> operator, which keeps its arguments at the same nesting level—but I personally find the <code><a href="https://patchwork.data-imaginist.com/reference/wrap_plots.html">wrap_plots()</a></code> syntax more intuitive.</p>
<div class="tabset-margin-container"></div><div class="panel-tabset">
<ul class="nav nav-tabs">
<li class="nav-item"><a class="nav-link active" id="tabset-6-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-6-1" aria-controls="tabset-6-1" aria-selected="true"><code>composite - p3</code></a></li>
<li class="nav-item"><a class="nav-link" id="tabset-6-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-6-2" aria-controls="tabset-6-2" aria-selected="false"><code>p3 - composite</code></a></li>
</ul>
<div class="tab-content">
<div id="tabset-6-1" class="tab-pane active" aria-labelledby="tabset-6-1-tab">
<div class="cell" data-fig.asp="0.5" data-hash="index_cache/html/unnamed-chunk-16_46e018c91dc22d4505f278831e996da5">
<div class="sourceCode" id="cb27" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">composite</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-16-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-28"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/unnamed-chunk-16-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-6-2" class="tab-pane" aria-labelledby="tabset-6-2-tab">
<div class="cell" data-fig.asp="0.5" data-hash="index_cache/html/unnamed-chunk-17_0317240887e17ff21a001d01da33a8c9">
<div class="sourceCode" id="cb28" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">composite</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-17-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-29"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/unnamed-chunk-17-1.png" class="img-fluid figure-img" style="width:100.0%"></a></p>
</figure>
</div>
</div>
</div>
</div>
</div>
</div>
</section><section id="alignment-across-multiple-slides" class="level2"><h2 class="anchored" data-anchor-id="alignment-across-multiple-slides">Alignment across multiple slides</h2>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-18_a4c9c0e92abc4483d36adfc13f651ba1">
<details><summary>Some plot theme changes for visibility in the following examples</summary><div class="sourceCode" id="cb29" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>legend.position <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"top"</span>, plot.background <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_blank</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>legend.position <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>, plot.background <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_blank</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>legend.position <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>, plot.background <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_blank</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>legend.position <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"left"</span>, plot.background <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_blank</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</details>
</div>
<p>When including plots in a slideshow, you often get an annoying jerking sensation as you move from one slide to the next:</p>
<div class="cell" data-animation.hook="gifski" data-hash="index_cache/html/unnamed-chunk-19_0d69ac5c31d3aaff0ab1ba7d1a2a3b11">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-19-.gif" class="lightbox" data-gallery="quarto-lightbox-gallery-16"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/unnamed-chunk-19-.gif" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
<p>You can generate aligned plots <code>align_patches</code>. Notice here how the axis labels are aligned with each other across multiple slides.</p>
<div class="cell" data-animation.hook="gifski" data-hash="index_cache/html/unnamed-chunk-20_287d0dfaf568f5e59247caac72d9c40c">
<div class="sourceCode" id="cb30" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plots_aligned</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://patchwork.data-imaginist.com/reference/multipage_align.html">align_patches</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p1</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p2</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p3</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plots_aligned</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/graphics/plot.default.html">plot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-20-.gif" class="lightbox" data-gallery="quarto-lightbox-gallery-17"><img src="https://abraver.github.io/usefulRstuff/posts/patchwork/index_files/figure-html/unnamed-chunk-20-.gif" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
<p>See <a href="https://patchwork.data-imaginist.com/articles/guides/multipage.html">the relevant documentation</a> for more details.</p>
<!-- End content -->
<div id="footer-session-info">
<details><summary>
Session info and package versions
</summary><div class="cell" data-hash="index_cache/html/unnamed-chunk-22_fb543f977d89c37cd242c024ad7be101">
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code> setting  value
 version  R version 4.3.1 (2023-06-16)
 os       macOS Ventura 13.4.1
 system   aarch64, darwin20
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Chicago
 date     2023-07-08
 pandoc   3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Packages ───────────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>           package loadedversion       date         source
          asbutils    0.0.0.9001 2023-07-06          local
               cli         3.6.1 2023-03-23 CRAN (R 4.3.0)
         codetools        0.2-19 2023-02-01 CRAN (R 4.3.1)
        colorspace         2.1-0 2023-01-23 CRAN (R 4.3.0)
            crayon         1.5.2 2022-09-29 CRAN (R 4.3.0)
              crul         1.4.0 2023-05-17 CRAN (R 4.3.0)
              curl         5.0.1 2023-06-07 CRAN (R 4.3.0)
            digest        0.6.31 2022-12-11 CRAN (R 4.3.0)
             dplyr         1.1.2 2023-04-20 CRAN (R 4.3.0)
          ellipsis         0.3.2 2021-04-29 CRAN (R 4.3.0)
          evaluate          0.21 2023-05-05 CRAN (R 4.3.0)
         extrafont          0.19 2023-01-18 CRAN (R 4.3.0)
       extrafontdb           1.0 2012-06-11 CRAN (R 4.3.0)
             fansi         1.0.4 2023-01-22 CRAN (R 4.3.0)
            farver         2.1.1 2022-07-06 CRAN (R 4.3.0)
           fastmap         1.1.1 2023-02-24 CRAN (R 4.3.0)
 fontBitstreamVera         0.1.1 2017-02-01 CRAN (R 4.3.0)
    fontLiberation         0.1.0 2016-10-15 CRAN (R 4.3.0)
        fontquiver         0.2.1 2017-02-01 CRAN (R 4.3.0)
           gdtools         0.3.3 2023-03-27 CRAN (R 4.3.0)
          generics         0.1.3 2022-07-05 CRAN (R 4.3.0)
            gfonts         0.2.0 2023-01-08 CRAN (R 4.3.0)
           ggplot2         3.4.2 2023-04-03 CRAN (R 4.3.0)
            gifski      1.12.0-1 2023-06-08 CRAN (R 4.3.0)
              glue         1.6.2 2022-02-24 CRAN (R 4.3.0)
            gtable         0.3.3 2023-03-21 CRAN (R 4.3.0)
        hrbrthemes         0.8.0 2020-03-06 CRAN (R 4.3.0)
         htmltools         0.5.5 2023-03-23 CRAN (R 4.3.0)
       htmlwidgets         1.6.2 2023-03-17 CRAN (R 4.3.0)
          httpcode         0.3.0 2020-04-10 CRAN (R 4.3.0)
            httpuv        1.6.11 2023-05-11 CRAN (R 4.3.0)
          jsonlite         1.8.4 2022-12-06 CRAN (R 4.3.0)
             knitr          1.43 2023-05-25 CRAN (R 4.3.0)
          labeling         0.4.2 2020-10-20 CRAN (R 4.3.0)
             later         1.3.1 2023-05-02 CRAN (R 4.3.0)
         lifecycle         1.0.3 2022-10-07 CRAN (R 4.3.0)
          magrittr         2.0.3 2022-03-30 CRAN (R 4.3.0)
              mime          0.12 2021-09-28 CRAN (R 4.3.0)
           munsell         0.5.0 2018-06-12 CRAN (R 4.3.0)
    palmerpenguins         0.1.1 2022-08-15 CRAN (R 4.3.0)
         patchwork         1.1.2 2022-08-19 CRAN (R 4.3.0)
            pillar         1.9.0 2023-03-22 CRAN (R 4.3.0)
         pkgconfig         2.0.3 2019-09-22 CRAN (R 4.3.0)
          promises       1.2.0.1 2021-02-11 CRAN (R 4.3.0)
                R6         2.5.1 2021-08-19 CRAN (R 4.3.0)
              ragg         1.2.5 2023-01-12 CRAN (R 4.3.0)
              Rcpp        1.0.10 2023-01-22 CRAN (R 4.3.0)
              renv        0.17.3 2023-04-06 CRAN (R 4.3.0)
             rlang         1.1.1 2023-04-28 CRAN (R 4.3.0)
         rmarkdown          2.21 2023-03-26 CRAN (R 4.3.0)
        rstudioapi          0.14 2022-08-22 CRAN (R 4.3.0)
          Rttf2pt1        1.3.12 2023-01-22 CRAN (R 4.3.0)
            scales         1.2.1 2022-08-20 CRAN (R 4.3.0)
       sessioninfo         1.2.2 2021-12-06 CRAN (R 4.3.0)
             shiny         1.7.4 2022-12-15 CRAN (R 4.3.0)
       systemfonts         1.0.4 2022-02-11 CRAN (R 4.3.0)
       textshaping         0.3.6 2021-10-13 CRAN (R 4.3.0)
            tibble         3.2.1 2023-03-20 CRAN (R 4.3.0)
        tidyselect         1.2.0 2022-10-10 CRAN (R 4.3.0)
              utf8         1.2.3 2023-01-31 CRAN (R 4.3.0)
             vctrs         0.6.2 2023-04-19 CRAN (R 4.3.0)
             withr         2.5.0 2022-03-03 CRAN (R 4.3.0)
              xfun          0.39 2023-04-20 CRAN (R 4.3.0)
            xtable         1.8-4 2019-04-21 CRAN (R 4.3.0)
              yaml         2.3.7 2023-01-23 CRAN (R 4.3.0)</code></pre>
</div>
</div>
</details>
</div>


</section><div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>
<ol>
<li id="fn1"><p>Somewhat annoyingly, the argument order here is <code>tlbr</code>, rather than <code>trbl</code> as in css, which is how my brain works.↩︎</p></li>
</ol></section></div> ]]></description>
  <category>visualization</category>
  <guid>https://abraver.github.io/usefulRstuff/posts/patchwork/index.html</guid>
  <pubDate>Fri, 07 Jul 2023 05:00:00 GMT</pubDate>
</item>
<item>
  <title>Spotlight subsets of data in your plots with gghighlight
</title>
  <dc:creator>Aaron Braver</dc:creator>
  <link>https://abraver.github.io/usefulRstuff/posts/gghighlight/index.html</link>
  <description><![CDATA[ <script src="../../jquery-3.7.0.min.js"></script><script src="../../fold.js"></script><script src="../../move_session_info.js"></script><!-- begin content --><div class="cell" data-hash="index_cache/html/setup_b776bcb1cc19d5561a7dbf474281a81b">
<details><summary>Setup</summary><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://tidyverse.tidyverse.org">tidyverse</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</details>
</div>
<section id="the-problem" class="level2 page-columns page-full"><h2 class="anchored" data-anchor-id="the-problem">The problem</h2>
<p>We often want to make a subset of data stand out from the rest, but doing so manually is a bit tedious. You could, for example, add a logical column to the data <code>highlight</code>, and set a plot aesthetic to make <code>1</code>s in a bright color and <code>0</code>s in grey.</p>
<p>But <code>gghighlight</code> automates this process for <code>ggplot2</code> plots. Let’s look at the life expectancy dataset from <code>gapminder</code>. Even when color-coding by continent, it’s very difficult to pick out individual countries. We can use <code>gghighlight</code>, though, to emphasize countries with the top 10 highest populations:</p>
<div class="page-columns page-full">
<details><summary>Code</summary><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://yutannihilation.github.io/gghighlight/">gghighlight</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">base_plot</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gapminder</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://jennybc.github.io/gapminder/reference/gapminder.html">gapminder</a></span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">year</span>, y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">lifeExp</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">continent</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/geom_path.html">geom_line</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>group <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">country</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">pretty_plot</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">base_plot</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/scale_continuous.html">scale_x_continuous</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>expand <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/expansion.html">expansion</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>mult <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/geom_path.html">geom_line</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>group <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">country</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://yutannihilation.github.io/gghighlight/reference/gghighlight.html">gghighlight</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/Extremes.html">max</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">pop</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, max_highlight <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span>              unhighlighted_params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>,</span>
<span>                                          color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span></span>
<span>              <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>,</span>
<span>              line_label_type <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ggrepel_text"</span>,</span>
<span>              label_params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>                                  hjust <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span>                                  direction <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>,</span>
<span>                                  nudge_x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span>                                  segment.size <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span></span>
<span>              <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">base_plot</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">pretty_plot</span></span></code></pre></div>
</details><div class="cell column-page quarto-layout-panel" data-hash="index_cache/html/unnamed-chunk-3_a0730677d1678b178cb7701e129a8cf6">
<div class="quarto-layout-row quarto-layout-valign-top">
<div class="quarto-figure quarto-figure-center" style="flex-basis: 50.0%;justify-content: center;">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-3-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-1" title="Vanilla ggplot: Too busy to glean any insights"><img src="https://abraver.github.io/usefulRstuff/posts/gghighlight/index_files/figure-html/unnamed-chunk-3-1.png" class="img-fluid figure-img" width="672"></a></p>
<figcaption class="figure-caption">Vanilla <code>ggplot</code>: Too busy to glean any insights</figcaption></figure>
</div>
<div class="quarto-figure quarto-figure-center" style="flex-basis: 50.0%;justify-content: center;">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-3-2.png" class="lightbox" data-gallery="quarto-lightbox-gallery-2" title="Countries with the top 10 highest populations gghighlighted"><img src="https://abraver.github.io/usefulRstuff/posts/gghighlight/index_files/figure-html/unnamed-chunk-3-2.png" class="img-fluid figure-img" width="672"></a></p>
<figcaption class="figure-caption">Countries with the top 10 highest populations <code>gghighlight</code>ed</figcaption></figure>
</div>
</div>
</div>
</div>
</section><section id="gghighlight-basics" class="level2"><h2 class="anchored" data-anchor-id="gghighlight-basics">
<code>gghighlight</code> basics</h2>
<p>Let’s start with the busy plot from above, which we’ve saved as <code>base_plot</code>. The <code><a href="https://yutannihilation.github.io/gghighlight/reference/gghighlight.html">gghighlight()</a></code> function can be added to any <code>ggplot</code>, and requires only a predicate to select the highlighted portion of the data (passed directly to <code><a href="https://dplyr.tidyverse.org/reference/filter.html">dplyr::filter()</a></code>, so anything you can do there is fair game). Here we highlight countries with a population greater than 50 million.<sup>1</sup></p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-4_08a96b3ae8b26f5de706f9c690413a0d">
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">base_plot</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://yutannihilation.github.io/gghighlight/reference/gghighlight.html">gghighlight</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">pop</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">50000000</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-4-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-3"><img src="https://abraver.github.io/usefulRstuff/posts/gghighlight/index_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
<p>Since there are so many un-highlighted lines, it’s quite hard to see what’s happening. We can change the aesthetics of the un-highlighted lines with <code>unhighlighted_params</code>.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-5_b1a00fe3977290a5d6c0c9160ae01fc6">
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">base_plot</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://yutannihilation.github.io/gghighlight/reference/gghighlight.html">gghighlight</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">pop</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">50000000</span>,</span>
<span>              unhighlighted_params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-5-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-4"><img src="https://abraver.github.io/usefulRstuff/posts/gghighlight/index_files/figure-html/unnamed-chunk-5-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
</section><section id="more-complicated-filtering-criteria" class="level2"><h2 class="anchored" data-anchor-id="more-complicated-filtering-criteria">More complicated filtering criteria</h2>
<p>Since the first argument(s) of <code>gghighlight</code> get passed directly to <code>filter</code>, you can include multiple filtering criteria, like population over 50 million and only countries in Asia:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-6_957071608e2dbce79f385080bfe53a22">
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">base_plot</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://yutannihilation.github.io/gghighlight/reference/gghighlight.html">gghighlight</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">pop</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">50000000</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">continent</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Asia"</span>,</span>
<span>              unhighlighted_params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-6-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-5"><img src="https://abraver.github.io/usefulRstuff/posts/gghighlight/index_files/figure-html/unnamed-chunk-6-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
<p>(Note that in this plot, where we have relatively few highlighted lines, <code>gghighlight</code> adds labels for us.)</p>
<p>We can also provide a non-logical predicate to filter by, for example the top ten countries by population. The predicate is used to order the results, and the <code>max_highlight</code> argument determines the top <code>n</code> rows/groups based on that criterion:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-7_cf2b0fae5b299ffb4b9cb0c8a2de0ef7">
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">base_plot</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://yutannihilation.github.io/gghighlight/reference/gghighlight.html">gghighlight</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/Extremes.html">max</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">pop</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, max_highlight <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span>              unhighlighted_params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-7-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-6"><img src="https://abraver.github.io/usefulRstuff/posts/gghighlight/index_files/figure-html/unnamed-chunk-7-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
</section><section id="labels" class="level2 page-columns page-full"><h2 class="anchored" data-anchor-id="labels">Labels</h2>
<p>The labels in the previous plot make things pretty crowded. <code>gghighlight</code> uses the <code><a href="https://rdrr.io/pkg/ggrepel/man/geom_text_repel.html">ggrepel::geom_label_repel</a></code> geom by default, and arguments can be passed to that function with the <code>label_params</code> argument.<sup>2</sup> Here we’ll modify <code>max.overlaps</code>, which removes some labels when there are too many overlapping objects:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-8_a13e9829a3f1e882b2f0e1266e7aea0b">
<div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">base_plot</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://yutannihilation.github.io/gghighlight/reference/gghighlight.html">gghighlight</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/Extremes.html">max</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">pop</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, max_highlight <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span>              unhighlighted_params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>,</span>
<span>              label_params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>                max.overlaps <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span></span>
<span>              <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-8-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-7"><img src="https://abraver.github.io/usefulRstuff/posts/gghighlight/index_files/figure-html/unnamed-chunk-8-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
<p>What if we want to have all of the labels off on one side, rather than on top of the plotted data? We can once again avail ourselves of <code>label_params</code>. I also prefer the labels to be text only—no border—which is accomplished with <code>line_label_type = "ggrepel_text"</code>.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-9_81b5c908b492899d9a08e0033229ac98">
<div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">base_plot</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://yutannihilation.github.io/gghighlight/reference/gghighlight.html">gghighlight</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/Extremes.html">max</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">pop</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, max_highlight <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span>    unhighlighted_params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>,</span>
<span>    line_label_type <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ggrepel_text"</span>,</span>
<span>    label_params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>      hjust <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># align label text</span></span>
<span>      direction <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># allow shifting labels on y axis to make room</span></span>
<span>      nudge_x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># push everything further to the right</span></span>
<span>      segment.size <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># make pointing lines thinner</span></span>
<span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-9-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-8"><img src="https://abraver.github.io/usefulRstuff/posts/gghighlight/index_files/figure-html/unnamed-chunk-9-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
<p>One final tweak is to expand the plot rightward, so there is more room for labels. This is done by modifying the scale of the plot, as below. (I have not found a good way to make the labels appear in the margin)</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-10_2a24bb76d1603b1b5a04be40c41f1e6e">
<div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">base_plot</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Modify scale:</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/scale_continuous.html">scale_x_continuous</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>expand <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/expansion.html">expansion</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>mult <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://yutannihilation.github.io/gghighlight/reference/gghighlight.html">gghighlight</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/Extremes.html">max</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">pop</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, max_highlight <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span>    unhighlighted_params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>,</span>
<span>    line_label_type <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ggrepel_text"</span>,</span>
<span>    label_params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>      hjust <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># align label text</span></span>
<span>      direction <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># allow shifting labels on y axis to make room</span></span>
<span>      nudge_x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># push everything further to the right</span></span>
<span>      segment.size <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># make pointing lines thinner</span></span>
<span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-10-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-9"><img src="https://abraver.github.io/usefulRstuff/posts/gghighlight/index_files/figure-html/unnamed-chunk-10-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
<p>You’ll notice that in the plot above, the labels are drawn <em>inside</em> the plotting area, and not in the margin. I have not found a good way to make the labels in the margin only. The closest built-in option to <code>gghighlight</code> is to set <code>line_label_type = "sec_axis"</code> instead of <code>"ggrepel_text"</code>, but this does not prevent the labels from overlapping each other (since it’s not using <code>ggrepel</code> anymore). This is ok in a plot with only a few—or very spaced out—labels, but doesn’t work well for our current plot. You can see in the second plot below that it looks pretty good when we select, say, only the top 3 countries by population.</p>
<div class="page-columns page-full">
<div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">base_plot</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://yutannihilation.github.io/gghighlight/reference/gghighlight.html">gghighlight</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/Extremes.html">max</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">pop</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, max_highlight <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span>    unhighlighted_params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>,</span>
<span>    line_label_type <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sec_axis"</span></span>
<span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">base_plot</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://yutannihilation.github.io/gghighlight/reference/gghighlight.html">gghighlight</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/Extremes.html">max</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">pop</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, max_highlight <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ***</span></span>
<span>    unhighlighted_params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>,</span>
<span>    line_label_type <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sec_axis"</span></span>
<span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell column-page quarto-layout-panel" data-hash="index_cache/html/unnamed-chunk-11_49abe6911bbe5df09f4d867342e2f8dd">
<div class="quarto-layout-row quarto-layout-valign-top">
<div class="quarto-figure quarto-figure-center" style="flex-basis: 50.0%;justify-content: center;">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-11-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-10"><img src="https://abraver.github.io/usefulRstuff/posts/gghighlight/index_files/figure-html/unnamed-chunk-11-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
<div class="quarto-figure quarto-figure-center" style="flex-basis: 50.0%;justify-content: center;">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-11-2.png" class="lightbox" data-gallery="quarto-lightbox-gallery-11"><img src="https://abraver.github.io/usefulRstuff/posts/gghighlight/index_files/figure-html/unnamed-chunk-11-2.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
</div>
</section><section id="other-geoms" class="level2"><h2 class="anchored" data-anchor-id="other-geoms">Other geoms</h2>
<p><code>gghighlight</code> works on geoms other than <code>line</code>, and in fact looks pretty snazzy in barplots/histograms plotted by group, where there is a lot of overlap. In the highlighted plot we facet by continent, but also show the overall distribution in gray.</p>
<div class="tabset-margin-container"></div><div class="panel-tabset">
<ul class="nav nav-tabs">
<li class="nav-item"><a class="nav-link active" id="tabset-1-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-1" aria-controls="tabset-1-1" aria-selected="true">Highlighting</a></li>
<li class="nav-item"><a class="nav-link" id="tabset-1-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-2" aria-controls="tabset-1-2" aria-selected="false">No highlighting</a></li>
</ul>
<div class="tab-content">
<div id="tabset-1-1" class="tab-pane active" aria-labelledby="tabset-1-1-tab">
<div class="cell" data-hash="index_cache/html/unnamed-chunk-12_64ec42da78caa350d321c7f8a099bbfb">
<div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gapminder</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://jennybc.github.io/gapminder/reference/gapminder.html">gapminder</a></span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">lifeExp</span>, fill <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">continent</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/geom_histogram.html">geom_histogram</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/facet_wrap.html">facet_wrap</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">continent</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://yutannihilation.github.io/gghighlight/reference/gghighlight.html">gghighlight</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-12-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-14"><img src="https://abraver.github.io/usefulRstuff/posts/gghighlight/index_files/figure-html/unnamed-chunk-12-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-1-2" class="tab-pane" aria-labelledby="tabset-1-2-tab">
<div class="cell" data-hash="index_cache/html/unnamed-chunk-13_8241e140e38d439b729ee30bdc005eb9">
<div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gapminder</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://jennybc.github.io/gapminder/reference/gapminder.html">gapminder</a></span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">lifeExp</span>, fill <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">continent</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/geom_histogram.html">geom_histogram</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-13-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-15"><img src="https://abraver.github.io/usefulRstuff/posts/gghighlight/index_files/figure-html/unnamed-chunk-13-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
</div>
</div>
</div>
<p>And with <code>geom_point</code>, for example, we can call out the top ten countries by population in the data from 2002:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-14_fc195a459c4c153b6cbca730b59c58ca">
<div class="sourceCode" id="cb13" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gapminder</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://jennybc.github.io/gapminder/reference/gapminder.html">gapminder</a></span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">year</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2002</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">lifeExp</span>, y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">pop</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">country</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/geom_point.html">geom_point</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>group <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://yutannihilation.github.io/gghighlight/reference/gghighlight.html">gghighlight</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/Extremes.html">max</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">pop</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, max_highlight <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span>              label_key <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">country</span>,</span>
<span>              label_params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>                max.overlaps <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span>              <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning: ggrepel: 6 unlabeled data points (too many overlaps). Consider
increasing max.overlaps</code></pre>
</div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-14-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-12"><img src="https://abraver.github.io/usefulRstuff/posts/gghighlight/index_files/figure-html/unnamed-chunk-14-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
<p>Note above that we’re warned that there were “too many overlaps,” and therefore some labels are omitted. In fact, if there are too many overlapping data points, all labels will be omitted You can remedy this by either having fewer highlighted points and/or changing <code>max.overlaps</code>.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-15_5d277e96fcbd976004e6cd3af4b53a07">
<div class="sourceCode" id="cb15" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gapminder</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://jennybc.github.io/gapminder/reference/gapminder.html">gapminder</a></span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">year</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2002</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">lifeExp</span>, y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">pop</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">country</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/geom_point.html">geom_point</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>group <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://yutannihilation.github.io/gghighlight/reference/gghighlight.html">gghighlight</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/Extremes.html">max</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">pop</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, max_highlight <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span>              label_key <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">country</span>,</span>
<span>              label_params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>                max.overlaps <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span></span>
<span>              <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-15-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-13"><img src="https://abraver.github.io/usefulRstuff/posts/gghighlight/index_files/figure-html/unnamed-chunk-15-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
<!-- End content -->
<div id="footer-session-info">
<details><summary>
Session info and package versions
</summary><div class="cell" data-hash="index_cache/html/unnamed-chunk-17_e4c39ad0395e7aa68e02447d84d00b77">
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code> setting  value
 version  R version 4.3.1 (2023-06-16)
 os       macOS Ventura 13.4.1
 system   aarch64, darwin20
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Chicago
 date     2023-07-08
 pandoc   3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Packages ───────────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>           package loadedversion       date         source
          asbutils    0.0.0.9001 2023-07-06          local
               cli         3.6.1 2023-03-23 CRAN (R 4.3.0)
         codetools        0.2-19 2023-02-01 CRAN (R 4.3.1)
        colorspace         2.1-0 2023-01-23 CRAN (R 4.3.0)
            crayon         1.5.2 2022-09-29 CRAN (R 4.3.0)
              crul         1.4.0 2023-05-17 CRAN (R 4.3.0)
              curl         5.0.1 2023-06-07 CRAN (R 4.3.0)
            digest        0.6.31 2022-12-11 CRAN (R 4.3.0)
             dplyr         1.1.2 2023-04-20 CRAN (R 4.3.0)
          ellipsis         0.3.2 2021-04-29 CRAN (R 4.3.0)
          evaluate          0.21 2023-05-05 CRAN (R 4.3.0)
         extrafont          0.19 2023-01-18 CRAN (R 4.3.0)
       extrafontdb           1.0 2012-06-11 CRAN (R 4.3.0)
             fansi         1.0.4 2023-01-22 CRAN (R 4.3.0)
            farver         2.1.1 2022-07-06 CRAN (R 4.3.0)
           fastmap         1.1.1 2023-02-24 CRAN (R 4.3.0)
 fontBitstreamVera         0.1.1 2017-02-01 CRAN (R 4.3.0)
    fontLiberation         0.1.0 2016-10-15 CRAN (R 4.3.0)
        fontquiver         0.2.1 2017-02-01 CRAN (R 4.3.0)
           forcats         1.0.0 2023-01-29 CRAN (R 4.3.0)
         gapminder         1.0.0 2023-03-10 CRAN (R 4.3.0)
           gdtools         0.3.3 2023-03-27 CRAN (R 4.3.0)
          generics         0.1.3 2022-07-05 CRAN (R 4.3.0)
            gfonts         0.2.0 2023-01-08 CRAN (R 4.3.0)
       gghighlight         0.4.0 2022-10-16 CRAN (R 4.3.0)
           ggplot2         3.4.2 2023-04-03 CRAN (R 4.3.0)
           ggrepel         0.9.3 2023-02-03 CRAN (R 4.3.0)
              glue         1.6.2 2022-02-24 CRAN (R 4.3.0)
            gtable         0.3.3 2023-03-21 CRAN (R 4.3.0)
               hms         1.1.3 2023-03-21 CRAN (R 4.3.0)
        hrbrthemes         0.8.0 2020-03-06 CRAN (R 4.3.0)
         htmltools         0.5.5 2023-03-23 CRAN (R 4.3.0)
       htmlwidgets         1.6.2 2023-03-17 CRAN (R 4.3.0)
          httpcode         0.3.0 2020-04-10 CRAN (R 4.3.0)
            httpuv        1.6.11 2023-05-11 CRAN (R 4.3.0)
          jsonlite         1.8.4 2023-06-29 CRAN (R 4.3.0)
             knitr          1.43 2023-05-25 CRAN (R 4.3.0)
          labeling         0.4.2 2020-10-20 CRAN (R 4.3.0)
             later         1.3.1 2023-05-02 CRAN (R 4.3.0)
         lifecycle         1.0.3 2022-10-07 CRAN (R 4.3.0)
         lubridate         1.9.2 2023-02-10 CRAN (R 4.3.0)
          magrittr         2.0.3 2022-03-30 CRAN (R 4.3.0)
              mime          0.12 2021-09-28 CRAN (R 4.3.0)
           munsell         0.5.0 2018-06-12 CRAN (R 4.3.0)
            pillar         1.9.0 2023-03-22 CRAN (R 4.3.0)
         pkgconfig         2.0.3 2019-09-22 CRAN (R 4.3.0)
          promises       1.2.0.1 2021-02-11 CRAN (R 4.3.0)
             purrr         1.0.1 2023-01-10 CRAN (R 4.3.0)
                R6         2.5.1 2021-08-19 CRAN (R 4.3.0)
              ragg         1.2.5 2023-01-12 CRAN (R 4.3.0)
              Rcpp        1.0.10 2023-01-22 CRAN (R 4.3.0)
             readr         2.1.4 2023-02-10 CRAN (R 4.3.0)
              renv        0.17.3 2023-04-06 CRAN (R 4.3.0)
             rlang         1.1.1 2023-04-28 CRAN (R 4.3.0)
         rmarkdown          2.21 2023-06-01 CRAN (R 4.3.0)
        rstudioapi          0.14 2022-08-22 CRAN (R 4.3.0)
          Rttf2pt1        1.3.12 2023-01-22 CRAN (R 4.3.0)
            scales         1.2.1 2022-08-20 CRAN (R 4.3.0)
       sessioninfo         1.2.2 2021-12-06 CRAN (R 4.3.0)
             shiny         1.7.4 2022-12-15 CRAN (R 4.3.0)
           stringi        1.7.12 2023-01-11 CRAN (R 4.3.0)
           stringr         1.5.0 2022-12-02 CRAN (R 4.3.0)
       systemfonts         1.0.4 2022-02-11 CRAN (R 4.3.0)
       textshaping         0.3.6 2021-10-13 CRAN (R 4.3.0)
            tibble         3.2.1 2023-03-20 CRAN (R 4.3.0)
             tidyr         1.3.0 2023-01-24 CRAN (R 4.3.0)
        tidyselect         1.2.0 2022-10-10 CRAN (R 4.3.0)
         tidyverse         2.0.0 2023-02-22 CRAN (R 4.3.0)
        timechange         0.2.0 2023-01-11 CRAN (R 4.3.0)
              tzdb         0.3.0 2023-05-12 CRAN (R 4.3.0)
              utf8         1.2.3 2023-01-31 CRAN (R 4.3.0)
             vctrs         0.6.2 2023-06-14 CRAN (R 4.3.0)
             withr         2.5.0 2022-03-03 CRAN (R 4.3.0)
              xfun          0.39 2023-04-20 CRAN (R 4.3.0)
            xtable         1.8-4 2019-04-21 CRAN (R 4.3.0)
              yaml         2.3.7 2023-01-23 CRAN (R 4.3.0)</code></pre>
</div>
</div>
</details>
</div>


</section><div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>
<ol>
<li id="fn1"><p>NB: unless you set <code>use_direct_label = FALSE</code>, the legend will not be included in a highlighted plot. Also, if you want the colors to match an unhighlighted version of the plot, use <code>keep_scales = TRUE</code>.↩︎</p></li>
<li id="fn2"><p>See the <code>geom_label_repel</code> documentation for more options.↩︎</p></li>
</ol></section></div> ]]></description>
  <category>visualization</category>
  <guid>https://abraver.github.io/usefulRstuff/posts/gghighlight/index.html</guid>
  <pubDate>Thu, 06 Jul 2023 05:00:00 GMT</pubDate>
</item>
<item>
  <title>
khroma and colorblindr: Tools for colorblind-friendly plots</title>
  <dc:creator>Aaron Braver</dc:creator>
  <link>https://abraver.github.io/usefulRstuff/posts/khroma/index.html</link>
  <description><![CDATA[ <script src="../../jquery-3.7.0.min.js"></script><script src="../../fold.js"></script><script src="../../move_session_info.js"></script><!-- begin content --><div class="cell" data-hash="index_cache/html/setup_595abedba9a11dd4a6248900d6ba183e">
<details><summary>Load packages</summary><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org">dplyr</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org">ggplot2</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</details>
</div>
<section id="khroma---colorblind-friendly-palettes" class="level2"><h2 class="anchored" data-anchor-id="khroma---colorblind-friendly-palettes">
<code>khroma</code> - colorblind-friendly palettes</h2>
<p><a href="https://packages.tesselle.org/khroma/"><code>khroma</code></a> contains a number of color schemes that are colorblind-friendly, divided into diverging, qualitative, and sequential types:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-3_958e08d567d21135652c2e5163db29a5">
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">khroma</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://packages.tesselle.org/khroma/reference/info.html">info</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/summarise.html">summarize</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>palettes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/paste.html">paste</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">palette</span>, collapse <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="kable-table">
<table class="table table-sm table-striped small">
<colgroup>
<col style="width: 5%">
<col style="width: 94%">
</colgroup>
<thead><tr class="header">
<th style="text-align: left;">type</th>
<th style="text-align: left;">palettes</th>
</tr></thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">diverging</td>
<td style="text-align: left;">broc, cork, vik, lisbon, tofino, berlin, roma, bam, vanimo, oleron, bukavu, fes, sunset, BuRd, PRGn</td>
</tr>
<tr class="even">
<td style="text-align: left;">qualitative</td>
<td style="text-align: left;">bright, highcontrast, vibrant, muted, mediumcontrast, pale, dark, light, okabeito, okabeitoblack, stratigraphy, soil, land</td>
</tr>
<tr class="odd">
<td style="text-align: left;">sequential</td>
<td style="text-align: left;">devon, lajolla, bamako, davos, bilbao, nuuk, oslo, grayC, hawaii, lapaz, tokyo, buda, acton, turku, imola, batlow, batlowW, batlowK, brocO, corkO, vikO, romaO, bamO, YlOrBr, iridescent, discreterainbow, smoothrainbow</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>The <code>color</code> function takes a palette name and returns a function, which in turn returns a palette of specified size:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-4_abf3629c2d138aa659e4cb76f7359099">
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://packages.tesselle.org/khroma/">khroma</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bright_fun</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://packages.tesselle.org/khroma/reference/colour.html">color</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bright"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bright_fun</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>     blue       red     green    yellow      cyan 
"#4477AA" "#EE6677" "#228833" "#CCBB44" "#66CCEE" 
attr(,"missing")
[1] NA</code></pre>
</div>
</div>
<p>And you can preview these palettes with <code><a href="https://packages.tesselle.org/khroma/reference/plot.html">plot_scheme()</a></code>:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-5_f7aa5e8e80c121240bbbd0165394e4d9">
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://packages.tesselle.org/khroma/reference/plot.html">plot_scheme</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bright_fun</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, names <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span>            colours <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># NB: `colours` must be spelled British-ly</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-5-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-1"><img src="https://abraver.github.io/usefulRstuff/posts/khroma/index_files/figure-html/unnamed-chunk-5-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
<p>Further, you can preview the palette as viewed by several types of colorblindness:</p>
<div class="cell fold o" data-hash="index_cache/html/unnamed-chunk-6_ac3a79bf41c5580710d0d4beb5a34fc7">
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://packages.tesselle.org/khroma/reference/plot.html">plot_scheme_colorblind</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bright_fun</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-6-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-2"><img src="https://abraver.github.io/usefulRstuff/posts/khroma/index_files/figure-html/unnamed-chunk-6-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
<p><br></p>
<p>Each of the schemes have built-in <code>ggplot</code> scales in the form <code>scale_color_{palettename}</code> and <code>scale_fill_{palettename}</code>:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-7_cc902cc69122d7120e2d52bbb0e65c46">
<div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">midwest</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">percbelowpoverty</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">percollege</span>, y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">percbelowpoverty</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">state</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/geom_point.html">geom_point</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>size <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://packages.tesselle.org/khroma/reference/scale_tol_bright.html">scale_color_bright</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><figcaption class="figure-caption">Percent of population with a college degree vs.&nbsp;percent of population below the poverty line, by state. Data from <code><a href="https://ggplot2.tidyverse.org/reference/midwest.html">ggplot2::midwest</a></code></figcaption><p><a href="index_files/figure-html/unnamed-chunk-7-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-3" title="Percent of population with a college degree vs.&nbsp;percent of population below the poverty line, by state. Data from ggplot2::midwest"><img src="https://abraver.github.io/usefulRstuff/posts/khroma/index_files/figure-html/unnamed-chunk-7-1.png" class="img-fluid figure-img" alt="Percent of population with a college degree vs. percent of population below the poverty line, by state.  Data from `ggplot2::midwest`" width="672"></a></p>
</figure>
</div>
</div>
</div>
<p>(NB: you can use the <em>sequential</em> and <em>diverging</em> type palettes for discrete/categorical data if you add the argument <code>discrete = TRUE</code>)</p>
</section><section id="colorblindr---preview-your-plots-with-colorblind-simulation" class="level2"><h2 class="anchored" data-anchor-id="colorblindr---preview-your-plots-with-colorblind-simulation">
<code>colorblindr</code> - Preview your plots with colorblind simulation</h2>
<p><code><a href="https://rdrr.io/pkg/colorblindr/man/cvd_grid.html">colorblindr::cvd_grid</a></code> will simulate how your plots will look to people with various types of colorblindness:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-8_8a6e19f28ff070ca7f87e78965630a3d">
<div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># remotes::install_github("clauswilke/colorblindr")</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">msleep</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/NA.html">is.na</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">vore</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sleep_rem</span>, fill <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">vore</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/geom_density.html">geom_density</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://packages.tesselle.org/khroma/reference/scale_tol_light.html">scale_fill_light</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot</span></span>
<span></span>
<span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colorblindr</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/colorblindr/man/cvd_grid.html">cvd_grid</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><figcaption class="figure-caption">Density of hours of REM sleep, for carnivores, omnivores, herbivores, and insectivores. Data from the mammal sleep dataset (<code>ggplot::msleep</code>).</figcaption><p><a href="index_files/figure-html/unnamed-chunk-8-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-4" title="Density of hours of REM sleep, for carnivores, omnivores, herbivores, and insectivores. Data from the mammal sleep dataset (ggplot::msleep)."><img src="https://abraver.github.io/usefulRstuff/posts/khroma/index_files/figure-html/unnamed-chunk-8-1.png" class="img-fluid figure-img" width="960"></a></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><figcaption class="figure-caption">The same plot in various simulations of colorblindness</figcaption><p><a href="index_files/figure-html/unnamed-chunk-8-2.png" class="lightbox" data-gallery="quarto-lightbox-gallery-5" title="The same plot in various simulations of colorblindness"><img src="https://abraver.github.io/usefulRstuff/posts/khroma/index_files/figure-html/unnamed-chunk-8-2.png" class="img-fluid figure-img" width="960"></a></p>
</figure>
</div>
</div>
</div>
<!-- End content -->
<div id="footer-session-info">
<details><summary>
Session info and package versions
</summary><div class="cell" data-hash="index_cache/html/unnamed-chunk-10_f95d2683f6418068e78022ec6f59d533">
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code> setting  value
 version  R version 4.3.1 (2023-06-16)
 os       macOS Ventura 13.4.1
 system   aarch64, darwin20
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Chicago
 date     2023-07-08
 pandoc   3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Packages ───────────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>           package loadedversion       date         source
          asbutils    0.0.0.9001 2023-07-06          local
               cli         3.6.1 2023-03-23 CRAN (R 4.3.0)
         codetools        0.2-19 2023-02-01 CRAN (R 4.3.1)
       colorblindr         0.1.0 2023-07-05         Github
        colorspace         2.1-0 2023-01-23 CRAN (R 4.3.0)
           cowplot         1.1.1 2020-12-30 CRAN (R 4.3.0)
            crayon         1.5.2 2022-09-29 CRAN (R 4.3.0)
              crul         1.4.0 2023-05-17 CRAN (R 4.3.0)
              curl         5.0.1 2023-06-07 CRAN (R 4.3.0)
            digest        0.6.31 2022-12-11 CRAN (R 4.3.0)
             dplyr         1.1.2 2023-04-20 CRAN (R 4.3.0)
          ellipsis         0.3.2 2021-04-29 CRAN (R 4.3.0)
          evaluate          0.21 2023-05-05 CRAN (R 4.3.0)
         extrafont          0.19 2023-01-18 CRAN (R 4.3.0)
       extrafontdb           1.0 2012-06-11 CRAN (R 4.3.0)
             fansi         1.0.4 2023-01-22 CRAN (R 4.3.0)
            farver         2.1.1 2022-07-06 CRAN (R 4.3.0)
           fastmap         1.1.1 2023-02-24 CRAN (R 4.3.0)
 fontBitstreamVera         0.1.1 2017-02-01 CRAN (R 4.3.0)
    fontLiberation         0.1.0 2016-10-15 CRAN (R 4.3.0)
        fontquiver         0.2.1 2017-02-01 CRAN (R 4.3.0)
           gdtools         0.3.3 2023-03-27 CRAN (R 4.3.0)
          generics         0.1.3 2022-07-05 CRAN (R 4.3.0)
            gfonts         0.2.0 2023-01-08 CRAN (R 4.3.0)
           ggplot2         3.4.2 2023-04-03 CRAN (R 4.3.0)
              glue         1.6.2 2022-02-24 CRAN (R 4.3.0)
            gtable         0.3.3 2023-03-21 CRAN (R 4.3.0)
        hrbrthemes         0.8.0 2020-03-06 CRAN (R 4.3.0)
         htmltools         0.5.5 2023-03-23 CRAN (R 4.3.0)
       htmlwidgets         1.6.2 2023-03-17 CRAN (R 4.3.0)
          httpcode         0.3.0 2020-04-10 CRAN (R 4.3.0)
            httpuv        1.6.11 2023-05-11 CRAN (R 4.3.0)
          jsonlite         1.8.7 2023-06-29 CRAN (R 4.3.0)
            khroma        1.10.0 2023-04-17 CRAN (R 4.3.0)
             knitr          1.43 2023-05-25 CRAN (R 4.3.0)
          labeling         0.4.2 2020-10-20 CRAN (R 4.3.0)
             later         1.3.1 2023-05-02 CRAN (R 4.3.0)
         lifecycle         1.0.3 2022-10-07 CRAN (R 4.3.0)
          magrittr         2.0.3 2022-03-30 CRAN (R 4.3.0)
              mime          0.12 2021-09-28 CRAN (R 4.3.0)
           munsell         0.5.0 2018-06-12 CRAN (R 4.3.0)
            pillar         1.9.0 2023-03-22 CRAN (R 4.3.0)
         pkgconfig         2.0.3 2019-09-22 CRAN (R 4.3.0)
          promises       1.2.0.1 2021-02-11 CRAN (R 4.3.0)
                R6         2.5.1 2021-08-19 CRAN (R 4.3.0)
              ragg         1.2.5 2023-01-12 CRAN (R 4.3.0)
              Rcpp        1.0.10 2023-01-22 CRAN (R 4.3.0)
              renv        0.17.3 2023-04-06 CRAN (R 4.3.0)
             rlang         1.1.1 2023-04-28 CRAN (R 4.3.0)
         rmarkdown          2.22 2023-06-01 CRAN (R 4.3.0)
        rstudioapi          0.14 2022-08-22 CRAN (R 4.3.0)
          Rttf2pt1        1.3.12 2023-01-22 CRAN (R 4.3.0)
            scales         1.2.1 2022-08-20 CRAN (R 4.3.0)
       sessioninfo         1.2.2 2021-12-06 CRAN (R 4.3.0)
             shiny         1.7.4 2022-12-15 CRAN (R 4.3.0)
       systemfonts         1.0.4 2022-02-11 CRAN (R 4.3.0)
       textshaping         0.3.6 2021-10-13 CRAN (R 4.3.0)
            tibble         3.2.1 2023-03-20 CRAN (R 4.3.0)
        tidyselect         1.2.0 2022-10-10 CRAN (R 4.3.0)
              utf8         1.2.3 2023-01-31 CRAN (R 4.3.0)
             vctrs         0.6.3 2023-06-14 CRAN (R 4.3.0)
             withr         2.5.0 2022-03-03 CRAN (R 4.3.0)
              xfun          0.39 2023-04-20 CRAN (R 4.3.0)
            xtable         1.8-4 2019-04-21 CRAN (R 4.3.0)
              yaml         2.3.7 2023-01-23 CRAN (R 4.3.0)</code></pre>
</div>
</div>
</details>
</div>


</section> ]]></description>
  <category>visualization</category>
  <category>colors</category>
  <guid>https://abraver.github.io/usefulRstuff/posts/khroma/index.html</guid>
  <pubDate>Tue, 04 Jul 2023 05:00:00 GMT</pubDate>
</item>
<item>
  <title>Paginate a faceted graph and save as a single multi-page PDF</title>
  <dc:creator>Aaron Braver</dc:creator>
  <link>https://abraver.github.io/usefulRstuff/posts/paginate_faceted_graphs/index.html</link>
  <description><![CDATA[ <script src="../../jquery-3.7.0.min.js"></script><script src="../../fold.js"></script><script src="../../move_session_info.js"></script><!-- begin content --><p>When you have a plot with just a few facets, it’s easy to fit them all on a single page. But what if you have a whole bunch of facets that you want to visualize? For example, the <code>USArrests</code> dataset has data from all 50 US states.</p>
<p>If we just use the usual <code>facet_wrap</code> or <code>facet_grid</code> from <code>ggplot2</code>, you end up with one massive, smooshed-together image:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-3_52fccedd5623c1b3af8e4446d2e025eb">
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://tidyverse.tidyverse.org">tidyverse</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot_1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">USArrests</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># dataset on US arrests</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://tibble.tidyverse.org/reference/rownames.html">rownames_to_column</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"State"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span>   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># This is just so we can see the state names</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">UrbanPop</span>, y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">Murder</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/geom_point.html">geom_point</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/facet_wrap.html">facet_wrap</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">State</span>,</span>
<span>             nrow <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, ncol <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot_1</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-3-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-1"><img src="https://abraver.github.io/usefulRstuff/posts/paginate_faceted_graphs/index_files/figure-html/unnamed-chunk-3-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
<p>The <a href="https://ggforce.data-imaginist.com"><code>ggforce</code></a> library, among its many useful functions, includes <code>facet_wrap_paginate</code> and <code>facet_grid_paginate</code>. These work like <code>facet_wrap</code> and <code>facet_grid</code>, but take an additional <code>page</code> argument. Here we specify that we want 4 rows and 5 columns per page, so for 50 states there will be 2 full pages plus one page with the remaining 10 states:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-4_d8421f0354f96113226db1d1dd04e278">
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://ggforce.data-imaginist.com">ggforce</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot_2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot_1</span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggforce.data-imaginist.com/reference/facet_wrap_paginate.html">facet_wrap_paginate</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">State</span>,</span>
<span>             nrow <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, ncol <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, page <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot_2</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-4-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-2"><img src="https://abraver.github.io/usefulRstuff/posts/paginate_faceted_graphs/index_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
<p>Note that we had to specify which page we wanted to print. We can then easily put this into a loop to generate all the necessary pages. The helpful <code><a href="https://ggforce.data-imaginist.com/reference/n_pages.html">n_pages()</a></code> will count the pages needed, which we can then use in a loop. This gives us 3 separate plots.</p>
<div class="cell fold o g" data-hash="index_cache/html/unnamed-chunk-6_cd188727526c8f5e7b9cb54296cabe60">
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot_pages</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot_2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggforce.data-imaginist.com/reference/n_pages.html">n_pages</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">i</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot_pages</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/print.html">print</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>    <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot_1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggforce.data-imaginist.com/reference/facet_wrap_paginate.html">facet_wrap_paginate</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">State</span>,</span>
<span>             nrow <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, ncol <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, page <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">i</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>  </span>
<span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span></code></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-6-1.png" class="lightbox" data-gallery="these"><img src="https://abraver.github.io/usefulRstuff/posts/paginate_faceted_graphs/index_files/figure-html/unnamed-chunk-6-1.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-6-2.png" class="lightbox" data-gallery="these"><img src="https://abraver.github.io/usefulRstuff/posts/paginate_faceted_graphs/index_files/figure-html/unnamed-chunk-6-2.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="index_files/figure-html/unnamed-chunk-6-3.png" class="lightbox" data-gallery="these"><img src="https://abraver.github.io/usefulRstuff/posts/paginate_faceted_graphs/index_files/figure-html/unnamed-chunk-6-3.png" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
<p><br></p>
<p>That’s better, but for inclusion in a longer document or for sharing the plot, you may want all three pages in a single PDF. This can be accomplished by calling <code><a href="https://rdrr.io/r/grDevices/pdf.html">pdf()</a></code> before the loop and <code><a href="https://rdrr.io/r/grDevices/dev.html">dev.off()</a></code> after.<sup>1</sup></p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-7_3653771f1a0701bd9183eff1a4073de1">
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/grDevices/pdf.html">pdf</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'many_plots.pdf'</span>, width <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>, height <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">8.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#start building pdf</span></span>
<span>  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">i</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot_pages</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/print.html">print</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># don't forget this</span></span>
<span>      <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot_1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggforce.data-imaginist.com/reference/facet_wrap_paginate.html">facet_wrap_paginate</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">State</span>, nrow <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, ncol <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, page <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">i</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/grDevices/dev.html">dev.off</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># end building pdf</span></span></code></pre></div>
</div>
<p>The <a href="many_plots.pdf">resulting PDF</a> is a single file with 3 pages, as we expect.</p>
<p>(This post was inspired by <a href="https://stackoverflow.com/questions/48544039/how-to-save-output-from-ggforcefacet-grid-paginate-in-only-one-pdf">this conversation on StackOverflow</a>.)</p>
<!-- End content -->
<div id="footer-session-info">
<details><summary>
Session info and package versions
</summary><div class="cell" data-hash="index_cache/html/unnamed-chunk-9_e9175bd67460e15c5615e5268fb63de0">
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code> setting  value
 version  R version 4.3.1 (2023-06-16)
 os       macOS Ventura 13.4.1
 system   aarch64, darwin20
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Chicago
 date     2023-07-08
 pandoc   3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Packages ───────────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>           package loadedversion       date         source
          asbutils    0.0.0.9001 2023-07-06          local
               cli         3.6.1 2023-03-23 CRAN (R 4.3.0)
         codetools        0.2-19 2023-02-01 CRAN (R 4.3.1)
        colorspace         2.1-0 2023-01-23 CRAN (R 4.3.0)
            crayon         1.5.2 2022-09-29 CRAN (R 4.3.0)
              crul         1.4.0 2023-05-17 CRAN (R 4.3.0)
              curl         5.0.1 2023-06-07 CRAN (R 4.3.0)
            digest        0.6.31 2022-12-11 CRAN (R 4.3.0)
             dplyr         1.1.2 2023-04-20 CRAN (R 4.3.0)
          ellipsis         0.3.2 2021-04-29 CRAN (R 4.3.0)
          evaluate          0.21 2023-05-05 CRAN (R 4.3.0)
         extrafont          0.19 2023-01-18 CRAN (R 4.3.0)
       extrafontdb           1.0 2012-06-11 CRAN (R 4.3.0)
             fansi         1.0.4 2023-01-22 CRAN (R 4.3.0)
            farver         2.1.1 2022-07-06 CRAN (R 4.3.0)
           fastmap         1.1.1 2023-02-24 CRAN (R 4.3.0)
 fontBitstreamVera         0.1.1 2017-02-01 CRAN (R 4.3.0)
    fontLiberation         0.1.0 2016-10-15 CRAN (R 4.3.0)
        fontquiver         0.2.1 2017-02-01 CRAN (R 4.3.0)
           forcats         1.0.0 2023-01-29 CRAN (R 4.3.0)
           gdtools         0.3.3 2023-03-27 CRAN (R 4.3.0)
          generics         0.1.3 2022-07-05 CRAN (R 4.3.0)
            gfonts         0.2.0 2023-01-08 CRAN (R 4.3.0)
           ggforce         0.4.1 2022-10-04 CRAN (R 4.3.0)
           ggplot2         3.4.2 2023-04-03 CRAN (R 4.3.0)
              glue         1.6.2 2022-02-24 CRAN (R 4.3.0)
            gtable         0.3.3 2023-03-21 CRAN (R 4.3.0)
               hms         1.1.3 2023-03-21 CRAN (R 4.3.0)
        hrbrthemes         0.8.0 2020-03-06 CRAN (R 4.3.0)
         htmltools         0.5.5 2023-03-23 CRAN (R 4.3.0)
       htmlwidgets         1.6.2 2023-03-17 CRAN (R 4.3.0)
          httpcode         0.3.0 2020-04-10 CRAN (R 4.3.0)
            httpuv        1.6.11 2023-05-11 CRAN (R 4.3.0)
          jsonlite         1.8.4 2023-06-29 CRAN (R 4.3.0)
             knitr          1.43 2023-05-25 CRAN (R 4.3.0)
          labeling         0.4.2 2020-10-20 CRAN (R 4.3.0)
             later         1.3.1 2023-05-02 CRAN (R 4.3.0)
         lifecycle         1.0.3 2022-10-07 CRAN (R 4.3.0)
         lubridate         1.9.2 2023-02-10 CRAN (R 4.3.0)
          magrittr         2.0.3 2022-03-30 CRAN (R 4.3.0)
              MASS        7.3-60 2023-05-04 CRAN (R 4.3.1)
              mime          0.12 2021-09-28 CRAN (R 4.3.0)
           munsell         0.5.0 2018-06-12 CRAN (R 4.3.0)
            pillar         1.9.0 2023-03-22 CRAN (R 4.3.0)
         pkgconfig         2.0.3 2019-09-22 CRAN (R 4.3.0)
          polyclip        1.10-4 2022-10-20 CRAN (R 4.3.0)
          promises       1.2.0.1 2021-02-11 CRAN (R 4.3.0)
             purrr         1.0.1 2023-01-10 CRAN (R 4.3.0)
                R6         2.5.1 2021-08-19 CRAN (R 4.3.0)
              ragg         1.2.5 2023-01-12 CRAN (R 4.3.0)
              Rcpp        1.0.10 2023-01-22 CRAN (R 4.3.0)
             readr         2.1.4 2023-02-10 CRAN (R 4.3.0)
              renv        0.17.3 2023-04-06 CRAN (R 4.3.0)
             rlang         1.1.1 2023-04-28 CRAN (R 4.3.0)
         rmarkdown          2.21 2023-06-01 CRAN (R 4.3.0)
        rstudioapi          0.14 2022-08-22 CRAN (R 4.3.0)
          Rttf2pt1        1.3.12 2023-01-22 CRAN (R 4.3.0)
            scales         1.2.1 2022-08-20 CRAN (R 4.3.0)
       sessioninfo         1.2.2 2021-12-06 CRAN (R 4.3.0)
             shiny         1.7.4 2022-12-15 CRAN (R 4.3.0)
           stringi        1.7.12 2023-01-11 CRAN (R 4.3.0)
           stringr         1.5.0 2022-12-02 CRAN (R 4.3.0)
       systemfonts         1.0.4 2022-02-11 CRAN (R 4.3.0)
       textshaping         0.3.6 2021-10-13 CRAN (R 4.3.0)
            tibble         3.2.1 2023-03-20 CRAN (R 4.3.0)
             tidyr         1.3.0 2023-01-24 CRAN (R 4.3.0)
        tidyselect         1.2.0 2022-10-10 CRAN (R 4.3.0)
         tidyverse         2.0.0 2023-02-22 CRAN (R 4.3.0)
        timechange         0.2.0 2023-01-11 CRAN (R 4.3.0)
            tweenr         2.0.2 2022-09-06 CRAN (R 4.3.0)
              tzdb         0.3.0 2023-05-12 CRAN (R 4.3.0)
              utf8         1.2.3 2023-01-31 CRAN (R 4.3.0)
             vctrs         0.6.2 2023-06-14 CRAN (R 4.3.0)
             withr         2.5.0 2022-03-03 CRAN (R 4.3.0)
              xfun          0.39 2023-04-20 CRAN (R 4.3.0)
            xtable         1.8-4 2019-04-21 CRAN (R 4.3.0)
              yaml         2.3.7 2023-01-23 CRAN (R 4.3.0)</code></pre>
</div>
</div>
</details>
</div>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>
<ol>
<li id="fn1"><p>In the past I’ve had issues with getting <code><a href="https://rdrr.io/r/grDevices/pdf.html">pdf()</a></code> to work, especially if I use any fancy fonts in the ggplot theme. If you run into issues, you can replace <code><a href="https://rdrr.io/r/grDevices/pdf.html">pdf()</a></code> with <code>cairo_pdf(..., onefile = TRUE)</code>, which seems to work even with exotic fonts.↩︎</p></li>
</ol></section></div> ]]></description>
  <category>visualization</category>
  <guid>https://abraver.github.io/usefulRstuff/posts/paginate_faceted_graphs/index.html</guid>
  <pubDate>Sat, 01 Jul 2023 05:00:00 GMT</pubDate>
</item>
<item>
  <title>Upgrading R without losing all your packages</title>
  <dc:creator>Aaron Braver</dc:creator>
  <link>https://abraver.github.io/usefulRstuff/posts/upgrading_R/index.html</link>
  <description><![CDATA[ <script src="../../jquery-3.7.0.min.js"></script><script src="../../fold.js"></script><script src="../../move_session_info.js"></script><!-- begin content --><p>If you upgrade R to a new major or minor release (e.g.&nbsp;4.0 or 4.1, but not 4.1.1), your library of installed packages doesn’t come along for the ride.</p>
<section id="before-you-upgrade" class="level2"><h2 class="anchored" data-anchor-id="before-you-upgrade">Before you upgrade</h2>
<p><em>Before</em> you upgrade, you should make a list of all of your installed packages—this is easy with <code>sessioninfo::package_info("installed")</code>. If you’ve got packages installed from multiple sources (like CRAN and also Github), it’s best to save these as separate lists to facilitate automated reinstallation of these grouped by source:</p>
<div class="cell" data-messages="false" data-hash="index_cache/html/unnamed-chunk-2_fadae0ccd48b4d71a521e30a2eace8dc">
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://tidyverse.tidyverse.org">tidyverse</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Figure out what's installed</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">installed_packages</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sessioninfo</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://r-lib.github.io/sessioninfo/reference/package_info.html">package_info</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"installed"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"where_from"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dplyr</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/case_when.html">case_when</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://stringr.tidyverse.org/reference/str_detect.html">str_detect</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">source</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CRAN"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CRAN"</span>,</span>
<span>    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://stringr.tidyverse.org/reference/str_detect.html">str_detect</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">source</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Github"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Github"</span>,</span>
<span>    .default <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"other"</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># catch any packages from other sources;</span></span>
<span>                       <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># not automatically installed below</span></span>
<span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://tidyr.tidyverse.org/reference/nest.html">nest</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>.by <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">where_from</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Where to write the lists of packages.  Change as needed</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">file_location</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fs</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://fs.r-lib.org/reference/path.html">path</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~/Desktop/tmp/"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Write these lists to disk</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">installed_packages</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"><a href="https://magrittr.tidyverse.org/reference/pipe.html">%&gt;%</a></span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://purrr.tidyverse.org/reference/pmap.html">pwalk</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">where_from</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">data</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://readr.tidyverse.org/reference/write_delim.html">write_csv</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">data</span>,</span>
<span>              file <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fs</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://fs.r-lib.org/reference/path.html">path</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">file_location</span>,</span>
<span>                              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">where_from</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_packages"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>,</span>
<span>                              ext <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"csv"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</div>
</section><section id="after-you-upgrade" class="level2"><h2 class="anchored" data-anchor-id="after-you-upgrade">After you upgrade</h2>
<p>Then, after you upgrade R, you can re-install the packages from these lists:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-3_6bc8088647c912836deab03c6182fd9d">
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Install manually some things we'll need since they won't be installed anymore</span></span>
<span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/utils/install.packages.html">install.packages</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"remotes"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dplyr"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stringr"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">file_location</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~/Desktop/tmp/"</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Change as needed</span></span>
<span></span>
<span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Install CRAN packages</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">CRAN_packages</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/utils/read.table.html">read.csv</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">file_location</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CRAN_packages"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".csv"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">remotes</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://remotes.r-lib.org/reference/install_cran.html">install_cran</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">CRAN_packages</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">package</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Install Github packages</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">github_packages</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/utils/read.table.html">read.csv</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">file_location</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Github_packages"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".csv"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dplyr</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>github_source <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stringr</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://stringr.tidyverse.org/reference/str_extract.html">str_extract</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">source</span>,</span>
<span>      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(?&lt;=Github \\().*(?=@)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Get the username and repo name</span></span>
<span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">remotes</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://remotes.r-lib.org/reference/install_github.html">install_github</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">github_packages</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">github_source</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</div>
<p>NB: If you have locally installed packages, or packages from another source, these aren’t automatically reinstalled with the code above, but are listed in <code>other_packages.csv</code>.</p>
<!-- End content -->
<div id="footer-session-info">
<details><summary>
Session info and package versions
</summary><div class="cell" data-hash="index_cache/html/unnamed-chunk-5_21b31f662589a1115e67bd4254f280f5">
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code> setting  value
 version  R version 4.3.1 (2023-06-16)
 os       macOS Ventura 13.4.1
 system   aarch64, darwin20
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Chicago
 date     2023-07-08
 pandoc   3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Packages ───────────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>           package loadedversion       date         source
               bit         4.0.5 2022-11-15 CRAN (R 4.3.0)
             bit64         4.0.5 2020-08-30 CRAN (R 4.3.0)
               cli         3.6.1 2023-03-23 CRAN (R 4.3.0)
         codetools        0.2-19 2023-02-01 CRAN (R 4.3.1)
        colorspace         2.1-0 2023-01-23 CRAN (R 4.3.0)
            crayon         1.5.2 2022-09-29 CRAN (R 4.3.0)
              crul         1.4.0 2023-05-17 CRAN (R 4.3.0)
              curl         5.0.1 2023-06-07 CRAN (R 4.3.0)
            digest        0.6.31 2022-12-11 CRAN (R 4.3.0)
             dplyr         1.1.2 2023-04-20 CRAN (R 4.3.0)
          ellipsis         0.3.2 2021-04-29 CRAN (R 4.3.0)
          evaluate          0.21 2023-05-05 CRAN (R 4.3.0)
             fansi         1.0.4 2023-01-22 CRAN (R 4.3.0)
           fastmap         1.1.1 2023-02-24 CRAN (R 4.3.0)
 fontBitstreamVera         0.1.1 2017-02-01 CRAN (R 4.3.0)
    fontLiberation         0.1.0 2016-10-15 CRAN (R 4.3.0)
        fontquiver         0.2.1 2017-02-01 CRAN (R 4.3.0)
           forcats         1.0.0 2023-01-29 CRAN (R 4.3.0)
                fs         1.6.2 2023-04-25 CRAN (R 4.3.0)
           gdtools         0.3.3 2023-03-27 CRAN (R 4.3.0)
          generics         0.1.3 2022-07-05 CRAN (R 4.3.0)
            gfonts         0.2.0 2023-01-08 CRAN (R 4.3.0)
           ggplot2         3.4.2 2023-04-03 CRAN (R 4.3.0)
              glue         1.6.2 2022-02-24 CRAN (R 4.3.0)
            gtable         0.3.3 2023-03-21 CRAN (R 4.3.0)
               hms         1.1.3 2023-03-21 CRAN (R 4.3.0)
         htmltools         0.5.5 2023-03-23 CRAN (R 4.3.0)
       htmlwidgets         1.6.2 2023-03-17 CRAN (R 4.3.0)
          httpcode         0.3.0 2020-04-10 CRAN (R 4.3.0)
            httpuv        1.6.11 2023-05-11 CRAN (R 4.3.0)
          jsonlite         1.8.7 2023-06-29 CRAN (R 4.3.0)
             knitr          1.43 2023-05-25 CRAN (R 4.3.0)
             later         1.3.1 2023-05-02 CRAN (R 4.3.0)
         lifecycle         1.0.3 2022-10-07 CRAN (R 4.3.0)
         lubridate         1.9.2 2023-02-10 CRAN (R 4.3.0)
          magrittr         2.0.3 2022-03-30 CRAN (R 4.3.0)
              mime          0.12 2021-09-28 CRAN (R 4.3.0)
           munsell         0.5.0 2018-06-12 CRAN (R 4.3.0)
            pillar         1.9.0 2023-03-22 CRAN (R 4.3.0)
         pkgconfig         2.0.3 2019-09-22 CRAN (R 4.3.0)
          promises       1.2.0.1 2021-02-11 CRAN (R 4.3.0)
             purrr         1.0.1 2023-01-10 CRAN (R 4.3.0)
                R6         2.5.1 2021-08-19 CRAN (R 4.3.0)
              ragg         1.2.5 2023-01-12 CRAN (R 4.3.0)
              Rcpp        1.0.10 2023-01-22 CRAN (R 4.3.0)
             readr         2.1.4 2023-02-10 CRAN (R 4.3.0)
              renv        0.17.3 2023-04-06 CRAN (R 4.3.0)
             rlang         1.1.1 2023-04-28 CRAN (R 4.3.0)
         rmarkdown          2.22 2023-06-01 CRAN (R 4.3.0)
        rstudioapi          0.14 2022-08-22 CRAN (R 4.3.0)
            scales         1.2.1 2022-08-20 CRAN (R 4.3.0)
       sessioninfo         1.2.2 2021-12-06 CRAN (R 4.3.0)
             shiny         1.7.4 2022-12-15 CRAN (R 4.3.0)
           stringi        1.7.12 2023-01-11 CRAN (R 4.3.0)
           stringr         1.5.0 2022-12-02 CRAN (R 4.3.0)
       systemfonts         1.0.4 2022-02-11 CRAN (R 4.3.0)
       textshaping         0.3.6 2021-10-13 CRAN (R 4.3.0)
            tibble         3.2.1 2023-03-20 CRAN (R 4.3.0)
             tidyr         1.3.0 2023-01-24 CRAN (R 4.3.0)
        tidyselect         1.2.0 2022-10-10 CRAN (R 4.3.0)
         tidyverse         2.0.0 2023-02-22 CRAN (R 4.3.0)
        timechange         0.2.0 2023-01-11 CRAN (R 4.3.0)
              tzdb         0.4.0 2023-05-12 CRAN (R 4.3.0)
              utf8         1.2.3 2023-01-31 CRAN (R 4.3.0)
             vctrs         0.6.3 2023-06-14 CRAN (R 4.3.0)
             vroom         1.6.3 2023-04-28 CRAN (R 4.3.0)
             withr         2.5.0 2022-03-03 CRAN (R 4.3.0)
              xfun          0.39 2023-04-20 CRAN (R 4.3.0)
            xtable         1.8-4 2019-04-21 CRAN (R 4.3.0)
              yaml         2.3.7 2023-01-23 CRAN (R 4.3.0)</code></pre>
</div>
</div>
</details>
</div>


</section> ]]></description>
  <category>upgrading</category>
  <category>package management</category>
  <guid>https://abraver.github.io/usefulRstuff/posts/upgrading_R/index.html</guid>
  <pubDate>Fri, 30 Jun 2023 05:00:00 GMT</pubDate>
</item>
<item>
  <title>Interactive plots with ggiraph
</title>
  <dc:creator>Aaron Braver</dc:creator>
  <link>https://abraver.github.io/usefulRstuff/posts/ggiraph/index.html</link>
  <description><![CDATA[ <script src="../../jquery-3.7.0.min.js"></script><script src="../../fold.js"></script><script src="../../move_session_info.js"></script><!-- begin content --><section id="ggiraph" class="level2"><h2 class="anchored" data-anchor-id="ggiraph"><code>ggiraph</code></h2>
<div class="float-right">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><a href="https://davidgohel.github.io/ggiraph/"><img src="https://abraver.github.io/usefulRstuff/posts/ggiraph/images/ggiraph-logo.png" class="img-fluid figure-img" alt="ggiraph logo" width="150"></a></p>
</figure>
</div>
</div>
<p><code>ggiraph</code> allows for the creation of interactive plots in documents that will output as HTML or in <a href="https://shiny.posit.co">Shiny</a>. In static HTML pages, <code>ggiraph</code> allows for tooltips, mouseover highlighting, and JavaScript on click. In Shiny documents there is <a href="https://www.ardata.fr/ggiraph-book/ggiraph-shiny.html">additional interactivity</a> available—but since this document is static HTML, I won’t cover these here.</p>
<p>(For more details, see the <a href="https://davidgohel.github.io/ggiraph/"><code>ggiraph</code> overview</a>, and for even more details, see the <a href="https://www.ardata.fr/ggiraph-book/"><code>ggiraph book</code></a>; some examples here come from those sources.)</p>
<p>(You may also be interested in the <a href="https://plotly.com/r/"><code>plotly</code> package</a> as another option for adding interactivity to plots.)</p>
</section><section id="simple-example" class="level2"><h2 class="anchored" data-anchor-id="simple-example">Simple example</h2>
<p>As a simple example, here is a plot of the <code>palmerpenguins</code> dataset, showing <code>bill_depth_mm</code> vs.&nbsp;<code>bill_length_mm</code>; species are shown by color, and hovering over a point shows which island the sample was collected on (and highlights all other points from that island):</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-3_1c23a466a9a8afab5e7d99867c0392d3">
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/ggiraph/">ggiraph</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org">ggplot2</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://allisonhorst.github.io/palmerpenguins/">palmerpenguins</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Load penguins dataset</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot_1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguins</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>    x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bill_depth_mm</span>, y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bill_length_mm</span>,</span>
<span>    tooltip <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/paste.html">paste</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Island:"</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">island</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>,</span>
<span>    data_id <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">island</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">species</span></span>
<span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/ggiraph/reference/geom_point_interactive.html">geom_point_interactive</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>     hover_nearest <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/ggiraph/reference/girafe.html">girafe</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>ggobj <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot_1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="girafe html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-042b4ef0f02e2ff45805" style="width:100%;height:464px;"></div>
<script type="application/json" data-for="htmlwidget-042b4ef0f02e2ff45805">{"x":{"html":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' class='ggiraph-svg' role='img' id='svg_84d8be6e_5652_437c_ba12_52205cb087da' viewBox='0 0 504 360'>\n <defs id='svg_84d8be6e_5652_437c_ba12_52205cb087da_defs'>\n  <clipPath id='svg_84d8be6e_5652_437c_ba12_52205cb087da_c1'>\n   <rect x='0' y='0' width='504' height='360'/>\n  <\/clipPath>\n  <clipPath id='svg_84d8be6e_5652_437c_ba12_52205cb087da_c2'>\n   <rect x='61.75' y='29.89' width='331.63' height='269.08'/>\n  <\/clipPath>\n <\/defs>\n <g id='svg_84d8be6e_5652_437c_ba12_52205cb087da_rootg' class='ggiraph-svg-rootg'>\n  <g clip-path='url(#svg_84d8be6e_5652_437c_ba12_52205cb087da_c1)'>\n   <rect x='0' y='0' width='504' height='360' fill='#FFFFFF' fill-opacity='1' stroke='#FFFFFF' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='round' class='ggiraph-svg-bg'/>\n  <\/g>\n  <g clip-path='url(#svg_84d8be6e_5652_437c_ba12_52205cb087da_c2)'>\n   <polyline points='61.75,260.94 393.38,260.94' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.32' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='61.75,171.99 393.38,171.99' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.32' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='61.75,83.04 393.38,83.04' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.32' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='100.16,298.97 100.16,29.89' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.32' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='189.88,298.97 189.88,29.89' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.32' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='279.61,298.97 279.61,29.89' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.32' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='369.34,298.97 369.34,29.89' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.32' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='61.75,216.46 393.38,216.46' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='61.75,127.51 393.38,127.51' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='61.75,38.56 393.38,38.56' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='145.02,298.97 145.02,29.89' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='234.75,298.97 234.75,29.89' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='324.47,298.97 324.47,29.89' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e1' cx='277.82' cy='224.47' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e2' cx='231.16' cy='220.91' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e3' cx='252.69' cy='213.8' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e4' cx='299.35' cy='245.82' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e5' cx='346.01' cy='222.69' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e6' cx='245.51' cy='226.25' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e7' cx='310.12' cy='223.58' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e8' cx='256.28' cy='268.95' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e9' cx='331.65' cy='198.67' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e10' cx='220.39' cy='236.03' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e11' cx='227.57' cy='236.03' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e12' cx='238.34' cy='206.68' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e13' cx='367.54' cy='228.92' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e14' cx='363.95' cy='264.5' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e15' cx='245.51' cy='246.71' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e16' cx='288.58' cy='228.03' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e17' cx='349.6' cy='194.23' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e18' cx='267.05' cy='266.28' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e19' cx='378.31' cy='163.09' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e20' cx='263.46' cy='236.03' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e21' cx='277.82' cy='236.92' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e22' cx='295.76' cy='252.93' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e23' cx='256.28' cy='232.48' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e24' cx='223.98' cy='227.14' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e25' cx='284.99' cy='258.27' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e26' cx='274.23' cy='211.13' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e27' cx='249.1' cy='212.02' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e28' cx='274.23' cy='235.14' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e29' cx='284.99' cy='212.02' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e30' cx='206.03' cy='220.91' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e31' cx='256.28' cy='241.37' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e32' cx='245.51' cy='220.91' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e33' cx='284.99' cy='208.46' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e34' cx='216.8' cy='248.49' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e35' cx='363.95' cy='223.58' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e36' cx='324.47' cy='227.14' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e37' cx='270.64' cy='196.9' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e38' cx='299.35' cy='237.81' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e39' cx='292.17' cy='218.24' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e40' cx='252.69' cy='247.6' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e41' cx='267.05' cy='209.35' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e42' cx='270.64' cy='252.05' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e43' cx='313.71' cy='179.99' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e44' cx='213.21' cy='243.15' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e45' cx='281.4' cy='220.02' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e46' cx='288.58' cy='206.68' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e47' cx='284.99' cy='238.7' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e48' cx='249.1' cy='252.05' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e49' cx='367.54' cy='196.01' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e50' cx='241.92' cy='220.02' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e51' cx='284.99' cy='215.58' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e52' cx='249.1' cy='260.94' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e53' cx='306.53' cy='198.67' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e54' cx='256.28' cy='265.39' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e55' cx='274.23' cy='204.01' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e56' cx='234.75' cy='225.36' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e57' cx='281.4' cy='211.13' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e58' cx='202.44' cy='247.6' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e59' cx='292.17' cy='237.81' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e60' cx='213.21' cy='254.71' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e61' cx='363.95' cy='204.9' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e62' cx='216.8' cy='237.81' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e63' cx='259.87' cy='206.68' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e64' cx='220.39' cy='248.49' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e65' cx='252.69' cy='202.23' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e66' cx='188.09' cy='256.49' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e67' cx='292.17' cy='206.68' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e68' cx='202.44' cy='252.93' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e69' cx='302.94' cy='200.45' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e70' cx='288.58' cy='274.28' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e71' cx='267.05' cy='219.13' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e72' cx='223.98' cy='220.02' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e73' cx='284.99' cy='164.87' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e74' cx='234.75' cy='256.49' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e75' cx='270.64' cy='191.56' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e76' cx='209.62' cy='208.46' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e77' cx='302.94' cy='241.37' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e78' cx='184.5' cy='250.27' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e79' cx='292.17' cy='197.78' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e80' cx='223.98' cy='264.5' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e81' cx='238.34' cy='190.67' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e82' cx='281.4' cy='245.82' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e83' cx='302.94' cy='260.05' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e84' cx='245.51' cy='240.48' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e85' cx='335.24' cy='204.9' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e86' cx='306.53' cy='249.38' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e87' cx='274.23' cy='244.04' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e88' cx='295.76' cy='231.59' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e89' cx='281.4' cy='226.25' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e90' cx='252.69' cy='254.71' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e91' cx='256.28' cy='206.68' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e92' cx='220.39' cy='269.84' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e93' cx='256.28' cy='220.02' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e94' cx='227.57' cy='250.27' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e95' cx='284.99' cy='209.35' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e96' cx='274.23' cy='233.37' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e97' cx='270.64' cy='213.8' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e98' cx='184.5' cy='277.84' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e99' cx='270.64' cy='188' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e100' cx='249.1' cy='260.94' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e101' cx='324.47' cy='207.57' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e102' cx='180.91' cy='236.92' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e103' cx='324.47' cy='236.03' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e104' cx='274.23' cy='235.14' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e105' cx='284.99' cy='219.13' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e106' cx='223.98' cy='228.92' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e107' cx='324.47' cy='232.48' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e108' cx='216.8' cy='233.37' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e109' cx='288.58' cy='188' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e110' cx='198.86' cy='233.37' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e111' cx='335.24' cy='166.65' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e112' cx='241.92' cy='219.13' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e113' cx='306.53' cy='196.9' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e114' cx='349.6' cy='220.02' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e115' cx='263.46' cy='192.45' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e116' cx='216.8' cy='228.92' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e117' cx='342.42' cy='240.48' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e118' cx='216.8' cy='254.71' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e119' cx='274.23' cy='206.68' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e120' cx='223.98' cy='250.27' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e121' cx='317.3' cy='236.92' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e122' cx='216.8' cy='214.69' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e123' cx='270.64' cy='204.01' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e124' cx='177.32' cy='259.16' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e125' cx='288.58' cy='211.13' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e126' cx='238.34' cy='227.14' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e127' cx='263.46' cy='203.12' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e128' cx='220.39' cy='225.36' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e129' cx='252.69' cy='179.99' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e130' cx='249.1' cy='229.81' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e131' cx='295.76' cy='188.89' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Torgersen' data-id='Torgersen' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e132' cx='270.64' cy='244.93' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e133' cx='270.64' cy='238.7' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e134' cx='238.34' cy='233.37' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e135' cx='234.75' cy='206.68' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e136' cx='234.75' cy='255.6' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e137' cx='328.06' cy='214.69' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e138' cx='198.86' cy='243.15' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e139' cx='249.1' cy='219.13' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e140' cx='220.39' cy='214.69' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e141' cx='223.98' cy='211.13' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e142' cx='162.96' cy='286.74' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e143' cx='216.8' cy='210.24' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e144' cx='209.62' cy='240.48' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e145' cx='277.82' cy='225.36' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e146' cx='274.23' cy='223.58' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e147' cx='267.05' cy='246.71' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e148' cx='245.51' cy='252.05' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e149' cx='256.28' cy='236.03' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e150' cx='220.39' cy='252.05' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e151' cx='270.64' cy='203.12' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e152' cx='80.42' cy='162.2' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e153' cx='191.68' cy='127.51' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e154' cx='112.72' cy='139.08' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e155' cx='152.2' cy='127.51' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e156' cx='127.07' cy='148.86' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e157' cx='91.18' cy='158.65' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e158' cx='130.66' cy='168.43' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e159' cx='155.79' cy='156.87' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e160' cx='87.59' cy='187.11' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e161' cx='159.38' cy='155.98' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e162' cx='98.36' cy='208.46' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e163' cx='184.5' cy='136.41' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e164' cx='98.36' cy='167.54' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e165' cx='130.66' cy='141.74' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e166' cx='130.66' cy='164.87' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e167' cx='170.14' cy='133.74' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e168' cx='91.18' cy='198.67' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e169' cx='152.2' cy='134.63' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e170' cx='127.07' cy='161.31' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e171' cx='148.61' cy='139.08' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e172' cx='119.9' cy='125.73' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e173' cx='127.07' cy='171.1' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e174' cx='127.07' cy='158.65' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e175' cx='173.73' cy='160.42' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e176' cx='76.83' cy='190.67' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e177' cx='148.61' cy='162.2' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e178' cx='119.9' cy='176.44' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e179' cx='145.02' cy='147.08' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e180' cx='119.9' cy='143.52' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e181' cx='155.79' cy='127.51' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e182' cx='155.79' cy='151.53' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e183' cx='116.31' cy='191.56' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e184' cx='127.07' cy='171.1' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e185' cx='216.8' cy='42.12' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e186' cx='137.84' cy='135.52' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e187' cx='191.68' cy='141.74' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e188' cx='98.36' cy='193.34' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e189' cx='227.57' cy='177.33' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e190' cx='94.77' cy='180.88' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e191' cx='170.14' cy='139.08' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e192' cx='98.36' cy='192.45' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e193' cx='180.91' cy='131.07' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e194' cx='98.36' cy='169.32' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e195' cx='145.02' cy='131.07' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e196' cx='177.32' cy='123.07' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e197' cx='105.54' cy='184.44' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e198' cx='105.54' cy='167.54' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e199' cx='177.32' cy='123.07' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e200' cx='84' cy='172.88' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e201' cx='173.73' cy='170.21' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e202' cx='116.31' cy='157.76' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e203' cx='112.72' cy='140.86' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e204' cx='123.48' cy='171.1' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e205' cx='145.02' cy='126.62' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e206' cx='123.48' cy='158.65' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e207' cx='159.38' cy='171.99' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e208' cx='105.54' cy='182.66' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e209' cx='145.02' cy='167.54' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e210' cx='127.07' cy='188' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e211' cx='155.79' cy='123.95' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e212' cx='101.95' cy='169.32' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e213' cx='141.43' cy='161.31' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e214' cx='105.54' cy='165.76' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e215' cx='170.14' cy='89.26' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e216' cx='116.31' cy='164.87' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e217' cx='209.62' cy='129.29' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e218' cx='123.48' cy='161.31' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e219' cx='188.09' cy='131.96' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e220' cx='116.31' cy='185.33' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e221' cx='145.02' cy='121.29' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e222' cx='145.02' cy='147.97' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e223' cx='166.55' cy='159.54' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e224' cx='166.55' cy='143.52' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e225' cx='137.84' cy='158.65' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e226' cx='145.02' cy='159.54' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e227' cx='180.91' cy='139.97' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e228' cx='116.31' cy='149.75' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e229' cx='191.68' cy='117.73' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e230' cx='101.95' cy='170.21' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e231' cx='195.27' cy='170.21' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e232' cx='127.07' cy='135.52' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e233' cx='166.55' cy='105.27' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e234' cx='130.66' cy='150.64' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e235' cx='177.32' cy='127.51' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e236' cx='101.95' cy='172.88' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e237' cx='227.57' cy='120.4' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e238' cx='123.48' cy='186.22' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e239' cx='116.31' cy='115.95' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e240' cx='109.13' cy='149.75' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e241' cx='216.8' cy='108.83' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e242' cx='145.02' cy='149.75' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e243' cx='220.39' cy='107.94' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e244' cx='127.07' cy='167.54' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e245' cx='184.5' cy='131.96' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e246' cx='134.25' cy='176.44' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e247' cx='170.14' cy='120.4' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e248' cx='173.73' cy='132.85' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e249' cx='130.66' cy='155.09' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e250' cx='123.48' cy='141.74' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e251' cx='198.86' cy='117.73' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e252' cx='145.02' cy='140.86' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e253' cx='216.8' cy='75.03' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e254' cx='162.96' cy='152.42' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e255' cx='145.02' cy='135.52' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e256' cx='101.95' cy='151.53' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e257' cx='184.5' cy='155.98' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e258' cx='134.25' cy='201.34' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e259' cx='173.73' cy='97.27' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e260' cx='109.13' cy='187.11' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e261' cx='148.61' cy='144.41' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e262' cx='152.2' cy='123.07' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e263' cx='177.32' cy='129.29' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e264' cx='152.2' cy='185.33' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e265' cx='191.68' cy='114.17' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e266' cx='112.72' cy='161.31' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e267' cx='180.91' cy='82.15' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e268' cx='170.14' cy='176.44' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e269' cx='188.09' cy='138.19' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e270' cx='98.36' cy='152.42' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e271' cx='119.9' cy='155.98' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e272' cx='170.14' cy='123.95' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e273' cx='137.84' cy='170.21' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e274' cx='184.5' cy='128.4' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Biscoe' data-id='Biscoe' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e275' cx='249.1' cy='158.65' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e276' cx='306.53' cy='127.51' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e277' cx='295.76' cy='115.95' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e278' cx='277.82' cy='168.43' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e279' cx='317.3' cy='103.5' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e280' cx='245.51' cy='170.21' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e281' cx='259.87' cy='162.2' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e282' cx='259.87' cy='115.95' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e283' cx='284.99' cy='163.09' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e284' cx='320.88' cy='115.95' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e285' cx='245.51' cy='157.76' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e286' cx='335.24' cy='112.39' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e287' cx='227.57' cy='154.2' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e288' cx='256.28' cy='109.72' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e289' cx='220.39' cy='163.98' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e290' cx='310.12' cy='123.07' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e291' cx='324.47' cy='124.84' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e292' cx='245.51' cy='56.35' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e293' cx='274.23' cy='159.54' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e294' cx='259.87' cy='134.63' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e295' cx='227.57' cy='195.12' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e296' cx='234.75' cy='140.86' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e297' cx='202.44' cy='188' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e298' cx='302.94' cy='122.18' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e299' cx='249.1' cy='156.87' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e300' cx='288.58' cy='109.72' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e301' cx='267.05' cy='123.07' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e302' cx='288.58' cy='131.96' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e303' cx='245.51' cy='159.54' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e304' cx='324.47' cy='102.61' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e305' cx='202.44' cy='208.46' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e306' cx='353.19' cy='90.15' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e307' cx='206.03' cy='194.23' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e308' cx='281.4' cy='118.62' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e309' cx='274.23' cy='130.18' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e310' cx='209.62' cy='149.75' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e311' cx='263.46' cy='148.86' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e312' cx='349.6' cy='109.72' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e313' cx='202.44' cy='155.09' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e314' cx='320.88' cy='96.38' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e315' cx='306.53' cy='136.41' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e316' cx='234.75' cy='161.31' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e317' cx='292.17' cy='119.51' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e318' cx='216.8' cy='167.54' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e319' cx='249.1' cy='119.51' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e320' cx='270.64' cy='120.4' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e321' cx='249.1' cy='126.62' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e322' cx='310.12' cy='136.41' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e323' cx='277.82' cy='114.17' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e324' cx='227.57' cy='129.29' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e325' cx='195.27' cy='144.41' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e326' cx='288.58' cy='115.06' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e327' cx='227.57' cy='165.76' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e328' cx='313.71' cy='121.29' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e329' cx='227.57' cy='194.23' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e330' cx='281.4' cy='107.94' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e331' cx='202.44' cy='170.21' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e332' cx='320.88' cy='133.74' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e333' cx='281.4' cy='125.73' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e334' cx='302.94' cy='166.65' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e335' cx='306.53' cy='110.61' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e336' cx='198.86' cy='155.98' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e337' cx='216.8' cy='165.76' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e338' cx='317.3' cy='75.92' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e339' cx='256.28' cy='185.33' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e340' cx='259.87' cy='131.07' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e341' cx='288.58' cy='120.4' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e342' cx='277.82' cy='125.73' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='Island: Dream' data-id='Dream' nearest='true'/>\n  <\/g>\n  <g clip-path='url(#svg_84d8be6e_5652_437c_ba12_52205cb087da_c1)'>\n   <text x='47.54' y='220.55' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>40<\/text>\n   <text x='47.54' y='131.6' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>50<\/text>\n   <text x='47.54' y='42.65' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>60<\/text>\n   <text x='135' y='310' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>15.0<\/text>\n   <text x='224.72' y='310' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>17.5<\/text>\n   <text x='314.45' y='310' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>20.0<\/text>\n   <text x='181.73' y='326.7' font-size='12pt' font-family='Roboto Condensed'>bill_depth_mm<\/text>\n   <text transform='translate(41.26,211.99) rotate(-90.00)' font-size='12pt' font-family='Roboto Condensed'>bill_length_mm<\/text>\n   <text x='410.57' y='139.73' font-size='8.62pt' font-family='Roboto Condensed'>species<\/text>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e343' cx='419.21' cy='155.33' r='1.47pt' fill='#F8766D' fill-opacity='1' stroke='#F8766D' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e344' cx='419.21' cy='172.61' r='1.47pt' fill='#00BA38' fill-opacity='1' stroke='#00BA38' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' nearest='true'/>\n   <circle id='svg_84d8be6e_5652_437c_ba12_52205cb087da_e345' cx='419.21' cy='189.89' r='1.47pt' fill='#619CFF' fill-opacity='1' stroke='#619CFF' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' nearest='true'/>\n   <text x='433.58' y='158.59' font-size='6.9pt' font-family='Roboto Condensed'>Adelie<\/text>\n   <text x='433.58' y='175.87' font-size='6.9pt' font-family='Roboto Condensed'>Chinstrap<\/text>\n   <text x='433.58' y='193.15' font-size='6.9pt' font-family='Roboto Condensed'>Gentoo<\/text>\n  <\/g>\n <\/g>\n<\/svg>","js":null,"uid":"svg_84d8be6e_5652_437c_ba12_52205cb087da","ratio":1.4,"settings":{"tooltip":{"css":".tooltip_SVGID_ { padding:5px;background:black;color:white;border-radius:2px;text-align:left; ; position:absolute;pointer-events:none;z-index:999;}","placement":"doc","opacity":0.9,"offx":10,"offy":10,"use_cursor_pos":true,"use_fill":false,"use_stroke":false,"delay_over":200,"delay_out":500},"hover":{"css":".hover_data_SVGID_ { fill:orange;stroke:black;cursor:pointer; }\ntext.hover_data_SVGID_ { stroke:none;fill:orange; }\ncircle.hover_data_SVGID_ { fill:orange;stroke:black; }\nline.hover_data_SVGID_, polyline.hover_data_SVGID_ { fill:none;stroke:orange; }\nrect.hover_data_SVGID_, polygon.hover_data_SVGID_, path.hover_data_SVGID_ { fill:orange;stroke:none; }\nimage.hover_data_SVGID_ { stroke:orange; }","reactive":true,"nearest_distance":null},"hover_inv":{"css":""},"hover_key":{"css":".hover_key_SVGID_ { fill:orange;stroke:black;cursor:pointer; }\ntext.hover_key_SVGID_ { stroke:none;fill:orange; }\ncircle.hover_key_SVGID_ { fill:orange;stroke:black; }\nline.hover_key_SVGID_, polyline.hover_key_SVGID_ { fill:none;stroke:orange; }\nrect.hover_key_SVGID_, polygon.hover_key_SVGID_, path.hover_key_SVGID_ { fill:orange;stroke:none; }\nimage.hover_key_SVGID_ { stroke:orange; }","reactive":true},"hover_theme":{"css":".hover_theme_SVGID_ { fill:orange;stroke:black;cursor:pointer; }\ntext.hover_theme_SVGID_ { stroke:none;fill:orange; }\ncircle.hover_theme_SVGID_ { fill:orange;stroke:black; }\nline.hover_theme_SVGID_, polyline.hover_theme_SVGID_ { fill:none;stroke:orange; }\nrect.hover_theme_SVGID_, polygon.hover_theme_SVGID_, path.hover_theme_SVGID_ { fill:orange;stroke:none; }\nimage.hover_theme_SVGID_ { stroke:orange; }","reactive":true},"select":{"css":".select_data_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_data_SVGID_ { stroke:none;fill:red; }\ncircle.select_data_SVGID_ { fill:red;stroke:black; }\nline.select_data_SVGID_, polyline.select_data_SVGID_ { fill:none;stroke:red; }\nrect.select_data_SVGID_, polygon.select_data_SVGID_, path.select_data_SVGID_ { fill:red;stroke:none; }\nimage.select_data_SVGID_ { stroke:red; }","type":"multiple","only_shiny":true,"selected":[]},"select_inv":{"css":""},"select_key":{"css":".select_key_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_key_SVGID_ { stroke:none;fill:red; }\ncircle.select_key_SVGID_ { fill:red;stroke:black; }\nline.select_key_SVGID_, polyline.select_key_SVGID_ { fill:none;stroke:red; }\nrect.select_key_SVGID_, polygon.select_key_SVGID_, path.select_key_SVGID_ { fill:red;stroke:none; }\nimage.select_key_SVGID_ { stroke:red; }","type":"single","only_shiny":true,"selected":[]},"select_theme":{"css":".select_theme_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_theme_SVGID_ { stroke:none;fill:red; }\ncircle.select_theme_SVGID_ { fill:red;stroke:black; }\nline.select_theme_SVGID_, polyline.select_theme_SVGID_ { fill:none;stroke:red; }\nrect.select_theme_SVGID_, polygon.select_theme_SVGID_, path.select_theme_SVGID_ { fill:red;stroke:none; }\nimage.select_theme_SVGID_ { stroke:red; }","type":"single","only_shiny":true,"selected":[]},"zoom":{"min":1,"max":1,"duration":300},"toolbar":{"position":"topright","pngname":"diagram","tooltips":null,"hidden":[],"delay_over":200,"delay_out":500},"sizing":{"rescale":true,"width":1}}},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p>The <code>data_id</code> argument is how items will be grouped for tooltips and hover effects—here, we want all the dots from the same island to behave together.</p>
<p>Note, too, the <code>ggobj</code> argument to <code><a href="https://davidgohel.github.io/ggiraph/reference/girafe.html">girafe()</a></code>. The actual first argument to <code><a href="https://davidgohel.github.io/ggiraph/reference/girafe.html">girafe()</a></code> is <em>not</em> a <code>ggplot</code> object; this means the <code>ggobj</code> argument needs to be called explicitly, and also makes piping into <code>girafe</code> a bit annoying (hence saving the plot to <code>plot_1</code> and referring to that within the <code><a href="https://davidgohel.github.io/ggiraph/reference/girafe.html">girafe()</a></code> call.</p>
</section><section id="slightly-more-complicated-example" class="level2"><h2 class="anchored" data-anchor-id="slightly-more-complicated-example">Slightly more complicated example</h2>
<p>In this slightly more complicated example, the weight of chicks is shown over time. Hovering over a line highlights all chicks in that diet (and dims those in other diets)<sup>1</sup>, and shows the chick number in a tooltip.</p>
<p>The styling of moused-over elements is controlled with the <code>css</code> argument to <code>opts_hover</code> (which is called inside <code><a href="https://davidgohel.github.io/ggiraph/reference/girafe.html">girafe()</a></code>). I like making non-moused-over elements gray (in <code>opts_hover_inv</code>) and leaving the moused-over elements with their original color by specifiying `css=““.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-4_f6189911f9657eb00f55dd2b6a1c738e">
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot_2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">ChickWeight</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>    x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">Time</span>, y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">weight</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">Diet</span>,</span>
<span>    group <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">Chick</span>,</span>
<span>    tooltip <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Diet "</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">Diet</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (Chick "</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">Chick</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">")"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>,</span>
<span>    data_id <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">Diet</span></span>
<span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/ggiraph/reference/geom_path_interactive.html">geom_line_interactive</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>     hover_nearest <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/ggiraph/reference/girafe.html">girafe</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>ggobj <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot_2</span>,</span>
<span>      options <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/ggiraph/reference/opts_hover.html">opts_hover</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>css <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Don't change CSS for selected group</span></span>
<span>        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/ggiraph/reference/opts_hover.html">opts_hover_inv</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>css <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"opacity: 0.1"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># CSS for other groups</span></span>
<span>        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/ggiraph/reference/opts_toolbar.html">opts_toolbar</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>saveaspng <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Don't include save button</span></span>
<span>      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="girafe html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-10db0d422e5b52af25ef" style="width:100%;height:464px;"></div>
<script type="application/json" data-for="htmlwidget-10db0d422e5b52af25ef">{"x":{"html":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' class='ggiraph-svg' role='img' id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d' viewBox='0 0 504 360'>\n <defs id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_defs'>\n  <clipPath id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_c1'>\n   <rect x='0' y='0' width='504' height='360'/>\n  <\/clipPath>\n  <clipPath id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_c2'>\n   <rect x='67.43' y='29.89' width='356.23' height='269.08'/>\n  <\/clipPath>\n <\/defs>\n <g id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_rootg' class='ggiraph-svg-rootg'>\n  <g clip-path='url(#svg_272e5630_23a8_4e02_89f8_f6570e52c15d_c1)'>\n   <rect x='0' y='0' width='504' height='360' fill='#FFFFFF' fill-opacity='1' stroke='#FFFFFF' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='round' class='ggiraph-svg-bg'/>\n  <\/g>\n  <g clip-path='url(#svg_272e5630_23a8_4e02_89f8_f6570e52c15d_c2)'>\n   <polyline points='67.43,275.88 423.65,275.88' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.32' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='67.43,203.51 423.65,203.51' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.32' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='67.43,131.14 423.65,131.14' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.32' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='67.43,58.76 423.65,58.76' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.32' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='122.17,298.97 122.17,29.89' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.32' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='199.28,298.97 199.28,29.89' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.32' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='276.38,298.97 276.38,29.89' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.32' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='353.49,298.97 353.49,29.89' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.32' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='67.43,239.69 423.65,239.69' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='67.43,167.32 423.65,167.32' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='67.43,94.95 423.65,94.95' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='83.62,298.97 83.62,29.89' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='160.72,298.97 160.72,29.89' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='237.83,298.97 237.83,29.89' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='314.93,298.97 314.93,29.89' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='392.04,298.97 392.04,29.89' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e1' points='83.62,283.84 114.46,286.74' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 18)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e2' points='83.62,282.39 114.46,279.50 145.30,276.60 176.14,275.16 206.99,270.81 237.83,275.16 268.67,272.99' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 16)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e3' points='83.62,282.39 114.46,276.60 145.30,271.54 176.14,265.75 206.99,262.85 237.83,262.85 268.67,263.58 299.51,262.85' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 15)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e4' points='83.62,282.39 114.46,277.33 145.30,273.71 176.14,268.64 206.99,265.03 237.83,263.58 268.67,260.68 299.51,261.41 330.36,260.68 361.20,253.45 392.04,246.21 407.46,242.59' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 13)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e5' points='83.62,281.67 114.46,275.16 145.30,269.37 176.14,262.85 206.99,250.55 237.83,242.59 268.67,246.93 299.51,245.48 330.36,244.76 361.20,239.69 392.04,239.69 407.46,241.14' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 9)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e6' points='83.62,282.39 114.46,278.05 145.30,272.99 176.14,270.09 206.99,265.03 237.83,259.24 268.67,256.34 299.51,247.66 330.36,241.14 361.20,234.63 392.04,228.84 407.46,227.39' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 20)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e7' points='83.62,282.39 114.46,280.22 145.30,274.43 176.14,266.47 206.99,258.51 237.83,253.45 268.67,247.66 299.51,242.59 330.36,238.97 361.20,231.01 392.04,225.22 407.46,222.33' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 10)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e8' points='83.62,281.67 114.46,275.88 145.30,267.92 176.14,260.68 206.99,251.27 237.83,244.76 268.67,232.46 299.51,228.12 330.36,220.88 361.20,215.09 392.04,221.60' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 8)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e9' points='83.62,281.67 114.46,275.16 145.30,267.92 176.14,259.96 206.99,252.00 237.83,247.66 268.67,241.14 299.51,237.52 330.36,230.29 361.20,223.05 392.04,215.81 407.46,209.30' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 17)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e10' points='83.62,280.95 114.46,277.33 145.30,272.26 176.14,267.20 206.99,265.03 237.83,260.68 268.67,252.72 299.51,248.38 330.36,235.35 361.20,225.22 392.04,207.85 407.46,198.44' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 19)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e11' points='83.62,281.67 114.46,276.60 145.30,271.54 176.14,263.58 206.99,258.51 237.83,249.10 268.67,238.25 299.51,233.91 330.36,213.64 361.20,200.61 392.04,196.27 407.46,198.44' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 4)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e12' points='83.62,282.39 114.46,276.60 145.30,269.37 176.14,258.51 206.99,241.87 237.83,222.33 268.67,210.02 299.51,204.96 330.36,199.89 361.20,196.27 392.04,196.27 407.46,198.44' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 6)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e13' points='83.62,280.95 114.46,275.16 145.30,266.47 176.14,251.27 206.99,231.01 237.83,211.47 268.67,190.48 299.51,183.97 330.36,180.35 361.20,178.90 392.04,181.07 407.46,185.42' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 11)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e14' points='83.62,280.95 114.46,283.84 145.30,272.26 176.14,263.58 206.99,251.27 237.83,240.42 268.67,228.84 299.51,212.19 330.36,194.10 361.20,176.73 392.04,168.77 407.46,165.88' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 3)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e15' points='83.62,281.67 114.46,275.16 145.30,269.37 176.14,265.75 206.99,257.06 237.83,244.76 268.67,235.35 299.51,221.60 330.36,204.23 361.20,188.31 392.04,168.05 407.46,163.70' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 1)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e16' points='83.62,282.39 114.46,276.60 145.30,271.54 176.14,267.20 206.99,259.96 237.83,248.38 268.67,225.94 299.51,214.36 330.36,194.82 361.20,178.18 392.04,170.94 407.46,163.70' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 12)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e17' points='83.62,283.12 114.46,276.60 145.30,270.09 176.14,259.96 206.99,251.27 237.83,237.52 268.67,223.77 299.51,212.19 330.36,194.82 361.20,176.73 392.04,160.81 407.46,156.47' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 2)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e18' points='83.62,282.39 114.46,281.67 145.30,277.33 176.14,268.64 206.99,254.89 237.83,235.35 268.67,210.02 299.51,193.38 330.36,169.49 361.20,168.05 392.04,152.85 407.46,150.68' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 5)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e19' points='83.62,282.39 114.46,276.60 145.30,267.20 176.14,254.89 206.99,238.97 237.83,219.43 268.67,193.38 299.51,173.11 330.36,147.78 361.20,132.58 392.04,124.62 407.46,119.56' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 14)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e20' points='83.62,282.39 114.46,276.60 145.30,270.81 176.14,260.68 206.99,247.66 237.83,231.01 268.67,206.40 299.51,186.14 330.36,154.30 361.20,131.14 392.04,103.64 407.46,91.33' fill='none' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 1 (Chick 7)' data-id='1' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e21' points='83.62,281.67 114.46,274.43 145.30,270.09 176.14,258.51 206.99,264.30 237.83,262.85 268.67,261.41 299.51,260.68 330.36,259.96 361.20,259.96 392.04,257.06 407.46,258.51' fill='none' stroke='#7CAE00' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 2 (Chick 24)' data-id='2' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e22' points='83.62,281.67 114.46,277.33 145.30,269.37 176.14,259.96 206.99,250.55 237.83,241.14 268.67,228.84 299.51,223.77 330.36,208.57 361.20,202.78 392.04,198.44 407.46,203.51' fill='none' stroke='#7CAE00' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 2 (Chick 30)' data-id='2' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e23' points='83.62,282.39 114.46,272.26 145.30,265.75 176.14,256.34 206.99,246.93 237.83,243.31 268.67,233.91 299.51,231.73 330.36,217.26 361.20,204.96 392.04,193.38 407.46,191.21' fill='none' stroke='#7CAE00' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 2 (Chick 22)' data-id='2' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e24' points='83.62,280.95 114.46,274.43 145.30,267.92 176.14,259.24 206.99,246.93 237.83,237.52 268.67,220.15 299.51,214.36 330.36,207.13 361.20,194.10 392.04,189.03 407.46,185.42' fill='none' stroke='#7CAE00' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 2 (Chick 23)' data-id='2' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e25' points='83.62,283.84 114.46,278.78 145.30,270.09 176.14,259.24 206.99,249.10 237.83,239.69 268.67,228.84 299.51,223.05 330.36,207.85 361.20,194.10 392.04,178.18 407.46,173.11' fill='none' stroke='#7CAE00' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 2 (Chick 27)' data-id='2' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e26' points='83.62,283.84 114.46,278.78 145.30,270.09 176.14,259.24 206.99,245.48 237.83,229.56 268.67,207.13 299.51,199.17 330.36,178.90 361.20,162.26 392.04,158.64 407.46,143.44' fill='none' stroke='#7CAE00' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 2 (Chick 28)' data-id='2' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e27' points='83.62,281.67 114.46,277.33 145.30,270.81 176.14,258.51 206.99,244.76 237.83,229.56 268.67,213.64 299.51,205.68 330.36,189.76 361.20,163.70 392.04,141.27 407.46,130.41' fill='none' stroke='#7CAE00' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 2 (Chick 26)' data-id='2' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e28' points='83.62,283.12 114.46,276.60 145.30,267.20 176.14,255.62 206.99,238.25 237.83,222.33 268.67,206.40 299.51,193.38 330.36,169.49 361.20,144.89 392.04,124.62 407.46,120.28' fill='none' stroke='#7CAE00' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 2 (Chick 25)' data-id='2' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e29' points='83.62,283.84 114.46,277.33 145.30,269.37 176.14,258.51 206.99,249.10 237.83,235.35 268.67,215.09 299.51,203.51 330.36,176.73 361.20,145.61 392.04,110.15 407.46,88.44' fill='none' stroke='#7CAE00' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 2 (Chick 29)' data-id='2' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e30' points='83.62,283.12 114.46,275.88 145.30,267.20 176.14,249.83 206.99,221.60 237.83,194.10 268.67,155.02 299.51,138.37 330.36,113.04 361.20,89.88 392.04,81.92 407.46,72.52' fill='none' stroke='#7CAE00' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 2 (Chick 21)' data-id='2' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e31' points='83.62,283.84 114.46,275.88 145.30,266.47 176.14,256.34 206.99,242.59 237.83,231.73 268.67,212.92 299.51,207.85 330.36,202.78 361.20,206.40 392.04,199.17 407.46,205.68' fill='none' stroke='#00BFC4' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 3 (Chick 33)' data-id='3' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e32' points='83.62,282.39 114.46,277.33 145.30,271.54 176.14,262.85 206.99,254.17 237.83,252.00 268.67,237.52 299.51,231.01 330.36,214.36 361.20,198.44 392.04,189.76 407.46,183.24' fill='none' stroke='#00BFC4' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 3 (Chick 37)' data-id='3' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e33' points='83.62,283.84 114.46,277.33 145.30,267.92 176.14,257.06 206.99,241.14 237.83,228.12 268.67,207.13 299.51,191.93 330.36,168.77 361.20,147.78 392.04,149.23 407.46,152.85' fill='none' stroke='#00BFC4' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 3 (Chick 36)' data-id='3' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e34' points='83.62,281.67 114.46,273.71 145.30,267.20 176.14,259.24 206.99,250.55 237.83,238.25 268.67,223.05 299.51,212.19 330.36,189.03 361.20,164.43 392.04,141.99 407.46,126.79' fill='none' stroke='#00BFC4' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 3 (Chick 31)' data-id='3' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e35' points='83.62,281.67 114.46,275.88 145.30,267.92 176.14,255.62 206.99,247.66 237.83,233.18 268.67,217.98 299.51,206.40 330.36,189.03 361.20,157.19 392.04,131.14 407.46,115.21' fill='none' stroke='#00BFC4' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 3 (Chick 39)' data-id='3' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e36' points='83.62,282.39 114.46,276.60 145.30,267.92 176.14,258.51 206.99,241.14 237.83,233.18 268.67,219.43 299.51,200.61 330.36,173.11 361.20,144.16 392.04,109.42 407.46,102.19' fill='none' stroke='#00BFC4' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 3 (Chick 38)' data-id='3' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e37' points='83.62,282.39 114.46,276.60 145.30,265.03 176.14,252.72 206.99,234.63 237.83,218.71 268.67,197.00 299.51,182.52 330.36,152.12 361.20,121.73 392.04,101.46 407.46,91.33' fill='none' stroke='#00BFC4' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 3 (Chick 32)' data-id='3' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e38' points='83.62,282.39 114.46,272.26 145.30,264.30 176.14,254.89 206.99,238.97 237.83,225.22 268.67,200.61 299.51,180.35 330.36,156.47 361.20,122.45 392.04,98.57 407.46,79.75' fill='none' stroke='#00BFC4' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 3 (Chick 40)' data-id='3' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e39' points='83.62,282.39 114.46,276.60 145.30,266.47 176.14,250.55 206.99,234.63 237.83,215.09 268.67,193.38 299.51,177.45 330.36,141.99 361.20,99.29 392.04,75.41 407.46,65.28' fill='none' stroke='#00BFC4' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 3 (Chick 34)' data-id='3' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e40' points='83.62,282.39 114.46,273.71 145.30,265.75 176.14,249.10 206.99,223.05 237.83,197.72 268.67,166.60 299.51,139.82 330.36,104.36 361.20,71.79 392.04,50.80 407.46,42.12' fill='none' stroke='#00BFC4' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 3 (Chick 35)' data-id='3' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e41' points='83.62,281.67 114.46,275.16 145.30,265.03 176.14,249.83 206.99,237.52 237.83,226.67 268.67,220.15 299.51,212.19 330.36,207.13 361.20,206.40' fill='none' stroke='#C77CFF' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 4 (Chick 44)' data-id='4' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e42' points='83.62,282.39 114.46,275.88 145.30,267.92 176.14,255.62 206.99,241.14 237.83,227.39 268.67,214.36 299.51,210.02 330.36,205.68 361.20,186.14 392.04,169.49 407.46,170.22' fill='none' stroke='#C77CFF' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 4 (Chick 45)' data-id='4' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e43' points='83.62,281.67 114.46,272.26 145.30,262.13 176.14,242.59 206.99,217.26 237.83,198.44 268.67,178.90 299.51,176.01 330.36,169.49 361.20,168.77 392.04,168.05 407.46,167.32' fill='none' stroke='#C77CFF' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 4 (Chick 43)' data-id='4' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e44' points='83.62,281.67 114.46,275.16 145.30,264.30 176.14,250.55 206.99,237.52 237.83,222.33 268.67,199.89 299.51,201.34 330.36,185.42 361.20,178.90 392.04,168.05 407.46,164.43' fill='none' stroke='#C77CFF' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 4 (Chick 41)' data-id='4' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e45' points='83.62,282.39 114.46,273.71 145.30,264.30 176.14,254.89 206.99,239.69 237.83,223.05 268.67,204.96 299.51,198.44 330.36,190.48 361.20,178.18 392.04,160.09 407.46,163.70' fill='none' stroke='#C77CFF' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 4 (Chick 47)' data-id='4' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e46' points='83.62,283.12 114.46,273.71 145.30,265.75 176.14,250.55 206.99,233.91 237.83,219.43 268.67,202.06 299.51,191.93 330.36,178.90 361.20,165.15 392.04,143.44 407.46,140.54' fill='none' stroke='#C77CFF' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 4 (Chick 49)' data-id='4' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e47' points='83.62,283.12 114.46,274.43 145.30,267.20 176.14,252.72 206.99,238.97 237.83,225.22 268.67,207.85 299.51,199.17 330.36,186.86 361.20,160.09 392.04,144.89 407.46,139.82' fill='none' stroke='#C77CFF' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 4 (Chick 46)' data-id='4' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e48' points='83.62,282.39 114.46,272.99 145.30,263.58 176.14,251.27 206.99,236.08 237.83,223.77 268.67,199.89 299.51,185.42 330.36,163.70 361.20,142.72 392.04,121.00 407.46,121.00' fill='none' stroke='#C77CFF' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 4 (Chick 50)' data-id='4' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e49' points='83.62,281.67 114.46,276.60 145.30,266.47 176.14,251.27 206.99,237.52 237.83,220.88 268.67,196.27 299.51,186.14 330.36,164.43 361.20,142.72 392.04,117.39 407.46,108.70' fill='none' stroke='#C77CFF' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 4 (Chick 42)' data-id='4' nearest='true'/>\n   <polyline id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e50' points='83.62,283.84 114.46,275.88 145.30,267.20 176.14,254.17 206.99,236.80 237.83,221.60 268.67,200.61 299.51,189.03 330.36,151.40 361.20,123.18 392.04,92.78 407.46,79.03' fill='none' stroke='#C77CFF' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' title='Diet 4 (Chick 48)' data-id='4' nearest='true'/>\n  <\/g>\n  <g clip-path='url(#svg_272e5630_23a8_4e02_89f8_f6570e52c15d_c1)'>\n   <text x='47.54' y='243.78' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>100<\/text>\n   <text x='47.54' y='171.41' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>200<\/text>\n   <text x='47.54' y='99.04' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>300<\/text>\n   <text x='80.78' y='310' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>0<\/text>\n   <text x='157.89' y='310' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>5<\/text>\n   <text x='232.16' y='310' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>10<\/text>\n   <text x='309.26' y='310' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>15<\/text>\n   <text x='386.37' y='310' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>20<\/text>\n   <text x='229.78' y='326.7' font-size='12pt' font-family='Roboto Condensed'>Time<\/text>\n   <text transform='translate(41.26,185.37) rotate(-90.00)' font-size='12pt' font-family='Roboto Condensed'>weight<\/text>\n   <text x='440.84' y='131.09' font-size='8.62pt' font-family='Roboto Condensed'>Diet<\/text>\n   <line id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e51' x1='442.57' y1='146.69' x2='456.39' y2='146.69' stroke='#F8766D' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' nearest='true'/>\n   <line id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e52' x1='442.57' y1='163.97' x2='456.39' y2='163.97' stroke='#7CAE00' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' nearest='true'/>\n   <line id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e53' x1='442.57' y1='181.25' x2='456.39' y2='181.25' stroke='#00BFC4' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' nearest='true'/>\n   <line id='svg_272e5630_23a8_4e02_89f8_f6570e52c15d_e54' x1='442.57' y1='198.53' x2='456.39' y2='198.53' stroke='#C77CFF' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt' nearest='true'/>\n   <text x='463.85' y='149.95' font-size='6.9pt' font-family='Roboto Condensed'>1<\/text>\n   <text x='463.85' y='167.23' font-size='6.9pt' font-family='Roboto Condensed'>2<\/text>\n   <text x='463.85' y='184.51' font-size='6.9pt' font-family='Roboto Condensed'>3<\/text>\n   <text x='463.85' y='201.79' font-size='6.9pt' font-family='Roboto Condensed'>4<\/text>\n  <\/g>\n <\/g>\n<\/svg>","js":null,"uid":"svg_272e5630_23a8_4e02_89f8_f6570e52c15d","ratio":1.4,"settings":{"tooltip":{"css":".tooltip_SVGID_ { padding:5px;background:black;color:white;border-radius:2px;text-align:left; ; position:absolute;pointer-events:none;z-index:999;}","placement":"doc","opacity":0.9,"offx":10,"offy":10,"use_cursor_pos":true,"use_fill":false,"use_stroke":false,"delay_over":200,"delay_out":500},"hover":{"css":"","reactive":false,"nearest_distance":null},"hover_inv":{"css":".hover_inv_SVGID_ { opacity: 0.1 }"},"hover_key":{"css":".hover_key_SVGID_ { fill:orange;stroke:black;cursor:pointer; }\ntext.hover_key_SVGID_ { stroke:none;fill:orange; }\ncircle.hover_key_SVGID_ { fill:orange;stroke:black; }\nline.hover_key_SVGID_, polyline.hover_key_SVGID_ { fill:none;stroke:orange; }\nrect.hover_key_SVGID_, polygon.hover_key_SVGID_, path.hover_key_SVGID_ { fill:orange;stroke:none; }\nimage.hover_key_SVGID_ { stroke:orange; }","reactive":true},"hover_theme":{"css":".hover_theme_SVGID_ { fill:orange;stroke:black;cursor:pointer; }\ntext.hover_theme_SVGID_ { stroke:none;fill:orange; }\ncircle.hover_theme_SVGID_ { fill:orange;stroke:black; }\nline.hover_theme_SVGID_, polyline.hover_theme_SVGID_ { fill:none;stroke:orange; }\nrect.hover_theme_SVGID_, polygon.hover_theme_SVGID_, path.hover_theme_SVGID_ { fill:orange;stroke:none; }\nimage.hover_theme_SVGID_ { stroke:orange; }","reactive":true},"select":{"css":".select_data_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_data_SVGID_ { stroke:none;fill:red; }\ncircle.select_data_SVGID_ { fill:red;stroke:black; }\nline.select_data_SVGID_, polyline.select_data_SVGID_ { fill:none;stroke:red; }\nrect.select_data_SVGID_, polygon.select_data_SVGID_, path.select_data_SVGID_ { fill:red;stroke:none; }\nimage.select_data_SVGID_ { stroke:red; }","type":"multiple","only_shiny":true,"selected":[]},"select_inv":{"css":""},"select_key":{"css":".select_key_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_key_SVGID_ { stroke:none;fill:red; }\ncircle.select_key_SVGID_ { fill:red;stroke:black; }\nline.select_key_SVGID_, polyline.select_key_SVGID_ { fill:none;stroke:red; }\nrect.select_key_SVGID_, polygon.select_key_SVGID_, path.select_key_SVGID_ { fill:red;stroke:none; }\nimage.select_key_SVGID_ { stroke:red; }","type":"single","only_shiny":true,"selected":[]},"select_theme":{"css":".select_theme_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_theme_SVGID_ { stroke:none;fill:red; }\ncircle.select_theme_SVGID_ { fill:red;stroke:black; }\nline.select_theme_SVGID_, polyline.select_theme_SVGID_ { fill:none;stroke:red; }\nrect.select_theme_SVGID_, polygon.select_theme_SVGID_, path.select_theme_SVGID_ { fill:red;stroke:none; }\nimage.select_theme_SVGID_ { stroke:red; }","type":"single","only_shiny":true,"selected":[]},"zoom":{"min":1,"max":1,"duration":300},"toolbar":{"position":"topright","pngname":"diagram","tooltips":null,"hidden":"saveaspng","delay_over":200,"delay_out":500},"sizing":{"rescale":true,"width":1}}},"evals":[],"jsHooks":[]}</script>
</div>
</div>
</section><section id="javascript-on-click" class="level2"><h2 class="anchored" data-anchor-id="javascript-on-click">Javascript on click</h2>
<p>The <code>onclick</code> aesthetic allows for execution of JavaScript on click. This is probably more useful in a Shiny project, but it does work even on static HTML pages. Here we get an alert when we click:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-5_ff1209004c6e66e6de626281a60b7d68">
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot_3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">penguins</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">species</span>, fill <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">island</span>,</span>
<span>             tooltip <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/sprintf.html">sprintf</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Island: %s | Species: %s'</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">island</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">species</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>,</span>
<span>             data_id <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">island</span>,</span>
<span>             onclick <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/sprintf.html">sprintf</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'alert("Island: %s | Species: %s");'</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">island</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">species</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>             <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>         <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/ggiraph/reference/geom_bar_interactive.html">geom_bar_interactive</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/ggiraph/reference/girafe.html">girafe</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>ggobj <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot_3</span>,</span>
<span>       options <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/ggiraph/reference/opts_hover.html">opts_hover</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>css <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Don't change CSS for selected group</span></span>
<span>         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/ggiraph/reference/opts_hover.html">opts_hover_inv</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>css <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill: gray"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># CSS for non-selected groups</span></span>
<span>         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://davidgohel.github.io/ggiraph/reference/opts_toolbar.html">opts_toolbar</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>saveaspng <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Don't include save button</span></span>
<span>       <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output-display">
<div class="girafe html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-44227978ea4380b506dc" style="width:100%;height:464px;"></div>
<script type="application/json" data-for="htmlwidget-44227978ea4380b506dc">{"x":{"html":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' class='ggiraph-svg' role='img' id='svg_76c46d75_5eb8_41a6_9a51_9cecf3876db3' viewBox='0 0 504 360'>\n <defs id='svg_76c46d75_5eb8_41a6_9a51_9cecf3876db3_defs'>\n  <clipPath id='svg_76c46d75_5eb8_41a6_9a51_9cecf3876db3_c1'>\n   <rect x='0' y='0' width='504' height='360'/>\n  <\/clipPath>\n  <clipPath id='svg_76c46d75_5eb8_41a6_9a51_9cecf3876db3_c2'>\n   <rect x='67.43' y='29.89' width='324.01' height='269.08'/>\n  <\/clipPath>\n <\/defs>\n <g id='svg_76c46d75_5eb8_41a6_9a51_9cecf3876db3_rootg' class='ggiraph-svg-rootg'>\n  <g clip-path='url(#svg_76c46d75_5eb8_41a6_9a51_9cecf3876db3_c1)'>\n   <rect x='0' y='0' width='504' height='360' fill='#FFFFFF' fill-opacity='1' stroke='#FFFFFF' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='round' class='ggiraph-svg-bg'/>\n  <\/g>\n  <g clip-path='url(#svg_76c46d75_5eb8_41a6_9a51_9cecf3876db3_c2)'>\n   <polyline points='67.43,246.50 391.44,246.50' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.32' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='67.43,166.04 391.44,166.04' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.32' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='67.43,85.57 391.44,85.57' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.32' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='67.43,286.74 391.44,286.74' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='67.43,206.27 391.44,206.27' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='67.43,125.80 391.44,125.80' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='67.43,45.34 391.44,45.34' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='128.18,298.97 128.18,29.89' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='229.43,298.97 229.43,29.89' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='330.69,298.97 330.69,29.89' fill='none' stroke='#CCCCCC' stroke-opacity='1' stroke-width='0.43' stroke-linejoin='round' stroke-linecap='butt'/>\n   <rect id='svg_76c46d75_5eb8_41a6_9a51_9cecf3876db3_e1' x='82.61' y='42.12' width='91.13' height='70.81' fill='#F8766D' fill-opacity='1' stroke='none' title='Island: Biscoe | Species: Adelie' data-id='Biscoe' onclick='alert(\"Island: Biscoe | Species: Adelie\");'/>\n   <rect id='svg_76c46d75_5eb8_41a6_9a51_9cecf3876db3_e2' x='82.61' y='112.93' width='91.13' height='90.12' fill='#00BA38' fill-opacity='1' stroke='none' title='Island: Dream | Species: Adelie' data-id='Dream' onclick='alert(\"Island: Dream | Species: Adelie\");'/>\n   <rect id='svg_76c46d75_5eb8_41a6_9a51_9cecf3876db3_e3' x='82.61' y='203.05' width='91.13' height='83.69' fill='#619CFF' fill-opacity='1' stroke='none' title='Island: Torgersen | Species: Adelie' data-id='Torgersen' onclick='alert(\"Island: Torgersen | Species: Adelie\");'/>\n   <rect id='svg_76c46d75_5eb8_41a6_9a51_9cecf3876db3_e4' x='183.87' y='177.3' width='91.13' height='109.43' fill='#00BA38' fill-opacity='1' stroke='none' title='Island: Dream | Species: Chinstrap' data-id='Dream' onclick='alert(\"Island: Dream | Species: Chinstrap\");'/>\n   <rect id='svg_76c46d75_5eb8_41a6_9a51_9cecf3876db3_e5' x='285.12' y='87.18' width='91.13' height='199.56' fill='#F8766D' fill-opacity='1' stroke='none' title='Island: Biscoe | Species: Gentoo' data-id='Biscoe' onclick='alert(\"Island: Biscoe | Species: Gentoo\");'/>\n  <\/g>\n  <g clip-path='url(#svg_76c46d75_5eb8_41a6_9a51_9cecf3876db3_c1)'>\n   <text x='58.89' y='290.82' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>0<\/text>\n   <text x='53.21' y='210.36' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>50<\/text>\n   <text x='47.54' y='129.89' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>100<\/text>\n   <text x='47.54' y='49.42' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>150<\/text>\n   <text x='113.99' y='310' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>Adelie<\/text>\n   <text x='207.64' y='310' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>Chinstrap<\/text>\n   <text x='314.34' y='310' font-size='8.62pt' font-family='Roboto Condensed' fill='#4D4D4D' fill-opacity='1'>Gentoo<\/text>\n   <text x='205.19' y='326.7' font-size='12pt' font-family='Roboto Condensed'>species<\/text>\n   <text transform='translate(41.26,182.23) rotate(-90.00)' font-size='12pt' font-family='Roboto Condensed'>count<\/text>\n   <text x='408.63' y='139.73' font-size='8.62pt' font-family='Roboto Condensed'>island<\/text>\n   <rect x='409.33' y='147.39' width='15.86' height='15.86' fill='#F8766D' fill-opacity='1' stroke='none'/>\n   <rect x='409.33' y='164.67' width='15.86' height='15.86' fill='#00BA38' fill-opacity='1' stroke='none'/>\n   <rect x='409.33' y='181.95' width='15.86' height='15.86' fill='#619CFF' fill-opacity='1' stroke='none'/>\n   <text x='431.63' y='158.59' font-size='6.9pt' font-family='Roboto Condensed'>Biscoe<\/text>\n   <text x='431.63' y='175.87' font-size='6.9pt' font-family='Roboto Condensed'>Dream<\/text>\n   <text x='431.63' y='193.15' font-size='6.9pt' font-family='Roboto Condensed'>Torgersen<\/text>\n  <\/g>\n <\/g>\n<\/svg>","js":null,"uid":"svg_76c46d75_5eb8_41a6_9a51_9cecf3876db3","ratio":1.4,"settings":{"tooltip":{"css":".tooltip_SVGID_ { padding:5px;background:black;color:white;border-radius:2px;text-align:left; ; position:absolute;pointer-events:none;z-index:999;}","placement":"doc","opacity":0.9,"offx":10,"offy":10,"use_cursor_pos":true,"use_fill":false,"use_stroke":false,"delay_over":200,"delay_out":500},"hover":{"css":"","reactive":false,"nearest_distance":null},"hover_inv":{"css":".hover_inv_SVGID_ { fill: gray }"},"hover_key":{"css":".hover_key_SVGID_ { fill:orange;stroke:black;cursor:pointer; }\ntext.hover_key_SVGID_ { stroke:none;fill:orange; }\ncircle.hover_key_SVGID_ { fill:orange;stroke:black; }\nline.hover_key_SVGID_, polyline.hover_key_SVGID_ { fill:none;stroke:orange; }\nrect.hover_key_SVGID_, polygon.hover_key_SVGID_, path.hover_key_SVGID_ { fill:orange;stroke:none; }\nimage.hover_key_SVGID_ { stroke:orange; }","reactive":true},"hover_theme":{"css":".hover_theme_SVGID_ { fill:orange;stroke:black;cursor:pointer; }\ntext.hover_theme_SVGID_ { stroke:none;fill:orange; }\ncircle.hover_theme_SVGID_ { fill:orange;stroke:black; }\nline.hover_theme_SVGID_, polyline.hover_theme_SVGID_ { fill:none;stroke:orange; }\nrect.hover_theme_SVGID_, polygon.hover_theme_SVGID_, path.hover_theme_SVGID_ { fill:orange;stroke:none; }\nimage.hover_theme_SVGID_ { stroke:orange; }","reactive":true},"select":{"css":".select_data_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_data_SVGID_ { stroke:none;fill:red; }\ncircle.select_data_SVGID_ { fill:red;stroke:black; }\nline.select_data_SVGID_, polyline.select_data_SVGID_ { fill:none;stroke:red; }\nrect.select_data_SVGID_, polygon.select_data_SVGID_, path.select_data_SVGID_ { fill:red;stroke:none; }\nimage.select_data_SVGID_ { stroke:red; }","type":"multiple","only_shiny":true,"selected":[]},"select_inv":{"css":""},"select_key":{"css":".select_key_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_key_SVGID_ { stroke:none;fill:red; }\ncircle.select_key_SVGID_ { fill:red;stroke:black; }\nline.select_key_SVGID_, polyline.select_key_SVGID_ { fill:none;stroke:red; }\nrect.select_key_SVGID_, polygon.select_key_SVGID_, path.select_key_SVGID_ { fill:red;stroke:none; }\nimage.select_key_SVGID_ { stroke:red; }","type":"single","only_shiny":true,"selected":[]},"select_theme":{"css":".select_theme_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_theme_SVGID_ { stroke:none;fill:red; }\ncircle.select_theme_SVGID_ { fill:red;stroke:black; }\nline.select_theme_SVGID_, polyline.select_theme_SVGID_ { fill:none;stroke:red; }\nrect.select_theme_SVGID_, polygon.select_theme_SVGID_, path.select_theme_SVGID_ { fill:red;stroke:none; }\nimage.select_theme_SVGID_ { stroke:red; }","type":"single","only_shiny":true,"selected":[]},"zoom":{"min":1,"max":1,"duration":300},"toolbar":{"position":"topright","pngname":"diagram","tooltips":null,"hidden":"saveaspng","delay_over":200,"delay_out":500},"sizing":{"rescale":true,"width":1}}},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<!-- End content -->
<div id="footer-session-info">
<details><summary>
Session info and package versions
</summary><div class="cell" data-hash="index_cache/html/unnamed-chunk-7_026ab0fdd59598f7b179c4f0fc1c5f3c">
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code> setting  value
 version  R version 4.3.1 (2023-06-16)
 os       macOS Ventura 13.4.1
 system   aarch64, darwin20
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Chicago
 date     2023-07-08
 pandoc   3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Packages ───────────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>           package loadedversion       date         source
          asbutils    0.0.0.9001 2023-07-06          local
               cli         3.6.1 2023-03-23 CRAN (R 4.3.0)
         codetools        0.2-19 2023-02-01 CRAN (R 4.3.1)
        colorspace         2.1-0 2023-01-23 CRAN (R 4.3.0)
            crayon         1.5.2 2022-09-29 CRAN (R 4.3.0)
              crul         1.4.0 2023-05-17 CRAN (R 4.3.0)
              curl         5.0.1 2023-06-07 CRAN (R 4.3.0)
            digest        0.6.31 2022-12-11 CRAN (R 4.3.0)
             dplyr         1.1.2 2023-04-20 CRAN (R 4.3.0)
          ellipsis         0.3.2 2021-04-29 CRAN (R 4.3.0)
          evaluate          0.21 2023-05-05 CRAN (R 4.3.0)
         extrafont          0.19 2023-01-18 CRAN (R 4.3.0)
       extrafontdb           1.0 2012-06-11 CRAN (R 4.3.0)
             fansi         1.0.4 2023-01-22 CRAN (R 4.3.0)
            farver         2.1.1 2022-07-06 CRAN (R 4.3.0)
           fastmap         1.1.1 2023-02-24 CRAN (R 4.3.0)
 fontBitstreamVera         0.1.1 2017-02-01 CRAN (R 4.3.0)
    fontLiberation         0.1.0 2016-10-15 CRAN (R 4.3.0)
        fontquiver         0.2.1 2017-02-01 CRAN (R 4.3.0)
           gdtools         0.3.3 2023-03-27 CRAN (R 4.3.0)
          generics         0.1.3 2022-07-05 CRAN (R 4.3.0)
            gfonts         0.2.0 2023-01-08 CRAN (R 4.3.0)
           ggiraph         0.8.7 2023-03-17 CRAN (R 4.3.0)
           ggplot2         3.4.2 2023-04-03 CRAN (R 4.3.0)
              glue         1.6.2 2022-02-24 CRAN (R 4.3.0)
            gtable         0.3.3 2023-03-21 CRAN (R 4.3.0)
        hrbrthemes         0.8.0 2020-03-06 CRAN (R 4.3.0)
         htmltools         0.5.5 2023-03-23 CRAN (R 4.3.0)
       htmlwidgets         1.6.2 2023-03-17 CRAN (R 4.3.0)
          httpcode         0.3.0 2020-04-10 CRAN (R 4.3.0)
            httpuv        1.6.11 2023-05-11 CRAN (R 4.3.0)
          jsonlite         1.8.7 2023-06-29 CRAN (R 4.3.0)
             knitr          1.43 2023-05-25 CRAN (R 4.3.0)
          labeling         0.4.2 2020-10-20 CRAN (R 4.3.0)
             later         1.3.1 2023-05-02 CRAN (R 4.3.0)
         lifecycle         1.0.3 2022-10-07 CRAN (R 4.3.0)
          magrittr         2.0.3 2022-03-30 CRAN (R 4.3.0)
              mime          0.12 2021-09-28 CRAN (R 4.3.0)
           munsell         0.5.0 2018-06-12 CRAN (R 4.3.0)
    palmerpenguins         0.1.1 2022-08-15 CRAN (R 4.3.0)
            pillar         1.9.0 2023-03-22 CRAN (R 4.3.0)
         pkgconfig         2.0.3 2019-09-22 CRAN (R 4.3.0)
          promises       1.2.0.1 2021-02-11 CRAN (R 4.3.0)
             purrr         1.0.1 2023-01-10 CRAN (R 4.3.0)
                R6         2.5.1 2021-08-19 CRAN (R 4.3.0)
              ragg         1.2.5 2023-01-12 CRAN (R 4.3.0)
              Rcpp        1.0.10 2023-01-22 CRAN (R 4.3.0)
              renv        0.17.3 2023-04-06 CRAN (R 4.3.0)
             rlang         1.1.1 2023-04-28 CRAN (R 4.3.0)
         rmarkdown          2.22 2023-06-01 CRAN (R 4.3.0)
        rstudioapi          0.14 2022-08-22 CRAN (R 4.3.0)
          Rttf2pt1        1.3.12 2023-01-22 CRAN (R 4.3.0)
            scales         1.2.1 2022-08-20 CRAN (R 4.3.0)
       sessioninfo         1.2.2 2021-12-06 CRAN (R 4.3.0)
             shiny         1.7.4 2022-12-15 CRAN (R 4.3.0)
       systemfonts         1.0.4 2022-02-11 CRAN (R 4.3.0)
       textshaping         0.3.6 2021-10-13 CRAN (R 4.3.0)
            tibble         3.2.1 2023-03-20 CRAN (R 4.3.0)
        tidyselect         1.2.0 2022-10-10 CRAN (R 4.3.0)
              utf8         1.2.3 2023-01-31 CRAN (R 4.3.0)
              uuid         1.1-0 2022-04-19 CRAN (R 4.3.0)
             vctrs         0.6.3 2023-06-14 CRAN (R 4.3.0)
             withr         2.5.0 2022-03-03 CRAN (R 4.3.0)
              xfun          0.39 2023-04-20 CRAN (R 4.3.0)
            xtable         1.8-4 2019-04-21 CRAN (R 4.3.0)
              yaml         2.3.7 2023-01-23 CRAN (R 4.3.0)</code></pre>
</div>
</div>
</details>
</div>


</section><div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>
<ol>
<li id="fn1"><p>For similar functionality in static graphs (i.e., highlighting one particular group), the <a href="https://cran.r-project.org/web/packages/gghighlight/vignettes/gghighlight.html"><code>gghighlight</code> package</a>.↩︎</p></li>
</ol></section></div> ]]></description>
  <category>visualization</category>
  <category>interactivity</category>
  <guid>https://abraver.github.io/usefulRstuff/posts/ggiraph/index.html</guid>
  <pubDate>Thu, 29 Jun 2023 05:00:00 GMT</pubDate>
</item>
<item>
  <title>Summary statistics for dfs with skimr
</title>
  <dc:creator>Aaron Braver</dc:creator>
  <link>https://abraver.github.io/usefulRstuff/posts/skimr/index.html</link>
  <description><![CDATA[ <script src="../../jquery-3.7.0.min.js"></script><script src="../../fold.js"></script><script src="../../move_session_info.js"></script><!-- begin content --><div class="cell" data-hash="index_cache/html/setup_668d215c957f387f8bc5bbdc3236a799">
<details><summary>Setup</summary><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org">dplyr</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</details>
</div>
<p><a href="https://docs.ropensci.org/skimr/"><code>skimr::skim()</code></a> provides handy summary statistics for <code>df</code>s and related objects, including little sparkline-style histograms right in the output.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-2_5e7697a29cb535fcf6edbae43be12029">
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://docs.ropensci.org/skimr/">skimr</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">palmerpenguins</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://allisonhorst.github.io/palmerpenguins/reference/penguins.html">penguins</a></span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://docs.ropensci.org/skimr/reference/skim.html">skim</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-3_b8c5321ba0da1f7afbae6c8c65f08ff6">
<div class="cell-output cell-output-stdout">
<pre><code>── Data Summary ────────────────────────
                           Values                  
Name                       palmerpenguins::penguins
Number of rows             344                     
Number of columns          8                       
_______________________                            
Column type frequency:                             
  factor                   3                       
  numeric                  5                       
________________________                           
Group variables            None                    

── Variable type: factor ───────────────────────────────────────────────────────
  skim_variable n_missing complete_rate ordered n_unique
1 species               0         1     FALSE          3
2 island                0         1     FALSE          3
3 sex                  11         0.968 FALSE          2
  top_counts                 
1 Ade: 152, Gen: 124, Chi: 68
2 Bis: 168, Dre: 124, Tor: 52
3 mal: 168, fem: 165         

── Variable type: numeric ──────────────────────────────────────────────────────
  skim_variable     n_missing complete_rate   mean      sd     p0    p25    p50
1 bill_length_mm            2         0.994   43.9   5.46    32.1   39.2   44.4
2 bill_depth_mm             2         0.994   17.2   1.97    13.1   15.6   17.3
3 flipper_length_mm         2         0.994  201.   14.1    172    190    197  
4 body_mass_g               2         0.994 4202.  802.    2700   3550   4050  
5 year                      0         1     2008.    0.818 2007   2007   2008  
     p75   p100 hist 
1   48.5   59.6 ▃▇▇▆▁
2   18.7   21.5 ▅▅▇▇▂
3  213    231   ▂▇▃▅▂
4 4750   6300   ▃▇▆▃▂
5 2009   2009   ▇▁▇▁▇</code></pre>
</div>
</div>
<p>It also handles grouped data nicely:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-4_65b37e679154a5729468d70c333e4342">
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">palmerpenguins</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://allisonhorst.github.io/palmerpenguins/reference/penguins.html">penguins</a></span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">species</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://docs.ropensci.org/skimr/reference/skim.html">skim</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-5_aedac71a0fd58d6ae7a4627363f365cc">
<div class="cell-output cell-output-stdout">
<pre><code>── Data Summary ────────────────────────
                           Values                      
Name                       group_by(palmerpenguins::...
Number of rows             344                         
Number of columns          8                           
_______________________                                
Column type frequency:                                 
  factor                   2                           
  numeric                  5                           
________________________                               
Group variables            species                     

── Variable type: factor ───────────────────────────────────────────────────────
  skim_variable species   n_missing complete_rate ordered n_unique
1 island        Adelie            0         1     FALSE          3
2 island        Chinstrap         0         1     FALSE          1
3 island        Gentoo            0         1     FALSE          1
4 sex           Adelie            6         0.961 FALSE          2
5 sex           Chinstrap         0         1     FALSE          2
6 sex           Gentoo            5         0.960 FALSE          2
  top_counts               
1 Dre: 56, Tor: 52, Bis: 44
2 Dre: 68, Bis: 0, Tor: 0  
3 Bis: 124, Dre: 0, Tor: 0 
4 fem: 73, mal: 73         
5 fem: 34, mal: 34         
6 mal: 61, fem: 58         

── Variable type: numeric ──────────────────────────────────────────────────────
   skim_variable     species   n_missing complete_rate   mean      sd     p0
 1 bill_length_mm    Adelie            1         0.993   38.8   2.66    32.1
 2 bill_length_mm    Chinstrap         0         1       48.8   3.34    40.9
 3 bill_length_mm    Gentoo            1         0.992   47.5   3.08    40.9
 4 bill_depth_mm     Adelie            1         0.993   18.3   1.22    15.5
 5 bill_depth_mm     Chinstrap         0         1       18.4   1.14    16.4
 6 bill_depth_mm     Gentoo            1         0.992   15.0   0.981   13.1
 7 flipper_length_mm Adelie            1         0.993  190.    6.54   172  
 8 flipper_length_mm Chinstrap         0         1      196.    7.13   178  
 9 flipper_length_mm Gentoo            1         0.992  217.    6.48   203  
10 body_mass_g       Adelie            1         0.993 3701.  459.    2850  
11 body_mass_g       Chinstrap         0         1     3733.  384.    2700  
12 body_mass_g       Gentoo            1         0.992 5076.  504.    3950  
13 year              Adelie            0         1     2008.    0.822 2007  
14 year              Chinstrap         0         1     2008.    0.863 2007  
15 year              Gentoo            0         1     2008.    0.792 2007  
      p25    p50    p75   p100 hist 
 1   36.8   38.8   40.8   46   ▁▆▇▆▁
 2   46.3   49.6   51.1   58   ▂▇▇▅▁
 3   45.3   47.3   49.6   59.6 ▃▇▆▁▁
 4   17.5   18.4   19     21.5 ▂▆▇▃▁
 5   17.5   18.4   19.4   20.8 ▅▇▇▆▂
 6   14.2   15     15.7   17.3 ▅▇▇▆▂
 7  186    190    195    210   ▁▆▇▅▁
 8  191    196    201    212   ▁▅▇▅▂
 9  212    216    221    231   ▂▇▇▆▃
10 3350   3700   4000   4775   ▅▇▇▃▂
11 3488.  3700   3950   4800   ▁▅▇▃▁
12 4700   5000   5500   6300   ▃▇▇▇▂
13 2007   2008   2009   2009   ▇▁▇▁▇
14 2007   2008   2009   2009   ▇▁▆▁▇
15 2007   2008   2009   2009   ▆▁▇▁▇</code></pre>
</div>
</div>
<p>And finally, since the output of <code><a href="https://docs.ropensci.org/skimr/reference/skim.html">skim()</a></code> has class <code>data.frame</code>, you can include it in a pipeline, e.g.&nbsp;to filter by one of the summary statistics:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-6_e1bef466cf2932c3d1096b6eb254e0a2">
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">palmerpenguins</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://allisonhorst.github.io/palmerpenguins/reference/penguins.html">penguins</a></span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://docs.ropensci.org/skimr/reference/skim.html">skim</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">numeric.sd</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</div>
<div class="cell fold o" data-hash="index_cache/html/unnamed-chunk-7_3d55fc2f927181f7edd3f350d1472830">
<div class="cell-output cell-output-stdout">
<pre><code>── Data Summary ────────────────────────
                           Values                  
Name                       palmerpenguins::penguins
Number of rows             344                     
Number of columns          8                       
_______________________                            
Column type frequency:                             
  numeric                  4                       
________________________                           
Group variables            None                    

── Variable type: numeric ──────────────────────────────────────────────────────
  skim_variable     n_missing complete_rate   mean     sd     p0    p25    p50
1 bill_length_mm            2         0.994   43.9   5.46   32.1   39.2   44.4
2 bill_depth_mm             2         0.994   17.2   1.97   13.1   15.6   17.3
3 flipper_length_mm         2         0.994  201.   14.1   172    190    197  
4 body_mass_g               2         0.994 4202.  802.   2700   3550   4050  
     p75   p100 hist 
1   48.5   59.6 ▃▇▇▆▁
2   18.7   21.5 ▅▅▇▇▂
3  213    231   ▂▇▃▅▂
4 4750   6300   ▃▇▆▃▂</code></pre>
</div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-8_56d73a9cf26d2497dcc3aadc6d6648b9">
<div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">palmerpenguins</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://allisonhorst.github.io/palmerpenguins/reference/penguins.html">penguins</a></span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://docs.ropensci.org/skimr/reference/skim.html">skim</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">factor.n_unique</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</div>
<div class="cell fold o" data-hash="index_cache/html/unnamed-chunk-9_6e20e48d84dd47aaea8a78507cf02945">
<div class="cell-output cell-output-stdout">
<pre><code>── Data Summary ────────────────────────
                           Values                  
Name                       palmerpenguins::penguins
Number of rows             344                     
Number of columns          8                       
_______________________                            
Column type frequency:                             
  factor                   3                       
________________________                           
Group variables            None                    

── Variable type: factor ───────────────────────────────────────────────────────
  skim_variable n_missing complete_rate ordered n_unique
1 species               0         1     FALSE          3
2 island                0         1     FALSE          3
3 sex                  11         0.968 FALSE          2
  top_counts                 
1 Ade: 152, Gen: 124, Chi: 68
2 Bis: 168, Dre: 124, Tor: 52
3 mal: 168, fem: 165         </code></pre>
</div>
</div>
<p><br></p>
<p>To refer to the summary statistic columns, be sure to preface the column name with the variable type, e.g.&nbsp;<code>factor.</code> or <code>numeric.</code> as appropriate. For a list of variable types and the default summary statistics for each:</p>
<div class="cell o fold" data-hash="index_cache/html/unnamed-chunk-10_2295d76350c609d2ce9a97acba07961f">
<div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://docs.ropensci.org/skimr/reference/get_default_skimmers.html">get_default_skimmer_names</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>$AsIs
[1] "n_unique"   "min_length" "max_length"

$character
[1] "min"        "max"        "empty"      "n_unique"   "whitespace"

$complex
[1] "mean"

$Date
[1] "min"      "max"      "median"   "n_unique"

$difftime
[1] "min"      "max"      "median"   "n_unique"

$factor
[1] "ordered"    "n_unique"   "top_counts"

$haven_labelled
[1] "mean" "sd"   "p0"   "p25"  "p50"  "p75"  "p100" "hist"

$list
[1] "n_unique"   "min_length" "max_length"

$logical
[1] "mean"  "count"

$numeric
[1] "mean" "sd"   "p0"   "p25"  "p50"  "p75"  "p100" "hist"

$POSIXct
[1] "min"      "max"      "median"   "n_unique"

$Timespan
[1] "min"      "max"      "median"   "n_unique"

$ts
 [1] "start"      "end"        "frequency"  "deltat"     "mean"      
 [6] "sd"         "min"        "max"        "median"     "line_graph"</code></pre>
</div>
</div>
<p>Finally, if you want to print the summary, but return the original <code>df</code>, use <code><a href="https://docs.ropensci.org/skimr/reference/skim.html">skim_tee()</a></code>.</p>
<!-- End content -->
<div id="footer-session-info">
<details><summary>
Session info and package versions
</summary><div class="cell" data-hash="index_cache/html/unnamed-chunk-12_c93db6b99817bdd368eabe3043b3795c">
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code> setting  value
 version  R version 4.3.1 (2023-06-16)
 os       macOS Ventura 13.4.1
 system   aarch64, darwin20
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Chicago
 date     2023-07-08
 pandoc   3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Packages ───────────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>           package loadedversion       date         source
         base64enc         0.1-3 2015-07-28 CRAN (R 4.3.0)
               cli         3.6.1 2023-03-23 CRAN (R 4.3.0)
         codetools        0.2-19 2023-02-01 CRAN (R 4.3.1)
            crayon         1.5.2 2022-09-29 CRAN (R 4.3.0)
              crul           1.3 2022-09-03 CRAN (R 4.3.1)
              curl         5.0.0 2023-01-12 CRAN (R 4.3.0)
            digest        0.6.31 2022-12-11 CRAN (R 4.3.0)
             dplyr         1.1.2 2023-04-20 CRAN (R 4.3.0)
          ellipsis         0.3.2 2021-04-29 CRAN (R 4.3.0)
          evaluate          0.21 2023-05-05 CRAN (R 4.3.0)
             fansi         1.0.4 2023-01-22 CRAN (R 4.3.0)
           fastmap         1.1.1 2023-02-24 CRAN (R 4.3.0)
 fontBitstreamVera         0.1.1 2017-02-01 CRAN (R 4.3.0)
    fontLiberation         0.1.0 2016-10-15 CRAN (R 4.3.0)
        fontquiver         0.2.1 2017-02-01 CRAN (R 4.3.0)
           gdtools         0.3.3 2023-03-27 CRAN (R 4.3.0)
          generics         0.1.3 2022-07-05 CRAN (R 4.3.0)
            gfonts         0.2.0 2023-01-08 CRAN (R 4.3.0)
              glue         1.6.2 2022-02-24 CRAN (R 4.3.0)
         htmltools         0.5.5 2023-03-23 CRAN (R 4.3.0)
       htmlwidgets         1.6.2 2023-03-17 CRAN (R 4.3.0)
          httpcode         0.3.0 2020-04-10 CRAN (R 4.3.0)
            httpuv        1.6.11 2023-05-11 CRAN (R 4.3.0)
          jsonlite         1.8.4 2022-12-06 CRAN (R 4.3.0)
             knitr          1.43 2023-05-25 CRAN (R 4.3.0)
             later         1.3.1 2023-05-02 CRAN (R 4.3.0)
         lifecycle         1.0.3 2022-10-07 CRAN (R 4.3.0)
          magrittr         2.0.3 2022-03-30 CRAN (R 4.3.0)
              mime          0.12 2021-09-28 CRAN (R 4.3.0)
    palmerpenguins         0.1.1 2022-08-15 CRAN (R 4.3.0)
            pillar         1.9.0 2023-03-22 CRAN (R 4.3.0)
         pkgconfig         2.0.3 2019-09-22 CRAN (R 4.3.0)
          promises       1.2.0.1 2021-02-11 CRAN (R 4.3.0)
             purrr         1.0.1 2023-01-10 CRAN (R 4.3.0)
                R6         2.5.1 2021-08-19 CRAN (R 4.3.0)
              ragg         1.2.5 2023-01-12 CRAN (R 4.3.0)
              Rcpp        1.0.10 2023-01-22 CRAN (R 4.3.0)
              renv        0.17.3 2023-04-06 CRAN (R 4.3.0)
              repr         1.1.6 2023-01-26 CRAN (R 4.3.0)
             rlang         1.1.1 2023-04-28 CRAN (R 4.3.0)
         rmarkdown          2.21 2023-03-26 CRAN (R 4.3.0)
        rstudioapi          0.14 2022-08-22 CRAN (R 4.3.0)
       sessioninfo         1.2.2 2021-12-06 CRAN (R 4.3.0)
             shiny         1.7.4 2022-12-15 CRAN (R 4.3.0)
             skimr         2.1.5 2022-12-23 CRAN (R 4.3.0)
           stringi        1.7.12 2023-01-11 CRAN (R 4.3.0)
           stringr         1.5.0 2022-12-02 CRAN (R 4.3.0)
       systemfonts         1.0.4 2022-02-11 CRAN (R 4.3.0)
       textshaping         0.3.6 2021-10-13 CRAN (R 4.3.0)
            tibble         3.2.1 2023-03-20 CRAN (R 4.3.0)
             tidyr         1.3.0 2023-01-24 CRAN (R 4.3.0)
        tidyselect         1.2.0 2022-10-10 CRAN (R 4.3.0)
              utf8         1.2.3 2023-01-31 CRAN (R 4.3.0)
             vctrs         0.6.2 2023-04-19 CRAN (R 4.3.0)
             withr         2.5.0 2022-03-03 CRAN (R 4.3.0)
              xfun          0.39 2023-04-20 CRAN (R 4.3.0)
            xtable         1.8-4 2019-04-21 CRAN (R 4.3.0)
              yaml         2.3.7 2023-01-23 CRAN (R 4.3.0)</code></pre>
</div>
</div>
</details>
</div>



 ]]></description>
  <category>dataframes</category>
  <category>summarizing</category>
  <guid>https://abraver.github.io/usefulRstuff/posts/skimr/index.html</guid>
  <pubDate>Mon, 26 Jun 2023 05:00:00 GMT</pubDate>
</item>
<item>
  <title>fuzzyjoin: Join dfs with inexact matching</title>
  <dc:creator>Aaron Braver</dc:creator>
  <link>https://abraver.github.io/usefulRstuff/posts/fuzzyjoin/index.html</link>
  <description><![CDATA[ 



<script src="../../jquery-3.7.0.min.js"></script>
<script src="../../fold.js"></script>
<script src="../../move_session_info.js"></script>
<!-- begin content -->
<div class="cell" data-hash="index_cache/html/setup_b776bcb1cc19d5561a7dbf474281a81b">
<details>
<summary>Setup</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span></code></pre></div>
</details>
</div>
<section id="join-dfs-by-string-distance" class="level2">
<h2 class="anchored" data-anchor-id="join-dfs-by-string-distance">Join <code>df</code>s by string distance</h2>
<p>Sometimes you want to join <code>df</code>s on fuzzy criteria. That’s where <code>fuzzyjoin</code> comes in. Consider this example lifted partially from the documentation:</p>
<p>Set up a <code>df</code> with some typos. We’ll join this to <code>ggplot2::diamonds</code> by <code>cut</code>, which has levels: Fair, Good, Very Good, Premium, Ideal.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-2_0af71fa9b420dec8807e2ba3567b5d7e">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create a dataframe with some typos</span></span>
<span id="cb2-2">d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">approximate_name =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Idea"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Premiums"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Premioom"</span>,</span>
<span id="cb2-3">                                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"VeryGood"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"VeryGood"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Faiir"</span>),</span>
<span id="cb2-4">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>)</span></code></pre></div>
</div>
<p>A regular inner join finds no matches, due to the typos:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-3_4e8ec02490363290b93237a7d653ee23">
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(diamonds, d, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cut =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"approximate_name"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>()</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0</code></pre>
</div>
</div>
<p><code>stringdist_inner_join()</code> however will match strings based on any of the methods available in the <code>stringdist</code> package (e.g.&nbsp;Levenshtein distance, Jaccard distance, etc).</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-4_53a0cca2ba3c10637187bd7bb5b669ac">
<div class="sourceCode cell-code" id="annotated-cell-4" style="background: #f1f3f5;"><pre class="sourceCode r code-annotation-code code-with-copy code-annotated"><code class="sourceCode r"><span id="annotated-cell-4-1">fuzzyjoin<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stringdist_inner_join</span>(diamonds, d,</span>
<span id="annotated-cell-4-2">                                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cut =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"approximate_name"</span>),</span>
<button class="code-annotation-anchor" data-target-cell="annotated-cell-4" data-target-annotation="1">1</button><span id="annotated-cell-4-3" class="code-annotation-target">                                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lv"</span>,</span>
<span id="annotated-cell-4-4">                                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_dist =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,</span>
<span id="annotated-cell-4-5">                                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">distance_col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"distance"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<button class="code-annotation-anchor" data-target-cell="annotated-cell-4" data-target-annotation="2">2</button><span id="annotated-cell-4-6" class="code-annotation-target">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">relocate</span>(approximate_name, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.after =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cut"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="annotated-cell-4-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span><div class="code-annotation-gutter-bg"></div><div class="code-annotation-gutter"></div></code></pre></div>
<div class="cell-annotation">
<dl class="code-annotation-container-hidden code-annotation-container-grid">
<dt data-target-cell="annotated-cell-4" data-target-annotation="1">1</dt>
<dd>
<span data-code-lines="3" data-code-cell="annotated-cell-4" data-code-annotation="1">Levenshtein distance</span>
</dd>
<dt data-target-cell="annotated-cell-4" data-target-annotation="2">2</dt>
<dd>
<span data-code-lines="6" data-code-cell="annotated-cell-4" data-code-annotation="2">Move these columns closer together for easier visual comparison</span>
</dd>
</dl>
</div>
<div class="cell-output-display">
<div class="kable-table">
<table class="table table-sm table-striped small">
<colgroup>
<col style="width: 6%">
<col style="width: 10%">
<col style="width: 18%">
<col style="width: 6%">
<col style="width: 8%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 9%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: right;">carat</th>
<th style="text-align: left;">cut</th>
<th style="text-align: left;">approximate_name</th>
<th style="text-align: left;">color</th>
<th style="text-align: left;">clarity</th>
<th style="text-align: right;">depth</th>
<th style="text-align: right;">table</th>
<th style="text-align: right;">price</th>
<th style="text-align: right;">x</th>
<th style="text-align: right;">y</th>
<th style="text-align: right;">z</th>
<th style="text-align: right;">type</th>
<th style="text-align: right;">distance</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">0.23</td>
<td style="text-align: left;">Ideal</td>
<td style="text-align: left;">Idea</td>
<td style="text-align: left;">E</td>
<td style="text-align: left;">SI2</td>
<td style="text-align: right;">61.5</td>
<td style="text-align: right;">55</td>
<td style="text-align: right;">326</td>
<td style="text-align: right;">3.95</td>
<td style="text-align: right;">3.98</td>
<td style="text-align: right;">2.43</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.21</td>
<td style="text-align: left;">Premium</td>
<td style="text-align: left;">Premiums</td>
<td style="text-align: left;">E</td>
<td style="text-align: left;">SI1</td>
<td style="text-align: right;">59.8</td>
<td style="text-align: right;">61</td>
<td style="text-align: right;">326</td>
<td style="text-align: right;">3.89</td>
<td style="text-align: right;">3.84</td>
<td style="text-align: right;">2.31</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td style="text-align: right;">0.21</td>
<td style="text-align: left;">Premium</td>
<td style="text-align: left;">Premioom</td>
<td style="text-align: left;">E</td>
<td style="text-align: left;">SI1</td>
<td style="text-align: right;">59.8</td>
<td style="text-align: right;">61</td>
<td style="text-align: right;">326</td>
<td style="text-align: right;">3.89</td>
<td style="text-align: right;">3.84</td>
<td style="text-align: right;">2.31</td>
<td style="text-align: right;">3</td>
<td style="text-align: right;">2</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.29</td>
<td style="text-align: left;">Premium</td>
<td style="text-align: left;">Premiums</td>
<td style="text-align: left;">I</td>
<td style="text-align: left;">VS2</td>
<td style="text-align: right;">62.4</td>
<td style="text-align: right;">58</td>
<td style="text-align: right;">334</td>
<td style="text-align: right;">4.20</td>
<td style="text-align: right;">4.23</td>
<td style="text-align: right;">2.63</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td style="text-align: right;">0.29</td>
<td style="text-align: left;">Premium</td>
<td style="text-align: left;">Premioom</td>
<td style="text-align: left;">I</td>
<td style="text-align: left;">VS2</td>
<td style="text-align: right;">62.4</td>
<td style="text-align: right;">58</td>
<td style="text-align: right;">334</td>
<td style="text-align: right;">4.20</td>
<td style="text-align: right;">4.23</td>
<td style="text-align: right;">2.63</td>
<td style="text-align: right;">3</td>
<td style="text-align: right;">2</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.24</td>
<td style="text-align: left;">Very Good</td>
<td style="text-align: left;">VeryGood</td>
<td style="text-align: left;">J</td>
<td style="text-align: left;">VVS2</td>
<td style="text-align: right;">62.8</td>
<td style="text-align: right;">57</td>
<td style="text-align: right;">336</td>
<td style="text-align: right;">3.94</td>
<td style="text-align: right;">3.96</td>
<td style="text-align: right;">2.48</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td style="text-align: right;">0.24</td>
<td style="text-align: left;">Very Good</td>
<td style="text-align: left;">VeryGood</td>
<td style="text-align: left;">J</td>
<td style="text-align: left;">VVS2</td>
<td style="text-align: right;">62.8</td>
<td style="text-align: right;">57</td>
<td style="text-align: right;">336</td>
<td style="text-align: right;">3.94</td>
<td style="text-align: right;">3.96</td>
<td style="text-align: right;">2.48</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.24</td>
<td style="text-align: left;">Very Good</td>
<td style="text-align: left;">VeryGood</td>
<td style="text-align: left;">I</td>
<td style="text-align: left;">VVS1</td>
<td style="text-align: right;">62.3</td>
<td style="text-align: right;">57</td>
<td style="text-align: right;">336</td>
<td style="text-align: right;">3.95</td>
<td style="text-align: right;">3.98</td>
<td style="text-align: right;">2.47</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td style="text-align: right;">0.24</td>
<td style="text-align: left;">Very Good</td>
<td style="text-align: left;">VeryGood</td>
<td style="text-align: left;">I</td>
<td style="text-align: left;">VVS1</td>
<td style="text-align: right;">62.3</td>
<td style="text-align: right;">57</td>
<td style="text-align: right;">336</td>
<td style="text-align: right;">3.95</td>
<td style="text-align: right;">3.98</td>
<td style="text-align: right;">2.47</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.26</td>
<td style="text-align: left;">Very Good</td>
<td style="text-align: left;">VeryGood</td>
<td style="text-align: left;">H</td>
<td style="text-align: left;">SI1</td>
<td style="text-align: right;">61.9</td>
<td style="text-align: right;">55</td>
<td style="text-align: right;">337</td>
<td style="text-align: right;">4.07</td>
<td style="text-align: right;">4.11</td>
<td style="text-align: right;">2.53</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">1</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
<section id="join-dfs-by-regex-matches" class="level2">
<h2 class="anchored" data-anchor-id="join-dfs-by-regex-matches">Join <code>df</code>s by regex matches</h2>
<p>Also extremely useful are the <code>regex_*_join</code> functions, which join based on whether there is a regex match between columns. (This example also from <a href="http://varianceexplained.org/fuzzyjoin/reference/regex_join.html">the documentation</a>)</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-5_1f3814ce097b6e221d1f7a66ba105b1f">
<div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regex_name =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^Idea"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mium"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Good"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb5-2"></span>
<span id="cb5-3">fuzzyjoin<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">regex_inner_join</span>(diamonds, d, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cut =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"regex_name"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb5-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">relocate</span>(regex_name, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.after =</span> cut) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb5-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>()</span></code></pre></div>
<div class="cell-output-display">
<div class="kable-table">
<table class="table table-sm table-striped small">
<colgroup>
<col style="width: 7%">
<col style="width: 12%">
<col style="width: 13%">
<col style="width: 7%">
<col style="width: 10%">
<col style="width: 7%">
<col style="width: 7%">
<col style="width: 7%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 6%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: right;">carat</th>
<th style="text-align: left;">cut</th>
<th style="text-align: left;">regex_name</th>
<th style="text-align: left;">color</th>
<th style="text-align: left;">clarity</th>
<th style="text-align: right;">depth</th>
<th style="text-align: right;">table</th>
<th style="text-align: right;">price</th>
<th style="text-align: right;">x</th>
<th style="text-align: right;">y</th>
<th style="text-align: right;">z</th>
<th style="text-align: right;">type</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">0.23</td>
<td style="text-align: left;">Ideal</td>
<td style="text-align: left;">^Idea</td>
<td style="text-align: left;">E</td>
<td style="text-align: left;">SI2</td>
<td style="text-align: right;">61.5</td>
<td style="text-align: right;">55</td>
<td style="text-align: right;">326</td>
<td style="text-align: right;">3.95</td>
<td style="text-align: right;">3.98</td>
<td style="text-align: right;">2.43</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.21</td>
<td style="text-align: left;">Premium</td>
<td style="text-align: left;">mium</td>
<td style="text-align: left;">E</td>
<td style="text-align: left;">SI1</td>
<td style="text-align: right;">59.8</td>
<td style="text-align: right;">61</td>
<td style="text-align: right;">326</td>
<td style="text-align: right;">3.89</td>
<td style="text-align: right;">3.84</td>
<td style="text-align: right;">2.31</td>
<td style="text-align: right;">2</td>
</tr>
<tr class="odd">
<td style="text-align: right;">0.23</td>
<td style="text-align: left;">Good</td>
<td style="text-align: left;">Good</td>
<td style="text-align: left;">E</td>
<td style="text-align: left;">VS1</td>
<td style="text-align: right;">56.9</td>
<td style="text-align: right;">65</td>
<td style="text-align: right;">327</td>
<td style="text-align: right;">4.05</td>
<td style="text-align: right;">4.07</td>
<td style="text-align: right;">2.31</td>
<td style="text-align: right;">3</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.29</td>
<td style="text-align: left;">Premium</td>
<td style="text-align: left;">mium</td>
<td style="text-align: left;">I</td>
<td style="text-align: left;">VS2</td>
<td style="text-align: right;">62.4</td>
<td style="text-align: right;">58</td>
<td style="text-align: right;">334</td>
<td style="text-align: right;">4.20</td>
<td style="text-align: right;">4.23</td>
<td style="text-align: right;">2.63</td>
<td style="text-align: right;">2</td>
</tr>
<tr class="odd">
<td style="text-align: right;">0.31</td>
<td style="text-align: left;">Good</td>
<td style="text-align: left;">Good</td>
<td style="text-align: left;">J</td>
<td style="text-align: left;">SI2</td>
<td style="text-align: right;">63.3</td>
<td style="text-align: right;">58</td>
<td style="text-align: right;">335</td>
<td style="text-align: right;">4.34</td>
<td style="text-align: right;">4.35</td>
<td style="text-align: right;">2.75</td>
<td style="text-align: right;">3</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.24</td>
<td style="text-align: left;">Very Good</td>
<td style="text-align: left;">Good</td>
<td style="text-align: left;">J</td>
<td style="text-align: left;">VVS2</td>
<td style="text-align: right;">62.8</td>
<td style="text-align: right;">57</td>
<td style="text-align: right;">336</td>
<td style="text-align: right;">3.94</td>
<td style="text-align: right;">3.96</td>
<td style="text-align: right;">2.48</td>
<td style="text-align: right;">3</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
<section id="join-dfs-by-absolute-difference-between-columns" class="level2">
<h2 class="anchored" data-anchor-id="join-dfs-by-absolute-difference-between-columns">Join <code>df</code>s by absolute difference between columns</h2>
<p>Say you want to join by two columns so long as they are equal within a certain degree of tolerance. Here we join so long as <code>sepal_lengths$Sepal.Length</code> is within 0.5 of the <code>iris$Sepal.Length</code>:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-6_57a90a80767692b396b047736462f014">
<div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">sepal_lengths <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Sepal.Length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb6-2"></span>
<span id="cb6-3">fuzzyjoin<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">difference_inner_join</span>(iris, sepal_lengths,</span>
<span id="cb6-4">                                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_dist =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb6-5">                                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">distance_col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"distance"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb6-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">relocate</span>(Sepal.Length.x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.after =</span> Sepal.Length.y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb6-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>()</span></code></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining by: "Sepal.Length"</code></pre>
</div>
<div class="cell-output-display">
<div class="kable-table">
<table class="table table-sm table-striped small">
<colgroup>
<col style="width: 13%">
<col style="width: 14%">
<col style="width: 13%">
<col style="width: 8%">
<col style="width: 16%">
<col style="width: 16%">
<col style="width: 5%">
<col style="width: 10%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: right;">Sepal.Width</th>
<th style="text-align: right;">Petal.Length</th>
<th style="text-align: right;">Petal.Width</th>
<th style="text-align: left;">Species</th>
<th style="text-align: right;">Sepal.Length.y</th>
<th style="text-align: right;">Sepal.Length.x</th>
<th style="text-align: right;">Type</th>
<th style="text-align: right;">distance</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">3.5</td>
<td style="text-align: right;">1.4</td>
<td style="text-align: right;">0.2</td>
<td style="text-align: left;">setosa</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">5.1</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0.1</td>
</tr>
<tr class="even">
<td style="text-align: right;">3.0</td>
<td style="text-align: right;">1.4</td>
<td style="text-align: right;">0.2</td>
<td style="text-align: left;">setosa</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">4.9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0.1</td>
</tr>
<tr class="odd">
<td style="text-align: right;">3.2</td>
<td style="text-align: right;">1.3</td>
<td style="text-align: right;">0.2</td>
<td style="text-align: left;">setosa</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">4.7</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0.3</td>
</tr>
<tr class="even">
<td style="text-align: right;">3.1</td>
<td style="text-align: right;">1.5</td>
<td style="text-align: right;">0.2</td>
<td style="text-align: left;">setosa</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">4.6</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0.4</td>
</tr>
<tr class="odd">
<td style="text-align: right;">3.6</td>
<td style="text-align: right;">1.4</td>
<td style="text-align: right;">0.2</td>
<td style="text-align: left;">setosa</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">5.0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0.0</td>
</tr>
<tr class="even">
<td style="text-align: right;">3.9</td>
<td style="text-align: right;">1.7</td>
<td style="text-align: right;">0.4</td>
<td style="text-align: left;">setosa</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">5.4</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0.4</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- End content -->
<div id="footer-session-info">
<details>
<summary>
Session info and package versions
</summary>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-8_d940852e96ac00760d6bf757ff970562">
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code> setting  value
 version  R version 4.3.1 (2023-06-16)
 os       macOS Ventura 13.4.1
 system   aarch64, darwin20
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Chicago
 date     2023-07-08
 pandoc   3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Packages ───────────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>           package loadedversion       date         source
               cli         3.6.1 2023-03-23 CRAN (R 4.3.0)
         codetools        0.2-19 2023-02-01 CRAN (R 4.3.1)
        colorspace         2.1-0 2023-01-23 CRAN (R 4.3.0)
            crayon         1.5.2 2022-09-29 CRAN (R 4.3.0)
              crul           1.3 2022-09-03 CRAN (R 4.3.1)
              curl         5.0.0 2023-01-12 CRAN (R 4.3.0)
            digest        0.6.31 2022-12-11 CRAN (R 4.3.0)
             dplyr         1.1.2 2023-04-20 CRAN (R 4.3.0)
          ellipsis         0.3.2 2021-04-29 CRAN (R 4.3.0)
          evaluate          0.21 2023-05-05 CRAN (R 4.3.0)
             fansi         1.0.4 2023-01-22 CRAN (R 4.3.0)
           fastmap         1.1.1 2023-02-24 CRAN (R 4.3.0)
 fontBitstreamVera         0.1.1 2017-02-01 CRAN (R 4.3.0)
    fontLiberation         0.1.0 2016-10-15 CRAN (R 4.3.0)
        fontquiver         0.2.1 2017-02-01 CRAN (R 4.3.0)
           forcats         1.0.0 2023-01-29 CRAN (R 4.3.0)
         fuzzyjoin         0.1.6 2020-05-15 CRAN (R 4.3.0)
           gdtools         0.3.3 2023-03-27 CRAN (R 4.3.0)
          generics         0.1.3 2022-07-05 CRAN (R 4.3.0)
            gfonts         0.2.0 2023-01-08 CRAN (R 4.3.0)
           ggplot2         3.4.2 2023-04-03 CRAN (R 4.3.0)
              glue         1.6.2 2022-02-24 CRAN (R 4.3.0)
            gtable         0.3.3 2023-03-21 CRAN (R 4.3.0)
               hms         1.1.3 2023-03-21 CRAN (R 4.3.0)
         htmltools         0.5.5 2023-03-23 CRAN (R 4.3.0)
       htmlwidgets         1.6.2 2023-03-17 CRAN (R 4.3.0)
          httpcode         0.3.0 2020-04-10 CRAN (R 4.3.0)
            httpuv        1.6.11 2023-05-11 CRAN (R 4.3.0)
          jsonlite         1.8.7 2022-12-06 CRAN (R 4.3.0)
             knitr          1.43 2023-05-25 CRAN (R 4.3.0)
             later         1.3.1 2023-05-02 CRAN (R 4.3.0)
         lifecycle         1.0.3 2022-10-07 CRAN (R 4.3.0)
         lubridate         1.9.2 2023-02-10 CRAN (R 4.3.0)
          magrittr         2.0.3 2022-03-30 CRAN (R 4.3.0)
              mime          0.12 2021-09-28 CRAN (R 4.3.0)
           munsell         0.5.0 2018-06-12 CRAN (R 4.3.0)
            pillar         1.9.0 2023-03-22 CRAN (R 4.3.0)
         pkgconfig         2.0.3 2019-09-22 CRAN (R 4.3.0)
          promises       1.2.0.1 2021-02-11 CRAN (R 4.3.0)
             purrr         1.0.1 2023-01-10 CRAN (R 4.3.0)
                R6         2.5.1 2021-08-19 CRAN (R 4.3.0)
              ragg         1.2.5 2023-01-12 CRAN (R 4.3.0)
              Rcpp        1.0.10 2023-01-22 CRAN (R 4.3.0)
             readr         2.1.4 2023-02-10 CRAN (R 4.3.0)
              renv        0.17.3 2023-04-06 CRAN (R 4.3.0)
             rlang         1.1.1 2023-04-28 CRAN (R 4.3.0)
         rmarkdown          2.22 2023-03-26 CRAN (R 4.3.0)
        rstudioapi          0.14 2022-08-22 CRAN (R 4.3.0)
            scales         1.2.1 2022-08-20 CRAN (R 4.3.0)
       sessioninfo         1.2.2 2021-12-06 CRAN (R 4.3.0)
             shiny         1.7.4 2022-12-15 CRAN (R 4.3.0)
        stringdist        0.9.10 2022-11-07 CRAN (R 4.3.0)
           stringi        1.7.12 2023-01-11 CRAN (R 4.3.0)
           stringr         1.5.0 2022-12-02 CRAN (R 4.3.0)
       systemfonts         1.0.4 2022-02-11 CRAN (R 4.3.0)
       textshaping         0.3.6 2021-10-13 CRAN (R 4.3.0)
            tibble         3.2.1 2023-03-20 CRAN (R 4.3.0)
             tidyr         1.3.0 2023-01-24 CRAN (R 4.3.0)
        tidyselect         1.2.0 2022-10-10 CRAN (R 4.3.0)
         tidyverse         2.0.0 2023-02-22 CRAN (R 4.3.0)
        timechange         0.2.0 2023-01-11 CRAN (R 4.3.0)
              tzdb         0.4.0 2022-03-28 CRAN (R 4.3.0)
              utf8         1.2.3 2023-01-31 CRAN (R 4.3.0)
             vctrs         0.6.3 2023-04-19 CRAN (R 4.3.0)
             withr         2.5.0 2022-03-03 CRAN (R 4.3.0)
              xfun          0.39 2023-04-20 CRAN (R 4.3.0)
            xtable         1.8-4 2019-04-21 CRAN (R 4.3.0)
              yaml         2.3.7 2023-01-23 CRAN (R 4.3.0)</code></pre>
</div>
</div>
</details>
</div>


</section>

 ]]></description>
  <category>dataframes</category>
  <category>joins</category>
  <guid>https://abraver.github.io/usefulRstuff/posts/fuzzyjoin/index.html</guid>
  <pubDate>Mon, 26 Jun 2023 05:00:00 GMT</pubDate>
</item>
<item>
  <title>
dplyr::glimpse(): Prettier than str()
</title>
  <dc:creator>Aaron Braver</dc:creator>
  <link>https://abraver.github.io/usefulRstuff/posts/glimpse/index.html</link>
  <description><![CDATA[ <script src="../../jquery-3.7.0.min.js"></script><script src="../../fold.js"></script><script src="../../move_session_info.js"></script><!-- begin content --><p>Instead of <code>str(df)</code> to see the structure of a dataframe, try <code><a href="https://pillar.r-lib.org/reference/glimpse.html">dplyr::glimpse()</a></code><sup>1</sup> instead. It gives a horizontal output and shows more data than fits with <code><a href="https://rdrr.io/r/utils/str.html">str()</a></code>:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-2_172e8f21959cc84f117b9b41b2dbc834">
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dplyr</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://pillar.r-lib.org/reference/glimpse.html">glimpse</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">palmerpenguins</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://allisonhorst.github.io/palmerpenguins/reference/penguins.html">penguins</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 344
Columns: 8
$ species           &lt;fct&gt; Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adel…
$ island            &lt;fct&gt; Torgersen, Torgersen, Torgersen, Torgersen, Torgerse…
$ bill_length_mm    &lt;dbl&gt; 39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, 34.1, …
$ bill_depth_mm     &lt;dbl&gt; 18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, 18.1, …
$ flipper_length_mm &lt;int&gt; 181, 186, 195, NA, 193, 190, 181, 195, 193, 190, 186…
$ body_mass_g       &lt;int&gt; 3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, 3475, …
$ sex               &lt;fct&gt; male, female, female, NA, female, male, female, male…
$ year              &lt;int&gt; 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007…</code></pre>
</div>
</div>
<p>You can also force more data to be shown with the <code>width</code> option:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-3_f2be168c1035aa687b04742f9da9bd9b">
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dplyr</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://pillar.r-lib.org/reference/glimpse.html">glimpse</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">palmerpenguins</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://allisonhorst.github.io/palmerpenguins/reference/penguins.html">penguins</a></span>, width <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 344
Columns: 8
$ species           &lt;fct&gt; Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adel…
$ island            &lt;fct&gt; Torgersen, Torgersen, Torgersen, Torgersen, Torgersen, Torgersen, Torgersen, Torgersen, Torgersen, Torgersen, Torgersen, Torgersen, Torgersen, Torgersen, Torgersen, Torgers…
$ bill_length_mm    &lt;dbl&gt; 39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, 34.1, 42.0, 37.8, 37.8, 41.1, 38.6, 34.6, 36.6, 38.7, 42.5, 34.4, 46.0, 37.8, 37.7, 35.9, 38.2, 38.8, 35.3, 40.6, 40.5, 37.9, …
$ bill_depth_mm     &lt;dbl&gt; 18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, 18.1, 20.2, 17.1, 17.3, 17.6, 21.2, 21.1, 17.8, 19.0, 20.7, 18.4, 21.5, 18.3, 18.7, 19.2, 18.1, 17.2, 18.9, 18.6, 17.9, 18.6, …
$ flipper_length_mm &lt;int&gt; 181, 186, 195, NA, 193, 190, 181, 195, 193, 190, 186, 180, 182, 191, 198, 185, 195, 197, 184, 194, 174, 180, 189, 185, 180, 187, 183, 187, 172, 180, 178, 178, 188, 184, 195…
$ body_mass_g       &lt;int&gt; 3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, 3475, 4250, 3300, 3700, 3200, 3800, 4400, 3700, 3450, 4500, 3325, 4200, 3400, 3600, 3800, 3950, 3800, 3800, 3550, 3200, 3150, …
$ sex               &lt;fct&gt; male, female, female, NA, female, male, female, male, NA, NA, NA, NA, female, male, male, female, female, male, female, male, female, male, female, male, male, female, male…
$ year              &lt;int&gt; 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007…</code></pre>
</div>
</div>
<!-- End content -->
<div id="footer-session-info">
<details><summary>
Session info and package versions
</summary><div class="cell" data-hash="index_cache/html/unnamed-chunk-5_21b31f662589a1115e67bd4254f280f5">
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code> setting  value
 version  R version 4.3.1 (2023-06-16)
 os       macOS Ventura 13.4.1
 system   aarch64, darwin20
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Chicago
 date     2023-07-08
 pandoc   3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Packages ───────────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>           package loadedversion       date         source
               cli         3.6.1 2023-03-23 CRAN (R 4.3.0)
         codetools        0.2-19 2023-02-01 CRAN (R 4.3.1)
            crayon         1.5.2 2022-09-29 CRAN (R 4.3.0)
              crul         1.4.0 2023-05-17 CRAN (R 4.3.0)
              curl         5.0.1 2023-06-07 CRAN (R 4.3.0)
            digest        0.6.31 2022-12-11 CRAN (R 4.3.0)
             dplyr         1.1.2 2023-04-20 CRAN (R 4.3.0)
          ellipsis         0.3.2 2021-04-29 CRAN (R 4.3.0)
          evaluate          0.21 2023-05-05 CRAN (R 4.3.0)
             fansi         1.0.4 2023-01-22 CRAN (R 4.3.0)
           fastmap         1.1.1 2023-02-24 CRAN (R 4.3.0)
 fontBitstreamVera         0.1.1 2017-02-01 CRAN (R 4.3.0)
    fontLiberation         0.1.0 2016-10-15 CRAN (R 4.3.0)
        fontquiver         0.2.1 2017-02-01 CRAN (R 4.3.0)
           gdtools         0.3.3 2023-03-27 CRAN (R 4.3.0)
          generics         0.1.3 2022-07-05 CRAN (R 4.3.0)
            gfonts         0.2.0 2023-01-08 CRAN (R 4.3.0)
              glue         1.6.2 2022-02-24 CRAN (R 4.3.0)
         htmltools         0.5.5 2023-03-23 CRAN (R 4.3.0)
       htmlwidgets         1.6.2 2023-03-17 CRAN (R 4.3.0)
          httpcode         0.3.0 2020-04-10 CRAN (R 4.3.0)
            httpuv        1.6.11 2023-05-11 CRAN (R 4.3.0)
          jsonlite         1.8.4 2022-12-06 CRAN (R 4.3.0)
             knitr          1.43 2023-05-25 CRAN (R 4.3.0)
             later         1.3.1 2023-05-02 CRAN (R 4.3.0)
         lifecycle         1.0.3 2022-10-07 CRAN (R 4.3.0)
          magrittr         2.0.3 2022-03-30 CRAN (R 4.3.0)
              mime          0.12 2021-09-28 CRAN (R 4.3.0)
    palmerpenguins         0.1.1 2022-08-15 CRAN (R 4.3.0)
            pillar         1.9.0 2023-03-22 CRAN (R 4.3.0)
         pkgconfig         2.0.3 2019-09-22 CRAN (R 4.3.0)
          promises       1.2.0.1 2021-02-11 CRAN (R 4.3.0)
                R6         2.5.1 2021-08-19 CRAN (R 4.3.0)
              ragg         1.2.5 2023-01-12 CRAN (R 4.3.0)
              Rcpp        1.0.10 2023-01-22 CRAN (R 4.3.0)
              renv        0.17.3 2023-04-06 CRAN (R 4.3.0)
             rlang         1.1.1 2023-04-28 CRAN (R 4.3.0)
         rmarkdown          2.21 2023-03-26 CRAN (R 4.3.0)
        rstudioapi          0.14 2022-08-22 CRAN (R 4.3.0)
       sessioninfo         1.2.2 2021-12-06 CRAN (R 4.3.0)
             shiny         1.7.4 2022-12-15 CRAN (R 4.3.0)
       systemfonts         1.0.4 2022-02-11 CRAN (R 4.3.0)
       textshaping         0.3.6 2021-10-13 CRAN (R 4.3.0)
            tibble         3.2.1 2023-03-20 CRAN (R 4.3.0)
        tidyselect         1.2.0 2022-10-10 CRAN (R 4.3.0)
              utf8         1.2.3 2023-01-31 CRAN (R 4.3.0)
             vctrs         0.6.2 2023-04-19 CRAN (R 4.3.0)
              xfun          0.39 2023-04-20 CRAN (R 4.3.0)
            xtable         1.8-4 2019-04-21 CRAN (R 4.3.0)
              yaml         2.3.7 2023-01-23 CRAN (R 4.3.0)</code></pre>
</div>
</div>
</details>
</div>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>
<ol>
<li id="fn1"><p>Technically, <code>glimpse</code> is from the <code>pillar</code> package, but it’s re-exported by <code>dplyr</code>, which I usually have loaded anyway.↩︎</p></li>
</ol></section></div> ]]></description>
  <category>dataframes</category>
  <category>summarizing</category>
  <guid>https://abraver.github.io/usefulRstuff/posts/glimpse/index.html</guid>
  <pubDate>Mon, 26 Jun 2023 05:00:00 GMT</pubDate>
</item>
<item>
  <title>janitor: Clean dirty data, plus improved tables and crosstab</title>
  <dc:creator>Aaron Braver</dc:creator>
  <link>https://abraver.github.io/usefulRstuff/posts/janitor/index.html</link>
  <description><![CDATA[ 



<script src="../../jquery-3.7.0.min.js"></script>
<script src="../../fold.js"></script>
<script src="../../move_session_info.js"></script>
<!-- begin content -->
<div class="cell" data-hash="index_cache/html/setup_561f5ca5d1bb2174e51a7e91856a278a">
<details>
<summary>Setup</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(janitor)</span></code></pre></div>
</details>
</div>
<p><a href="https://sfirke.github.io/janitor/index.html"><code>janitor</code></a> contains various tools for examining and cleaning dirty data.</p>
<section id="cleaning-dirty-data" class="level2">
<h2 class="anchored" data-anchor-id="cleaning-dirty-data">Cleaning dirty data</h2>
<section id="clean-column-names" class="level3">
<h3 class="anchored" data-anchor-id="clean-column-names">Clean column names</h3>
<p>Let’s create a <code>df</code> with some poorly-chosen column names:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-2_4b268de502f4d61e6fe4840f101fd1f3">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">test_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.frame</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>))</span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(test_df) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"firstName"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ábc@!*"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"% successful (2009)"</span>,</span>
<span id="cb2-3">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"REPEAT VALUE"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"REPEAT VALUE"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span></code></pre></div>
</div>
<p><code>clean_names()</code> does just as the name implies:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-3_01dfd91172ede1f4b036438e856e10e2">
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">test_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">clean_names</span>()</span></code></pre></div>
<div class="cell-output-display">
<div class="kable-table">
<table class="table table-sm table-striped small">
<colgroup>
<col style="width: 15%">
<col style="width: 5%">
<col style="width: 34%">
<col style="width: 18%">
<col style="width: 21%">
<col style="width: 4%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">first_name</th>
<th style="text-align: left;">abc</th>
<th style="text-align: left;">percent_successful_2009</th>
<th style="text-align: left;">repeat_value</th>
<th style="text-align: left;">repeat_value_2</th>
<th style="text-align: left;">x</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>The <code>case</code> argument to <code>clean_names()</code> specifies what case you’d like output names to be in. You can specify any case style that’s available in <code>snakecase::to_any_case()</code>, including “screaming_snake” if you want to be perverse:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-4_0901269dc1d76bb31830a57a10ed9dad">
<div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">test_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb4-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">clean_names</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">case =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"screaming_snake"</span>)</span></code></pre></div>
<div class="cell-output-display">
<div class="kable-table">
<table class="table table-sm table-striped small">
<colgroup>
<col style="width: 15%">
<col style="width: 5%">
<col style="width: 34%">
<col style="width: 18%">
<col style="width: 21%">
<col style="width: 4%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">FIRST_NAME</th>
<th style="text-align: left;">ABC</th>
<th style="text-align: left;">PERCENT_SUCCESSFUL_2009</th>
<th style="text-align: left;">REPEAT_VALUE</th>
<th style="text-align: left;">REPEAT_VALUE_2</th>
<th style="text-align: left;">X</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
<section id="check-if-dfs-are-row-bind-able" class="level3">
<h3 class="anchored" data-anchor-id="check-if-dfs-are-row-bind-able">Check if <code>df</code>s are row-bind-able</h3>
<p>Also useful is <code>compare_df_cols</code> which summarizes whether the specified <code>df</code>s can be row-bound (i.e., have columns of the same names/types):</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-5_ede269b16af52d466efc28d9702b1c80">
<div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">df1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">A=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">b =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"big"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"small"</span>))</span>
<span id="cb5-2">df2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">a =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">b =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"medium"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"small"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"big"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stringsAsFactors =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># here, column b is a factor</span></span>
<span id="cb5-3">df3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> df1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb5-4">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">b =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(b))</span>
<span id="cb5-5"></span>
<span id="cb5-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">compare_df_cols</span>(df1, df2, df3)</span></code></pre></div>
<div class="cell-output-display">
<div class="kable-table">
<table class="table table-sm table-striped small">
<thead>
<tr class="header">
<th style="text-align: left;">column_name</th>
<th style="text-align: left;">df1</th>
<th style="text-align: left;">df2</th>
<th style="text-align: left;">df3</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">a</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">integer</td>
<td style="text-align: left;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">A</td>
<td style="text-align: left;">integer</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">integer</td>
</tr>
<tr class="odd">
<td style="text-align: left;">b</td>
<td style="text-align: left;">character</td>
<td style="text-align: left;">factor</td>
<td style="text-align: left;">character</td>
</tr>
<tr class="even">
<td style="text-align: left;">c</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">numeric</td>
<td style="text-align: left;">NA</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>If you just want a simple <code>TRUE</code>/<code>FALSE</code> value telling you whether the <code>df</code>s match, you can use <code>compare_df_cols_same()</code>:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-6_d2bc0a894872c25e0db91148541183ad">
<div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">compare_df_cols_same</span>(df1, df2, df3, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">verbose =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>))</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code> logi FALSE</code></pre>
</div>
</div>
</section>
</section>
<section id="examining-data-and-crosstabs" class="level2">
<h2 class="anchored" data-anchor-id="examining-data-and-crosstabs">Examining data and crosstabs</h2>
<p><code>janitor</code>’s version of tables are called <code>tabyls</code>. You can easily generate crosstabs:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-7_3875943f08e53eb5f5176706e55d6af2">
<div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">palmerpenguins<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>penguins <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb8-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tabyl</span>(species, island)</span></code></pre></div>
<div class="cell-output-display">
<div class="kable-table">
<table class="table table-sm table-striped small">
<thead>
<tr class="header">
<th style="text-align: left;">species</th>
<th style="text-align: right;">Biscoe</th>
<th style="text-align: right;">Dream</th>
<th style="text-align: right;">Torgersen</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Adelie</td>
<td style="text-align: right;">44</td>
<td style="text-align: right;">56</td>
<td style="text-align: right;">52</td>
</tr>
<tr class="even">
<td style="text-align: left;">Chinstrap</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">68</td>
<td style="text-align: right;">0</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Gentoo</td>
<td style="text-align: right;">124</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>There are lots of ways to pretty up the output via <code>adorn_*</code> commands, giving things like column or row percentages, optionally with <code>n</code>s in parentheses:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-8_8d7b093a294300624a97b0e692249696">
<div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">palmerpenguins<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>penguins <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb9-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tabyl</span>(species, island) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb9-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">adorn_totals</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"col"</span>)  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb9-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">adorn_percentages</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"row"</span>)  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb9-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">adorn_pct_formatting</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb9-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">adorn_ns</span>()</span></code></pre></div>
<div class="cell-output-display">
<div class="kable-table">
<table class="table table-sm table-striped small">
<thead>
<tr class="header">
<th style="text-align: left;">species</th>
<th style="text-align: left;">Biscoe</th>
<th style="text-align: left;">Dream</th>
<th style="text-align: left;">Torgersen</th>
<th style="text-align: left;">Total</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Adelie</td>
<td style="text-align: left;">28.95% (44)</td>
<td style="text-align: left;">36.84% (56)</td>
<td style="text-align: left;">34.21% (52)</td>
<td style="text-align: left;">100.00% (152)</td>
</tr>
<tr class="even">
<td style="text-align: left;">Chinstrap</td>
<td style="text-align: left;">0.00% (0)</td>
<td style="text-align: left;">100.00% (68)</td>
<td style="text-align: left;">0.00% (0)</td>
<td style="text-align: left;">100.00% (68)</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Gentoo</td>
<td style="text-align: left;">100.00% (124)</td>
<td style="text-align: left;">0.00% (0)</td>
<td style="text-align: left;">0.00% (0)</td>
<td style="text-align: left;">100.00% (124)</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>You can also use the <code>adorn_*</code> functions on regular ol’ <code>df</code>s:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-9_4a45886879978ed991b803787e5b8ff4">
<div class="sourceCode cell-code" id="annotated-cell-9" style="background: #f1f3f5;"><pre class="sourceCode r code-annotation-code code-with-copy code-annotated"><code class="sourceCode r"><span id="annotated-cell-9-1">palmerpenguins<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>penguins <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<button class="code-annotation-anchor" data-target-cell="annotated-cell-9" data-target-annotation="1">1</button><span id="annotated-cell-9-2" class="code-annotation-target">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample_n</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="annotated-cell-9-3">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="annotated-cell-9-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">adorn_totals</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"row"</span>)</span><div class="code-annotation-gutter-bg"></div><div class="code-annotation-gutter"></div></code></pre></div>
<div class="cell-annotation">
<dl class="code-annotation-container-hidden code-annotation-container-grid">
<dt data-target-cell="annotated-cell-9" data-target-annotation="1">1</dt>
<dd>
<span data-code-cell="annotated-cell-9" data-code-annotation="1" data-code-lines="2">Choose 10 random rows so this doesn’t print forever</span>
</dd>
</dl>
</div>
<div class="cell-output-display">
<div class="kable-table">
<table class="table table-sm table-striped small">
<colgroup>
<col style="width: 11%">
<col style="width: 11%">
<col style="width: 17%">
<col style="width: 16%">
<col style="width: 20%">
<col style="width: 13%">
<col style="width: 8%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">species</th>
<th style="text-align: left;">island</th>
<th style="text-align: right;">bill_length_mm</th>
<th style="text-align: right;">bill_depth_mm</th>
<th style="text-align: right;">flipper_length_mm</th>
<th style="text-align: right;">body_mass_g</th>
<th style="text-align: left;">sex</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Chinstrap</td>
<td style="text-align: left;">Dream</td>
<td style="text-align: right;">45.7</td>
<td style="text-align: right;">17.0</td>
<td style="text-align: right;">195</td>
<td style="text-align: right;">3650</td>
<td style="text-align: left;">female</td>
</tr>
<tr class="even">
<td style="text-align: left;">Adelie</td>
<td style="text-align: left;">Torgersen</td>
<td style="text-align: right;">35.9</td>
<td style="text-align: right;">16.6</td>
<td style="text-align: right;">190</td>
<td style="text-align: right;">3050</td>
<td style="text-align: left;">female</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Chinstrap</td>
<td style="text-align: left;">Dream</td>
<td style="text-align: right;">45.5</td>
<td style="text-align: right;">17.0</td>
<td style="text-align: right;">196</td>
<td style="text-align: right;">3500</td>
<td style="text-align: left;">female</td>
</tr>
<tr class="even">
<td style="text-align: left;">Gentoo</td>
<td style="text-align: left;">Biscoe</td>
<td style="text-align: right;">49.4</td>
<td style="text-align: right;">15.8</td>
<td style="text-align: right;">216</td>
<td style="text-align: right;">4925</td>
<td style="text-align: left;">male</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Adelie</td>
<td style="text-align: left;">Dream</td>
<td style="text-align: right;">39.7</td>
<td style="text-align: right;">17.9</td>
<td style="text-align: right;">193</td>
<td style="text-align: right;">4250</td>
<td style="text-align: left;">male</td>
</tr>
<tr class="even">
<td style="text-align: left;">Chinstrap</td>
<td style="text-align: left;">Dream</td>
<td style="text-align: right;">49.5</td>
<td style="text-align: right;">19.0</td>
<td style="text-align: right;">200</td>
<td style="text-align: right;">3800</td>
<td style="text-align: left;">male</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Gentoo</td>
<td style="text-align: left;">Biscoe</td>
<td style="text-align: right;">46.6</td>
<td style="text-align: right;">14.2</td>
<td style="text-align: right;">210</td>
<td style="text-align: right;">4850</td>
<td style="text-align: left;">female</td>
</tr>
<tr class="even">
<td style="text-align: left;">Gentoo</td>
<td style="text-align: left;">Biscoe</td>
<td style="text-align: right;">50.5</td>
<td style="text-align: right;">15.9</td>
<td style="text-align: right;">222</td>
<td style="text-align: right;">5550</td>
<td style="text-align: left;">male</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Gentoo</td>
<td style="text-align: left;">Biscoe</td>
<td style="text-align: right;">50.0</td>
<td style="text-align: right;">15.2</td>
<td style="text-align: right;">218</td>
<td style="text-align: right;">5700</td>
<td style="text-align: left;">male</td>
</tr>
<tr class="even">
<td style="text-align: left;">Gentoo</td>
<td style="text-align: left;">Biscoe</td>
<td style="text-align: right;">48.2</td>
<td style="text-align: right;">14.3</td>
<td style="text-align: right;">210</td>
<td style="text-align: right;">4600</td>
<td style="text-align: left;">female</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Total</td>
<td style="text-align: left;">-</td>
<td style="text-align: right;">461.0</td>
<td style="text-align: right;">162.9</td>
<td style="text-align: right;">2050</td>
<td style="text-align: right;">43875</td>
<td style="text-align: left;">-</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Check out the <a href="https://cran.r-project.org/web/packages/janitor/vignettes/tabyls.html"><code>tabyl</code>s vignette</a> for more info.</p>
<!-- End content -->
<div id="footer-session-info">
<details>
<summary>
Session info and package versions
</summary>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-11_d498312526141dc12cb36ca799c2b9ce">
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code> setting  value
 version  R version 4.3.1 (2023-06-16)
 os       macOS Ventura 13.4.1
 system   aarch64, darwin20
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Chicago
 date     2023-07-08
 pandoc   3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Packages ───────────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>           package loadedversion       date         source
               cli         3.6.1 2023-03-23 CRAN (R 4.3.0)
         codetools        0.2-19 2023-02-01 CRAN (R 4.3.1)
            crayon         1.5.2 2022-09-29 CRAN (R 4.3.0)
              crul         1.4.0 2023-05-17 CRAN (R 4.3.0)
              curl         5.0.1 2023-06-07 CRAN (R 4.3.0)
            digest        0.6.31 2022-12-11 CRAN (R 4.3.0)
             dplyr         1.1.2 2023-04-20 CRAN (R 4.3.0)
          ellipsis         0.3.2 2021-04-29 CRAN (R 4.3.0)
          evaluate          0.21 2023-05-05 CRAN (R 4.3.0)
             fansi         1.0.4 2023-01-22 CRAN (R 4.3.0)
           fastmap         1.1.1 2023-02-24 CRAN (R 4.3.0)
 fontBitstreamVera         0.1.1 2017-02-01 CRAN (R 4.3.0)
    fontLiberation         0.1.0 2016-10-15 CRAN (R 4.3.0)
        fontquiver         0.2.1 2017-02-01 CRAN (R 4.3.0)
           gdtools         0.3.3 2023-03-27 CRAN (R 4.3.0)
          generics         0.1.3 2022-07-05 CRAN (R 4.3.0)
            gfonts         0.2.0 2023-01-08 CRAN (R 4.3.0)
              glue         1.6.2 2022-02-24 CRAN (R 4.3.0)
         htmltools         0.5.5 2023-03-23 CRAN (R 4.3.0)
       htmlwidgets         1.6.2 2023-03-17 CRAN (R 4.3.0)
          httpcode         0.3.0 2020-04-10 CRAN (R 4.3.0)
            httpuv        1.6.11 2023-05-11 CRAN (R 4.3.0)
           janitor         2.2.0 2023-02-02 CRAN (R 4.3.0)
          jsonlite         1.8.7 2022-12-06 CRAN (R 4.3.0)
             knitr          1.43 2023-05-25 CRAN (R 4.3.0)
             later         1.3.1 2023-05-02 CRAN (R 4.3.0)
         lifecycle         1.0.3 2022-10-07 CRAN (R 4.3.0)
         lubridate         1.9.2 2023-02-10 CRAN (R 4.3.0)
          magrittr         2.0.3 2022-03-30 CRAN (R 4.3.0)
              mime          0.12 2021-09-28 CRAN (R 4.3.0)
    palmerpenguins         0.1.1 2022-08-15 CRAN (R 4.3.0)
            pillar         1.9.0 2023-03-22 CRAN (R 4.3.0)
         pkgconfig         2.0.3 2019-09-22 CRAN (R 4.3.0)
          promises       1.2.0.1 2021-02-11 CRAN (R 4.3.0)
             purrr         1.0.1 2023-01-10 CRAN (R 4.3.0)
                R6         2.5.1 2021-08-19 CRAN (R 4.3.0)
              ragg         1.2.5 2023-01-12 CRAN (R 4.3.0)
              Rcpp        1.0.10 2023-01-22 CRAN (R 4.3.0)
              renv        0.17.3 2023-04-06 CRAN (R 4.3.0)
             rlang         1.1.1 2023-04-28 CRAN (R 4.3.0)
         rmarkdown          2.22 2023-03-26 CRAN (R 4.3.0)
        rstudioapi          0.14 2022-08-22 CRAN (R 4.3.0)
       sessioninfo         1.2.2 2021-12-06 CRAN (R 4.3.0)
             shiny         1.7.4 2022-12-15 CRAN (R 4.3.0)
         snakecase        0.11.0 2019-05-25 CRAN (R 4.3.0)
           stringi        1.7.12 2023-01-11 CRAN (R 4.3.0)
           stringr         1.5.0 2022-12-02 CRAN (R 4.3.0)
       systemfonts         1.0.4 2022-02-11 CRAN (R 4.3.0)
       textshaping         0.3.6 2021-10-13 CRAN (R 4.3.0)
            tibble         3.2.1 2023-03-20 CRAN (R 4.3.0)
             tidyr         1.3.0 2023-01-24 CRAN (R 4.3.0)
        tidyselect         1.2.0 2022-10-10 CRAN (R 4.3.0)
        timechange         0.2.0 2023-01-11 CRAN (R 4.3.0)
              utf8         1.2.3 2023-01-31 CRAN (R 4.3.0)
             vctrs         0.6.2 2023-04-19 CRAN (R 4.3.0)
             withr         2.5.0 2022-03-03 CRAN (R 4.3.0)
              xfun          0.39 2023-04-20 CRAN (R 4.3.0)
            xtable         1.8-4 2019-04-21 CRAN (R 4.3.0)
              yaml         2.3.7 2023-01-23 CRAN (R 4.3.0)</code></pre>
</div>
</div>
</details>
</div>


</section>

 ]]></description>
  <category>data cleaning</category>
  <guid>https://abraver.github.io/usefulRstuff/posts/janitor/index.html</guid>
  <pubDate>Sun, 25 Jun 2023 05:00:00 GMT</pubDate>
</item>
<item>
  <title>
diffobj: Compare two dfs (or other objects)</title>
  <dc:creator>Aaron Braver</dc:creator>
  <link>https://abraver.github.io/usefulRstuff/posts/diffobj/index.html</link>
  <description><![CDATA[ <script src="../../jquery-3.7.0.min.js"></script><script src="../../fold.js"></script><script src="../../move_session_info.js"></script><!-- begin content --><p>What’s the difference between two <code>df</code>s?</p>
<p><code><a href="https://rdrr.io/pkg/diffobj/man/diffPrint.html">diffobj::diffPrint()</a></code> gives a handy visual way to check differences:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-2_62006b2cd577cc25e72eced83baed27e">
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://github.com/brodieG/diffobj">diffobj</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">a</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">b</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/matrix.html">matrix</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>, ncol<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">a</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">a</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">[</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>,<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">]</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">b</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">b</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">[</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>,<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">]</span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">b</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">[</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">44</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">]</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">999</span></span>
<span></span>
<span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/diffobj/man/diffPrint.html">diffPrint</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>target<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">a</span>, current<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">b</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>&lt; a                &gt; b              
@@ 17,6 @@         @@ 17,7 @@       
~       [,1] [,2]  ~       [,1] [,2]
  [16,]   16   66    [16,]   16   66
  [17,]   17   67    [17,]   17   67
&lt; [18,]   18   68  &gt; [18,]  999   68
  [19,]   19   69    [19,]   19   69
~                  &gt; [20,]   20   70
  [20,]   21   71    [21,]   21   71
  [21,]   22   72    [22,]   22   72
@@ 42,6 @@         @@ 43,5 @@       
  [41,]   42   92    [42,]   42   92
  [42,]   43   93    [43,]   43   93
&lt; [43,]   44   94  &gt; [44,]  999   94
&lt; [44,]   45   95  ~                
  [45,]   46   96    [45,]   46   96
  [46,]   47   97    [46,]   47   97</code></pre>
</div>
</div>
<details><summary>
(In RStudio, this is shown in a colorful manner in the Viewer)
</summary><a href="diffobj-rstudio.jpg" class="lightbox" data-gallery="quarto-lightbox-gallery-1"><img src="https://abraver.github.io/usefulRstuff/posts/diffobj/diffobj-rstudio.jpg" class="img-fluid" width="400"></a>
</details><p>This also works for other types of objects, such as character vectors:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-3_2085abed92f9c498c1f6c99e40223a04">
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/diffobj/man/diffPrint.html">diffPrint</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">letters</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">[</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">]</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"B"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"c"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>&lt; letters[1:3]     &gt; c("a", "B", "..
@@ 1 @@            @@ 1 @@          
&lt; [1] "a" "b" "c"  &gt; [1] "a" "B" "c"</code></pre>
</div>
</div>
<p>For more details, see the <a href="https://cran.r-project.org/web/packages/diffobj/vignettes/diffobj.html">Introduction to diffobjj vignette</a>, or the <a href="https://github.com/brodieG/diffobj">diffobj github rep</a>.</p>
<!-- End content -->
<div id="footer-session-info">
<details><summary>
Session info and package versions
</summary><div class="cell" data-hash="index_cache/html/unnamed-chunk-5_21b31f662589a1115e67bd4254f280f5">
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code> setting  value
 version  R version 4.3.1 (2023-06-16)
 os       macOS Ventura 13.4.1
 system   aarch64, darwin20
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Chicago
 date     2023-07-08
 pandoc   3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Packages ───────────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>           package loadedversion       date         source
               cli         3.6.1 2023-03-23 CRAN (R 4.3.0)
         codetools        0.2-19 2023-02-01 CRAN (R 4.3.1)
            crayon         1.5.2 2022-09-29 CRAN (R 4.3.0)
              crul         1.4.0 2023-05-17 CRAN (R 4.3.0)
              curl         5.0.0 2023-01-12 CRAN (R 4.3.0)
           diffobj         0.3.5 2021-10-05 CRAN (R 4.3.0)
            digest        0.6.31 2022-12-11 CRAN (R 4.3.0)
             dplyr         1.1.2 2023-04-20 CRAN (R 4.3.0)
          ellipsis         0.3.2 2021-04-29 CRAN (R 4.3.0)
          evaluate          0.21 2023-05-05 CRAN (R 4.3.0)
             fansi         1.0.4 2023-01-22 CRAN (R 4.3.0)
           fastmap         1.1.1 2023-02-24 CRAN (R 4.3.0)
 fontBitstreamVera         0.1.1 2017-02-01 CRAN (R 4.3.0)
    fontLiberation         0.1.0 2016-10-15 CRAN (R 4.3.0)
        fontquiver         0.2.1 2017-02-01 CRAN (R 4.3.0)
           gdtools         0.3.3 2023-03-27 CRAN (R 4.3.0)
          generics         0.1.3 2022-07-05 CRAN (R 4.3.0)
            gfonts         0.2.0 2023-01-08 CRAN (R 4.3.0)
              glue         1.6.2 2022-02-24 CRAN (R 4.3.0)
         htmltools         0.5.5 2023-03-23 CRAN (R 4.3.0)
       htmlwidgets         1.6.2 2023-03-17 CRAN (R 4.3.0)
          httpcode         0.3.0 2020-04-10 CRAN (R 4.3.0)
            httpuv        1.6.11 2023-05-11 CRAN (R 4.3.0)
          jsonlite         1.8.4 2022-12-06 CRAN (R 4.3.0)
             knitr          1.43 2023-05-25 CRAN (R 4.3.0)
             later         1.3.1 2023-05-02 CRAN (R 4.3.0)
         lifecycle         1.0.3 2022-10-07 CRAN (R 4.3.0)
          magrittr         2.0.3 2022-03-30 CRAN (R 4.3.0)
              mime          0.12 2021-09-28 CRAN (R 4.3.0)
            pillar         1.9.0 2023-03-22 CRAN (R 4.3.0)
         pkgconfig         2.0.3 2019-09-22 CRAN (R 4.3.0)
          promises       1.2.0.1 2021-02-11 CRAN (R 4.3.0)
                R6         2.5.1 2021-08-19 CRAN (R 4.3.0)
              ragg         1.2.5 2023-01-12 CRAN (R 4.3.0)
              Rcpp        1.0.10 2023-01-22 CRAN (R 4.3.0)
              renv        0.17.3 2023-04-06 CRAN (R 4.3.0)
             rlang         1.1.1 2023-04-28 CRAN (R 4.3.0)
         rmarkdown          2.21 2023-03-26 CRAN (R 4.3.0)
        rstudioapi          0.14 2022-08-22 CRAN (R 4.3.0)
       sessioninfo         1.2.2 2021-12-06 CRAN (R 4.3.0)
             shiny         1.7.4 2022-12-15 CRAN (R 4.3.0)
       systemfonts         1.0.4 2022-02-11 CRAN (R 4.3.0)
       textshaping         0.3.6 2021-10-13 CRAN (R 4.3.0)
            tibble         3.2.1 2023-03-20 CRAN (R 4.3.0)
        tidyselect         1.2.0 2022-10-10 CRAN (R 4.3.0)
              utf8         1.2.3 2023-01-31 CRAN (R 4.3.0)
             vctrs         0.6.2 2023-04-19 CRAN (R 4.3.0)
              xfun          0.39 2023-04-20 CRAN (R 4.3.0)
            xtable         1.8-4 2019-04-21 CRAN (R 4.3.0)
              yaml         2.3.7 2023-01-23 CRAN (R 4.3.0)</code></pre>
</div>
</div>
</details>
</div>



 ]]></description>
  <category>dataframes</category>
  <guid>https://abraver.github.io/usefulRstuff/posts/diffobj/index.html</guid>
  <pubDate>Sun, 25 Jun 2023 05:00:00 GMT</pubDate>
</item>
<item>
  <title>thinkr::peep(): See intermediate stages of piped dfs</title>
  <dc:creator>Aaron Braver</dc:creator>
  <link>https://abraver.github.io/usefulRstuff/posts/thinkr_peep/index.html</link>
  <description><![CDATA[ 



<script src="../../jquery-3.7.0.min.js"></script>
<script src="../../fold.js"></script>
<script src="../../move_session_info.js"></script>
<!-- begin content -->
<div class="cell" data-hash="index_cache/html/setup_73122296f41c7d9b946d97e5e7fc4f4a">
<details>
<summary>Setup</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(thinkr)</span></code></pre></div>
</details>
</div>
<p>Insert <code>thinkr::peep(head)</code> into a <code>df</code> pipeline to print a few rows at a particular intermediate stage in the pipeline. Here it prints a few lines of the <code>df</code> before it gets summarized:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-2_dbf7fe24710b7544b20d38c058d195ad">
<div class="sourceCode cell-code" id="annotated-cell-2" style="background: #f1f3f5;"><pre class="sourceCode r code-annotation-code code-with-copy code-annotated"><code class="sourceCode r"><span id="annotated-cell-2-1">palmerpenguins<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>penguins <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="annotated-cell-2-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">peep</span>(head) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<button class="code-annotation-anchor" data-target-cell="annotated-cell-2" data-target-annotation="1">1</button><span id="annotated-cell-2-3" class="code-annotation-target">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(species) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="annotated-cell-2-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">where</span>(is.numeric), \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)))</span><div class="code-annotation-gutter-bg"></div><div class="code-annotation-gutter"></div></code></pre></div>
<div class="cell-annotation">
<dl class="code-annotation-container-hidden code-annotation-container-grid">
<dt data-target-cell="annotated-cell-2" data-target-annotation="1">1</dt>
<dd>
<span data-code-cell="annotated-cell-2" data-code-annotation="1" data-code-lines="3">How convenient that the base R pipe looks like a penguin.</span>
</dd>
</dl>
</div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6 × 8
  species island    bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
  &lt;fct&gt;   &lt;fct&gt;              &lt;dbl&gt;         &lt;dbl&gt;             &lt;int&gt;       &lt;int&gt;
1 Adelie  Torgersen           39.1          18.7               181        3750
2 Adelie  Torgersen           39.5          17.4               186        3800
3 Adelie  Torgersen           40.3          18                 195        3250
4 Adelie  Torgersen           NA            NA                  NA          NA
5 Adelie  Torgersen           36.7          19.3               193        3450
6 Adelie  Torgersen           39.3          20.6               190        3650
# ℹ 2 more variables: sex &lt;fct&gt;, year &lt;int&gt;</code></pre>
</div>
<div class="cell-output-display">
<div class="kable-table">
<table class="table table-sm table-striped small">
<colgroup>
<col style="width: 12%">
<col style="width: 19%">
<col style="width: 17%">
<col style="width: 23%">
<col style="width: 15%">
<col style="width: 11%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">species</th>
<th style="text-align: right;">bill_length_mm</th>
<th style="text-align: right;">bill_depth_mm</th>
<th style="text-align: right;">flipper_length_mm</th>
<th style="text-align: right;">body_mass_g</th>
<th style="text-align: right;">year</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Adelie</td>
<td style="text-align: right;">38.79139</td>
<td style="text-align: right;">18.34636</td>
<td style="text-align: right;">189.9536</td>
<td style="text-align: right;">3700.662</td>
<td style="text-align: right;">2008.013</td>
</tr>
<tr class="even">
<td style="text-align: left;">Chinstrap</td>
<td style="text-align: right;">48.83382</td>
<td style="text-align: right;">18.42059</td>
<td style="text-align: right;">195.8235</td>
<td style="text-align: right;">3733.088</td>
<td style="text-align: right;">2007.971</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Gentoo</td>
<td style="text-align: right;">47.50488</td>
<td style="text-align: right;">14.98211</td>
<td style="text-align: right;">217.1870</td>
<td style="text-align: right;">5076.016</td>
<td style="text-align: right;">2008.081</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>You can use multiple functions, like <code>head</code> and <code>tail</code> to see two views of the intermediate step; <code>verbose = TRUE</code> prints the functions used for these peeps:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-3_c77972840911b9cdb7e0f3570d5ce4dd">
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">palmerpenguins<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>penguins <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">peep</span>(head, tail, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">verbose =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(species) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">where</span>(is.numeric), \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)))</span></code></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>head(.)</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6 × 8
  species island    bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
  &lt;fct&gt;   &lt;fct&gt;              &lt;dbl&gt;         &lt;dbl&gt;             &lt;int&gt;       &lt;int&gt;
1 Adelie  Torgersen           39.1          18.7               181        3750
2 Adelie  Torgersen           39.5          17.4               186        3800
3 Adelie  Torgersen           40.3          18                 195        3250
4 Adelie  Torgersen           NA            NA                  NA          NA
5 Adelie  Torgersen           36.7          19.3               193        3450
6 Adelie  Torgersen           39.3          20.6               190        3650
# ℹ 2 more variables: sex &lt;fct&gt;, year &lt;int&gt;</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>tail(.)</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6 × 8
  species   island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
  &lt;fct&gt;     &lt;fct&gt;           &lt;dbl&gt;         &lt;dbl&gt;             &lt;int&gt;       &lt;int&gt;
1 Chinstrap Dream            45.7          17                 195        3650
2 Chinstrap Dream            55.8          19.8               207        4000
3 Chinstrap Dream            43.5          18.1               202        3400
4 Chinstrap Dream            49.6          18.2               193        3775
5 Chinstrap Dream            50.8          19                 210        4100
6 Chinstrap Dream            50.2          18.7               198        3775
# ℹ 2 more variables: sex &lt;fct&gt;, year &lt;int&gt;</code></pre>
</div>
<div class="cell-output-display">
<div class="kable-table">
<table class="table table-sm table-striped small">
<colgroup>
<col style="width: 12%">
<col style="width: 19%">
<col style="width: 17%">
<col style="width: 23%">
<col style="width: 15%">
<col style="width: 11%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">species</th>
<th style="text-align: right;">bill_length_mm</th>
<th style="text-align: right;">bill_depth_mm</th>
<th style="text-align: right;">flipper_length_mm</th>
<th style="text-align: right;">body_mass_g</th>
<th style="text-align: right;">year</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Adelie</td>
<td style="text-align: right;">38.79139</td>
<td style="text-align: right;">18.34636</td>
<td style="text-align: right;">189.9536</td>
<td style="text-align: right;">3700.662</td>
<td style="text-align: right;">2008.013</td>
</tr>
<tr class="even">
<td style="text-align: left;">Chinstrap</td>
<td style="text-align: right;">48.83382</td>
<td style="text-align: right;">18.42059</td>
<td style="text-align: right;">195.8235</td>
<td style="text-align: right;">3733.088</td>
<td style="text-align: right;">2007.971</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Gentoo</td>
<td style="text-align: right;">47.50488</td>
<td style="text-align: right;">14.98211</td>
<td style="text-align: right;">217.1870</td>
<td style="text-align: right;">5076.016</td>
<td style="text-align: right;">2008.081</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>And you can include arguments to functions inside <code>peep()</code> with dot syntax if you’re using the <code>magrittr</code> pipe <code>%&gt;%</code> (at least for the line directly above the <code>peep</code>):<sup>1</sup></p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-4_5516ed69206d6ef01bcda46443171b23">
<div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">palmerpenguins<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>penguins <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">peep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> .)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb8-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(species) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb8-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">where</span>(is.numeric), \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)))</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 7 × 8
  species island    bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
  &lt;fct&gt;   &lt;fct&gt;              &lt;dbl&gt;         &lt;dbl&gt;             &lt;int&gt;       &lt;int&gt;
1 Adelie  Torgersen           39.1          18.7               181        3750
2 Adelie  Torgersen           39.5          17.4               186        3800
3 Adelie  Torgersen           40.3          18                 195        3250
4 Adelie  Torgersen           NA            NA                  NA          NA
5 Adelie  Torgersen           36.7          19.3               193        3450
6 Adelie  Torgersen           39.3          20.6               190        3650
7 Adelie  Torgersen           38.9          17.8               181        3625
# ℹ 2 more variables: sex &lt;fct&gt;, year &lt;int&gt;</code></pre>
</div>
<div class="cell-output-display">
<div class="kable-table">
<table class="table table-sm table-striped small">
<colgroup>
<col style="width: 12%">
<col style="width: 19%">
<col style="width: 17%">
<col style="width: 23%">
<col style="width: 15%">
<col style="width: 11%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">species</th>
<th style="text-align: right;">bill_length_mm</th>
<th style="text-align: right;">bill_depth_mm</th>
<th style="text-align: right;">flipper_length_mm</th>
<th style="text-align: right;">body_mass_g</th>
<th style="text-align: right;">year</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Adelie</td>
<td style="text-align: right;">38.79139</td>
<td style="text-align: right;">18.34636</td>
<td style="text-align: right;">189.9536</td>
<td style="text-align: right;">3700.662</td>
<td style="text-align: right;">2008.013</td>
</tr>
<tr class="even">
<td style="text-align: left;">Chinstrap</td>
<td style="text-align: right;">48.83382</td>
<td style="text-align: right;">18.42059</td>
<td style="text-align: right;">195.8235</td>
<td style="text-align: right;">3733.088</td>
<td style="text-align: right;">2007.971</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Gentoo</td>
<td style="text-align: right;">47.50488</td>
<td style="text-align: right;">14.98211</td>
<td style="text-align: right;">217.1870</td>
<td style="text-align: right;">5076.016</td>
<td style="text-align: right;">2008.081</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- End content -->
<div id="footer-session-info">
<details>
<summary>
Session info and package versions
</summary>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-6_bfcf79e61653a815874581a08af012ba">
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code> setting  value
 version  R version 4.3.1 (2023-06-16)
 os       macOS Ventura 13.4.1
 system   aarch64, darwin20
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Chicago
 date     2023-07-08
 pandoc   3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Packages ───────────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>           package loadedversion       date         source
           askpass           1.1 2019-01-13 CRAN (R 4.3.0)
        assertthat         0.2.1 2019-03-21 CRAN (R 4.3.0)
            cachem         1.0.8 2023-05-01 CRAN (R 4.3.0)
             callr         3.7.3 2022-11-02 CRAN (R 4.3.0)
               cli         3.6.1 2023-03-23 CRAN (R 4.3.0)
         codetools        0.2-19 2023-02-01 CRAN (R 4.3.1)
        colorspace         2.1-0 2023-01-23 CRAN (R 4.3.0)
            crayon         1.5.2 2022-09-29 CRAN (R 4.3.0)
              crul           1.3 2022-09-03 CRAN (R 4.3.1)
              curl         5.0.0 2023-01-12 CRAN (R 4.3.0)
          devtools         2.4.5 2022-10-11 CRAN (R 4.3.0)
            digest        0.6.31 2022-12-11 CRAN (R 4.3.0)
             dplyr         1.1.2 2023-04-20 CRAN (R 4.3.0)
          ellipsis         0.3.2 2021-04-29 CRAN (R 4.3.0)
          evaluate          0.21 2023-05-05 CRAN (R 4.3.0)
             fansi         1.0.4 2023-01-22 CRAN (R 4.3.0)
           fastmap         1.1.1 2023-02-24 CRAN (R 4.3.0)
 fontBitstreamVera         0.1.1 2017-02-01 CRAN (R 4.3.0)
    fontLiberation         0.1.0 2016-10-15 CRAN (R 4.3.0)
        fontquiver         0.2.1 2017-02-01 CRAN (R 4.3.0)
           forcats         1.0.0 2023-01-29 CRAN (R 4.3.0)
                fs         1.6.2 2023-04-25 CRAN (R 4.3.0)
           gdtools         0.3.3 2023-03-27 CRAN (R 4.3.0)
          generics         0.1.3 2022-07-05 CRAN (R 4.3.0)
            gfonts         0.2.0 2023-01-08 CRAN (R 4.3.0)
           ggplot2         3.4.2 2023-04-03 CRAN (R 4.3.0)
              glue         1.6.2 2022-02-24 CRAN (R 4.3.0)
            gtable         0.3.3 2023-03-21 CRAN (R 4.3.0)
               hms         1.1.3 2023-03-21 CRAN (R 4.3.0)
         htmltools         0.5.5 2023-03-23 CRAN (R 4.3.0)
       htmlwidgets         1.6.2 2023-03-17 CRAN (R 4.3.0)
          httpcode         0.3.0 2020-04-10 CRAN (R 4.3.0)
            httpuv        1.6.11 2023-05-11 CRAN (R 4.3.0)
          jsonlite         1.8.4 2022-12-06 CRAN (R 4.3.0)
             knitr          1.43 2023-05-25 CRAN (R 4.3.0)
             later         1.3.1 2023-05-02 CRAN (R 4.3.0)
          lazyeval         0.2.2 2019-03-15 CRAN (R 4.3.0)
         lifecycle         1.0.3 2022-10-07 CRAN (R 4.3.0)
         lubridate         1.9.2 2023-02-10 CRAN (R 4.3.0)
          magrittr         2.0.3 2022-03-30 CRAN (R 4.3.0)
           memoise         2.0.1 2021-11-26 CRAN (R 4.3.0)
              mime          0.12 2021-09-28 CRAN (R 4.3.0)
            miniUI       0.1.1.1 2018-05-18 CRAN (R 4.3.0)
           munsell         0.5.0 2018-06-12 CRAN (R 4.3.0)
           officer         0.6.2 2023-03-28 CRAN (R 4.3.0)
           openssl         2.0.6 2023-03-09 CRAN (R 4.3.0)
    palmerpenguins         0.1.1 2022-08-15 CRAN (R 4.3.0)
            pillar         1.9.0 2023-03-22 CRAN (R 4.3.0)
          pkgbuild         1.4.0 2022-11-27 CRAN (R 4.3.1)
         pkgconfig         2.0.3 2019-09-22 CRAN (R 4.3.0)
           pkgload         1.3.2 2022-11-16 CRAN (R 4.3.0)
       prettyunits         1.1.1 2020-01-24 CRAN (R 4.3.0)
          processx         3.8.1 2023-04-18 CRAN (R 4.3.0)
           profvis         0.3.7 2020-11-02 CRAN (R 4.3.1)
          promises       1.2.0.1 2021-02-11 CRAN (R 4.3.0)
                ps         1.7.5 2023-04-18 CRAN (R 4.3.0)
             purrr         1.0.1 2023-01-10 CRAN (R 4.3.0)
                R6         2.5.1 2021-08-19 CRAN (R 4.3.0)
              ragg         1.2.5 2023-01-12 CRAN (R 4.3.0)
              Rcpp        1.0.10 2023-01-22 CRAN (R 4.3.0)
             readr         2.1.4 2023-02-10 CRAN (R 4.3.0)
           remotes         2.4.2 2021-11-30 CRAN (R 4.3.0)
              renv        0.17.3 2023-04-06 CRAN (R 4.3.0)
             rlang         1.1.1 2023-04-28 CRAN (R 4.3.0)
         rmarkdown          2.21 2023-03-26 CRAN (R 4.3.0)
        rstudioapi          0.14 2022-08-22 CRAN (R 4.3.0)
               rvg         0.3.2 2023-01-07 CRAN (R 4.3.0)
            scales         1.2.1 2022-08-20 CRAN (R 4.3.0)
       sessioninfo         1.2.2 2021-12-06 CRAN (R 4.3.0)
             shiny         1.7.4 2022-12-15 CRAN (R 4.3.0)
           stringi        1.7.12 2023-01-11 CRAN (R 4.3.0)
           stringr         1.5.0 2022-12-02 CRAN (R 4.3.0)
       systemfonts         1.0.4 2022-02-11 CRAN (R 4.3.0)
       textshaping         0.3.6 2021-10-13 CRAN (R 4.3.0)
            thinkr          0.16 2022-08-22 CRAN (R 4.3.0)
            tibble         3.2.1 2023-03-20 CRAN (R 4.3.0)
             tidyr         1.3.0 2023-01-24 CRAN (R 4.3.0)
        tidyselect         1.2.0 2022-10-10 CRAN (R 4.3.0)
         tidyverse         2.0.0 2023-02-22 CRAN (R 4.3.0)
        timechange         0.2.0 2023-01-11 CRAN (R 4.3.0)
              tzdb         0.3.0 2022-03-28 CRAN (R 4.3.0)
        urlchecker         1.0.1 2021-11-30 CRAN (R 4.3.0)
           usethis         2.1.6 2022-05-25 CRAN (R 4.3.1)
              utf8         1.2.3 2023-01-31 CRAN (R 4.3.0)
              uuid         1.1-0 2022-04-19 CRAN (R 4.3.0)
             vctrs         0.6.2 2023-04-19 CRAN (R 4.3.0)
             withr         2.5.0 2022-03-03 CRAN (R 4.3.0)
              xfun          0.39 2023-04-20 CRAN (R 4.3.0)
              xml2         1.3.4 2023-04-27 CRAN (R 4.3.0)
            xtable         1.8-4 2019-04-21 CRAN (R 4.3.0)
              yaml         2.3.7 2023-01-23 CRAN (R 4.3.0)
               zip         2.3.0 2023-04-17 CRAN (R 4.3.0)</code></pre>
</div>
</div>
</details>
</div>




<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>You can’t use the base pipe’s placeholder, <code>_</code>, here, since it does not work in nested functions.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>dataframes</category>
  <category>piping</category>
  <guid>https://abraver.github.io/usefulRstuff/posts/thinkr_peep/index.html</guid>
  <pubDate>Thu, 01 Jun 2023 05:00:00 GMT</pubDate>
</item>
</channel>
</rss>
