<?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>BG2</title>
<link>https://bioarch-guide.netlify.app/</link>
<atom:link href="https://bioarch-guide.netlify.app/index.xml" rel="self" type="application/rss+xml"/>
<description>A site in which I rant about a number of things of varying utility to others.</description>
<generator>quarto-1.9.37</generator>
<lastBuildDate>Thu, 19 Dec 2024 00:00:00 GMT</lastBuildDate>
<item>
  <title>(To) Plotting Dental Inventory with ggplot2</title>
  <dc:creator>Bjørn </dc:creator>
  <link>https://bioarch-guide.netlify.app/posts/blog/2024-12-19_dental-plot/</link>
  <description><![CDATA[ 





<p>This is a tutorial on an intuitive (or at very least, pretty) way to visualise dental inventory in a sample. It requires only a basic knowledge of R, and, of course, that you have installed it along with RStudio.</p>
<p>Required packages:</p>
<ul>
<li>tidyverse</li>
<li>patchwork</li>
</ul>
<p>To install the packages (if needed):</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><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;">install.packages</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;">"tidyverse"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"patchwork"</span>))</span></code></pre></div></div>
</div>
<section id="load-data-and-packages" class="level3">
<h3 class="anchored" data-anchor-id="load-data-and-packages">Load data and packages</h3>
<div class="cell">
<div class="code-copy-outer-scaffold"><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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(patchwork)</span>
<span id="cb2-3">dental_inv <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> readr<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;">read_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://raw.githubusercontent.com/bbartholdy/dental-inv-plot/main/data/dental-inv.csv"</span>)</span></code></pre></div></div>
</div>
<p>The variables are:</p>
<table class="caption-top table">
<colgroup>
<col style="width: 50%">
<col style="width: 50%">
</colgroup>
<thead>
<tr class="header">
<th>variable name</th>
<th>description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>id</td>
<td>skeletal identifier</td>
</tr>
<tr class="even">
<td>t11:18; t21:28; t31:38; t41:48</td>
<td>status of tooth (t + FDI notation). <br> p = present; m = missing; dna = removed for dna sampling; aml = antemortem loss.</td>
</tr>
</tbody>
</table>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://bioarch-guide.netlify.app/posts/blog/2024-12-19_dental-plot/img/FDI-tooth-numbering-adult.png" class="img-fluid figure-img"></p>
<figcaption>https://www.careforsmiles.com.au/images/FDI-tooth-numbering-adult.png</figcaption>
</figure>
</div>
</section>
<section id="convert-data-to-long-format" class="level3">
<h3 class="anchored" data-anchor-id="convert-data-to-long-format">Convert data to long format</h3>
<p>First step is to convert the data to long format with the <code>pivot_longer</code> function. This will take all of the tooth columns and combine them to two columns; one with the tooth name, and one with the tooth status.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><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">dental_inv_long <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dental_inv <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;">pivot_longer</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>id, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tooth"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"status"</span>)</span></code></pre></div></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><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">dental_inv_long <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;">slice_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;">10</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># show first 10 entries</span></span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 10 × 3
   id    tooth status
   &lt;chr&gt; &lt;chr&gt; &lt;chr&gt; 
 1 id08  t11   p     
 2 id08  t12   p     
 3 id08  t13   m     
 4 id08  t14   p     
 5 id08  t15   p     
 6 id08  t16   p     
 7 id08  t17   p     
 8 id08  t18   m     
 9 id08  t21   p     
10 id08  t22   m     </code></pre>
</div>
</div>
<p>It would also be useful to have a column that indicates to which region of the mouth the tooth belongs.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><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">maxilla <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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</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;">18</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</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;">28</span>))</span>
<span id="cb6-2">left <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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</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;">28</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">31</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;">38</span>))</span>
<span id="cb6-3"></span>
<span id="cb6-4">dental_inv_long <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dental_inv <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(</span>
<span id="cb6-6">    t11<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>t48, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tooth"</span>,</span>
<span id="cb6-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"status"</span></span>
<span id="cb6-8">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-9">   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb6-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">region =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if_else</span>(tooth <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> maxilla, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"maxilla"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mandible"</span>), </span>
<span id="cb6-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">side =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if_else</span>(tooth <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> left, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"left"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.before =</span> status</span>
<span id="cb6-12">  )</span></code></pre></div></div>
</div>
</section>
<section id="prepare-separate-plots" class="level3">
<h3 class="anchored" data-anchor-id="prepare-separate-plots">Prepare separate plots</h3>
<p>Indicate order of the teeth in each region as in the FDI diagram shown above. starting from the upper right third molar. We will use this to reorder the teeth shown in the plot.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">upper_order <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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</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;">11</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</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;">28</span>))</span>
<span id="cb7-2">lower_order <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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">48</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;">41</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">31</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;">38</span>))</span>
<span id="cb7-3">upper_order</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code> [1] "t18" "t17" "t16" "t15" "t14" "t13" "t12" "t11" "t21" "t22" "t23" "t24"
[13] "t25" "t26" "t27" "t28"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><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">lower_order</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code> [1] "t48" "t47" "t46" "t45" "t44" "t43" "t42" "t41" "t31" "t32" "t33" "t34"
[13] "t35" "t36" "t37" "t38"</code></pre>
</div>
</div>
<p>The plots for the maxilla and mandible are prepared separately, then combined with the <a href="https://patchwork.data-imaginist.com/"><strong>patchwork</strong></a> package.</p>
<p>First, the plot of the maxillary dentition:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Plot for the maxillary dentition</span></span>
<span id="cb11-2">maxilla_pl <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dental_inv_long <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(region <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"maxilla"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># we only want maxillary teeth</span></span>
<span id="cb11-4">  <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;">tooth =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(tooth, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels =</span> upper_order)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># make sure the order on the plot is according to the order the teeth are positioned in the mouth</span></span>
<span id="cb11-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> tooth, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> status)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stack"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># stacked bar plot</span></span>
<span id="cb11-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"top"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># move x-axis text to top</span></span>
<span id="cb11-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_viridis_d</span>() <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># colour-blind-friendly pallette</span></span>
<span id="cb11-9"></span>
<span id="cb11-10">maxilla_pl</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://bioarch-guide.netlify.app/posts/blog/2024-12-19_dental-plot/index_files/figure-html/unnamed-chunk-5-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Then, the plot of the mandibular dentition:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Plot for the mandibular dentition</span></span>
<span id="cb12-2">mandible_pl <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dental_inv_long <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(region <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mandible"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-4">  <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;">tooth =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(tooth, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels =</span> lower_order)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> tooth, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> status)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stack"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_viridis_d</span>()</span>
<span id="cb12-8"></span>
<span id="cb12-9">mandible_pl</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://bioarch-guide.netlify.app/posts/blog/2024-12-19_dental-plot/index_files/figure-html/unnamed-chunk-6-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="combine-plots" class="level3">
<h3 class="anchored" data-anchor-id="combine-plots">Combine plots</h3>
<p><strong>UPDATE:</strong> The two dental plots are combined using the <strong>patchwork</strong> package. Thanks <a href="https://genomic.social/@jfy133">@jfy133</a> for bringing it to my attention! (and of course <a href="https://fosstodon.org/@thomasp85">@thomasp85</a>, the package developer).</p>
<p>We will combine them using <code>/</code> instead of <code>+</code>, because we want one on top of the other to mimic the maxilla’s and mandible’s position in the mouth:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1">maxilla_pl <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> mandible_pl</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://bioarch-guide.netlify.app/posts/blog/2024-12-19_dental-plot/index_files/figure-html/unnamed-chunk-7-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>The <code>plot_layout()</code> function allows us to easily combine the shared legends and axes.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1">maxilla_pl <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> mandible_pl <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;">plot_layout</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guides =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"collect"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis_titles =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"collect"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://bioarch-guide.netlify.app/posts/blog/2024-12-19_dental-plot/index_files/figure-html/unnamed-chunk-8-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>We can also add shared theme elements</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1">maxilla_pl <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> mandible_pl <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb15-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot_layout</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guides =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"collect"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis_titles =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"collect"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> </span>
<span id="cb15-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(</span>
<span id="cb15-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="cb15-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.title.x.top =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>() <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># remove the extra x-axis title</span></span>
<span id="cb15-7">  )</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://bioarch-guide.netlify.app/posts/blog/2024-12-19_dental-plot/index_files/figure-html/unnamed-chunk-9-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>And done! This gives (in my opinion) a nice, intuitive overview of the dental inventory in a sample, and could also be used to look at dental diseases (caries, calculus, periodontitis, etc).</p>


</section>

 ]]></description>
  <category>Rstats</category>
  <category>DentalAnth</category>
  <category>DataViz</category>
  <guid>https://bioarch-guide.netlify.app/posts/blog/2024-12-19_dental-plot/</guid>
  <pubDate>Thu, 19 Dec 2024 00:00:00 GMT</pubDate>
  <media:content url="https://bioarch-guide.netlify.app/images/dental-inv-plot.png" medium="image" type="image/png" height="103" width="144"/>
</item>
<item>
  <title>(To) the FAIR Data Principles</title>
  <dc:creator>Bjørn </dc:creator>
  <link>https://bioarch-guide.netlify.app/posts/blog/2024-06-24_fair-principles/</link>
  <description><![CDATA[ 





<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://bioarch-guide.netlify.app/images/FAIRdataprinciples_foster.png" class="img-fluid figure-img" alt="Stick drawings of the FAIR principles. Findable is a stick drawing of a person with a microscope finding a sheet of paper with 1s and 0s and exclaiming 'AH!'. Accessible is a stick figure looking at a framed picture with a DOI pointing to the same sheet of 1s and 0s from before. Interoperable is a stick figure asking another stick figure 'How do you open a .xzq file?'. Reusable is a stick figure handing saying 'here' while handing a stack of papers with a note saying 'CC' to another stick figure."></p>
<figcaption><a href="https://book.fosteropenscience.eu/" class="uri">https://book.fosteropenscience.eu/</a></figcaption>
</figure>
</div>
<p>The FAIR Data Principles were created as guidelines to making data more reusable, both by humans and machines. They also promote more responsible data stewardship of valuable digital resources. FAIR stands for Findable, Accessible, Interoperable, and Reusable <span class="citation" data-cites="wilkinsonFAIRGuiding2016">(<span class="nocase">Wilkinson et al.</span>, 2016)</span>.</p>
<section id="why-should-you-care-about-fair" class="level2">
<h2 class="anchored" data-anchor-id="why-should-you-care-about-fair">Why should you care about FAIR?</h2>
<p>It’s good for science and accumulating knowledge. Not convincing enough? It’s also good for you.</p>
<p>By making your research data <strong>findable</strong> to other researchers, you are also increasing the <strong>findability</strong> of your work, and potentially increasing your impact.</p>
<p>By ensuring that others can easily <strong>access</strong> and work on your data, you are also ensuring that your future self will be easily(ish) able to <strong>access</strong> and work on your data.</p>
<p>By increasing <strong>interoperability</strong>, you are ensuring that others, especially those from related fields, can readily integrate your work into their workflow and encourage collaboration.</p>
<p>By making it easier for other researchers to <strong>reuse</strong> your data, you are also increasing the likelihood that they will actually <strong>reuse</strong> your data, and not give up because they have to jump through hoops to do this. Just remember to provide a clear license and citation so that you get credit for your work!</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://bioarch-guide.netlify.app/images/rdm-storage.jpg" title="Title: Research Data Management" class="img-fluid figure-img" alt="An image of a person looking in a closet with various books, folders, locked boxes, and a lab coat hanging from the inside of the door. There is a speachbox saying 'data from last year?' The title of the image is Research Data Management."></p>
<figcaption>This illustration is created by Scriberia with The Turing Way community. Used under a CC-BY 4.0 licence. DOI: <a href="https://doi.org/10.5281/zenodo.3332807">10.5281/zenodo.3332807</a></figcaption>
</figure>
</div>
</section>
<section id="definition-of-the-fair-principles" class="level2">
<h2 class="anchored" data-anchor-id="definition-of-the-fair-principles">Definition of the FAIR Principles</h2>
<p><strong><span class="x-large">F</span>indable</strong> means you can actually locate the (meta)data. This requires the data to be:</p>
<ul>
<li>assigned a persistent identifier (PID)</li>
<li>accompanied by metadata</li>
<li>registered in a searchable resource.</li>
</ul>
<p><strong><span class="x-large">A</span>ccessible</strong> means there should be a clear path to accessing the (meta)data. Preferably accessible via:</p>
<ul>
<li>an open, standardised protocol.</li>
<li>restricted access (authentication), if necessary.</li>
</ul>
<p><strong><span class="x-large">I</span>nteroperable</strong> means the (meta)data should be in a format that allows them to be used in common applications and workflows, preferably with:</p>
<ul>
<li>formal, accessible, broadly applicable language</li>
<li>vocabularies that follow FAIR principles</li>
<li>references to other related (meta)data</li>
</ul>
<p><strong><span class="x-large">R</span>eusable</strong> means the data should be well-documented, including:</p>
<ul>
<li>domain-relevant guidance using community standards for researchers who wish to reuse the data</li>
<li>provenance of their creation</li>
<li>a license to indicate the terms of reuse</li>
</ul>
<p><a href="https://www.go-fair.org/" class="uri">https://www.go-fair.org/</a></p>
</section>
<section id="putting-principles-into-practice" class="level2">
<h2 class="anchored" data-anchor-id="putting-principles-into-practice">Putting principles into practice</h2>
<p>Things to ask yourself:</p>
<ul>
<li>Can someone search for and find your data?</li>
<li>Do the data have a unique persistent identifier that you can refer to when communicating your findings?</li>
<li>Once someone finds your data, can they be downloaded or accessed in any way?</li>
<li>can information about your data be found, even if the dataset no longer exists?</li>
<li>Once the data have been obtained, can they easily be integrated into existing workflows?</li>
<li>Is it clear how researchers should re-use the data, and how they are allowed to do this?</li>
<li>How should they give you credit when re-using the data?</li>
</ul>
<p>I have found that it helps to prepare FAIR data by working backwards through the FAIR principles.</p>
<p>It all starts by ensuring your data are <strong>reusable</strong>. Proper documentation early on is much easier to do when the data are fresh in your memory. The most basic form of documentation is a README. This can be a plain-text (<em>README.txt</em>) or markdown (<em>README.md</em>) file. Here, you should describe the project and the data, including the methodology of data collection and a description of the variables (data dictionary). It may also be useful to add how the data can be accessed and what software might be needed to work with the data. For more information, see <a href="https://www.makeareadme.com/" class="uri">https://www.makeareadme.com/</a>.</p>
<p>Documenting the analytical workflow is also important for <strong>reuse</strong>. This can be done using using code notebooks such as <a href="https://jupyter.org/">Jupyter</a>, <a href="https://bookdown.org/yihui/rmarkdown/">R Markdown</a>, or <a href="https://quarto.org/">Quarto</a> (my personal favourite).</p>
<p>Making sure your data can be easily integrated into workflows (<strong>interoperable</strong>) requires using tools and data vocabularies that are standard to your field. To ensure wider adoption of the data, you should also be using free and open source tools and formats (for example, export your data as a CSV file rather than an Excel spreadsheet).</p>
<p>Making the data <strong>accessible</strong> is as easy (or difficult) as uploading them to a trusted data repository. The best way to choose is by exploring what repositories others in your field use. There are also general purpose repositories like <a href="https://zenodo.org">Zenodo</a>. You can find useful information on (trusted) repositories on <a href="https://re3data.org">re3data</a>.</p>
<p>Finally, to make your data <strong>findable</strong>, you should make sure to include the persistent identifier in your research article (Data Availability Statement). Often the data repository will allow you to reserve a DOI for your dataset. This means you can wait to publish your data until the manuscript has been accepted. Simply add the reserved DOI to your article, and then make the repository public when the manuscript has been accepted/published. Avoid using an email address for contact, or a personal/group website as the (only) data repository. These are more susceptible to change than, for example, an <a href="https://orcid.org/">ORCID</a> and a <a href="https://www.doi.org/">Digital Object Identifier (DOI)</a> (though, these are also not foolproof).</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://bioarch-guide.netlify.app/images/archive-or-publish.jpg" class="img-fluid figure-img" alt="A person with a lab coat is pushing a cart with 2 boxes, a book, and a poster tube. There is a sign pointing in two directions: Publish and Archive. The publish route is a road leading to the same person with a megaphone standing in front of a display of books, boxes, and folders. On the road it says 'Documentation', 'License', and 'Repository'. The archive route is a road leading to the same person storing books, boxes, and folders in a large vault with a security guard standing next to it. On the road it says 'Access Rights' and 'Agreements'."></p>
<figcaption>This illustration is created by Scriberia with The Turing Way community. Used under a CC-BY 4.0 licence. DOI: <a href="https://doi.org/10.5281/zenodo.3332807">10.5281/zenodo.3332807</a></figcaption>
</figure>
</div>
</section>
<section id="what-a-repository-can-do-for-you" class="level2">
<h2 class="anchored" data-anchor-id="what-a-repository-can-do-for-you">What a repository can do for you</h2>
<p>Repositories have the infrastructure to ensure long-term storage of your dataset. Zenodo, for example, is funded by CERN and OpenAIRE, among others. CERN has also committed to hosting the repository for the lifetime of CERN itself. Repositories also provide you with a persistent identifier and register your repository metadata in searchable resources. They implement access protocols for both humans (a nice big ‘Download’ button) and computers (Application Programming Interface).</p>
<p>Repositories will make it easy to adhere to general metadata standards (during the upload process you provide information about your data), and some repositories will enforce field-specific metadata standards. They will also track the (re-)usage (views, dowloads, citations) and display the license and recommended citation.</p>
</section>
<section id="common-misconceptions" class="level2">
<h2 class="anchored" data-anchor-id="common-misconceptions">Common misconceptions</h2>
<section id="fair-open" class="level3">
<h3 class="anchored" data-anchor-id="fair-open">FAIR = Open</h3>
<p>There are many reasons why a dataset cannot (and should not) be openly available. Many repositories allow you to restrict access to your dataset. In these cases, there should be a clear process of requesting access to the data, that can be updated on the repository. A statement of</p>
<blockquote class="blockquote">
<p>The data are available upon request.</p>
</blockquote>
<p>at the bottom of your article is not a clear process and cannot be updated with new contact information when needed. The data are also not very <strong>findable</strong>.</p>
</section>
<section id="i-use-the-supplementary-materials-of-journals.-isnt-that-fair-enough" class="level3">
<h3 class="anchored" data-anchor-id="i-use-the-supplementary-materials-of-journals.-isnt-that-fair-enough">I use the supplementary materials of journals. Isn’t that FAIR enough?</h3>
<p>The persistent identifier is often the same as the article, which means that the data do not have a unique identifier required to be <strong>findable</strong>. <strong>Access</strong> to a journal article’s supplementary materials may also be stuck behind a paywall. They also rarely have access procedures for computers (e.g.&nbsp;API). Supplementary materials are often in the form of a PDF document. This is not very <strong>interoperable</strong> and very difficult to <strong>reuse</strong>.</p>
</section>
</section>
<section id="i-still-have-questions" class="level2">
<h2 class="anchored" data-anchor-id="i-still-have-questions">I still have questions!?</h2>
<p>Where can you go for more help? Most institutions have dedicated (and passionate!) people working on promoting research data managment (including FAIR) and Open Science. These can be Data Stewards or (Digital) Librarians. Try to find them at your institute and reach out! Otherwise <a href="https://the-turing-way.netlify.app/reproducible-research/rdm/rdm-fair">The Turing Way</a> is also a good place to start.</p>



</section>

<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0" data-line-spacing="2">
<div id="ref-wilkinsonFAIRGuiding2016" class="csl-entry">
<span class="nocase">Wilkinson, M. D., Dumontier, M., Aalbersberg, Ij. J., Appleton, G., Axton, M., Baak, A., Blomberg, N., Boiten, J.-W., da Silva Santos, L. B., Bourne, P. E., Bouwman, J., Brookes, A. J., Clark, T., Crosas, M., Dillo, I., Dumon, O., Edmunds, S., Evelo, C. T., Finkers, R., … Mons, B.</span> (2016). The <span>FAIR Guiding Principles</span> for scientific data management and stewardship. <em>Scientific Data</em>, <em>3</em>(1), 160018. <a href="https://doi.org/10.1038/sdata.2016.18">https://doi.org/10.1038/sdata.2016.18</a>
</div>
</div></section></div> ]]></description>
  <category>open-science</category>
  <category>FAIR</category>
  <guid>https://bioarch-guide.netlify.app/posts/blog/2024-06-24_fair-principles/</guid>
  <pubDate>Mon, 24 Jun 2024 00:00:00 GMT</pubDate>
  <media:content url="https://bioarch-guide.netlify.app/images/rdm-storage.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>(To) The Bioarchaeologist’s Guide</title>
  <dc:creator>Bjørn </dc:creator>
  <link>https://bioarch-guide.netlify.app/posts/blog/2023-09-24_bg2-bg2/</link>
  <description><![CDATA[ 





<p>The Bioarchaeologist’s Guide has this to say on the subject of The Bioarchaeologist’s Guide:</p>
<section id="hello-world" class="level2">
<h2 class="anchored" data-anchor-id="hello-world">Hello World</h2>
<p>This is the inaugural post for <em>The Bioarchaeologist’s Guide</em>. The topic of this post will be <em>The Bioarchaeologist’s Guide</em>. How it came to be, what will be its purpose, and who is this Bjørn person anyway?</p>
</section>
<section id="how-it-came-to-be" class="level2">
<h2 class="anchored" data-anchor-id="how-it-came-to-be">How it came to be</h2>
<p>I have a bunch of notes on various topics that I wanted to share. Now I’m sharing them. That’s it.</p>
</section>
<section id="what-will-be-its-purpose" class="level2">
<h2 class="anchored" data-anchor-id="what-will-be-its-purpose">What will be its purpose</h2>
<p>The purpose of this site… blog… whatever it ends up being, is to provide a set of helpful resources on common topics in the field of bioarchaeology. Some may be interesting, others won’t. Some may be broadly applicable to many fields, others won’t. Topics will include <strong>dental diseases</strong>, <strong>statistics</strong>, the <strong>R programming language</strong>, and <strong>open science</strong>. It will not contain any entries on The Hitchhiker’s Guide to the Galaxy, but there will be quotes. There are, at the time of writing, two types of resources: <a href="../../../posts/blog/index.html">Blog posts</a> and <a href="../../../posts/entries/index.html">Entries</a>. Blog posts, like the one you are reading now, are long, often opinionated—but still grounded in facts— posts on a particular subject. If you don’t care about my opinions and find my writing to be unnecessarily filled with h2g2 references that you don’t understand and/or care about, you will often be able to find the essential parts of the blog posts in Entries. Basically the TL;DR.</p>
<p>I have done my best to make sure this site… blog… thing, will be as accessible as possible. The colours were generated using <a href="https://randoma11y.com/">randoma11y</a> and are chosen for their high contrast. The primary theme was styled after the BBC television adaptation of the Hitchhiker’s Guide, but there is also a secondary theme with a lower contrast and <a href="https://brailleinstitute.org/freefont">Atkinson Hyperlegible Font</a> (themes can be accessed using the switch in the navigation bar). I will also make sure that all images have alt text.</p>
</section>
<section id="who-is-this-bjørn-person-anyway" class="level2">
<h2 class="anchored" data-anchor-id="who-is-this-bjørn-person-anyway">Who is this Bjørn person anyway?</h2>
<p>I am a human, and the errors will reflect that (and I’m genuinely happy to have them pointed out). I’m a PhD student doing bioarchaeology. I have also been known to fumble may way through topics like Open Science and statistics.</p>
<p>Well, that about wraps it up for this post.</p>


</section>

 ]]></description>
  <category>about</category>
  <guid>https://bioarch-guide.netlify.app/posts/blog/2023-09-24_bg2-bg2/</guid>
  <pubDate>Sun, 24 Sep 2023 00:00:00 GMT</pubDate>
</item>
</channel>
</rss>
