add more posts

This commit is contained in:
Kyle Belanger 2023-10-12 09:05:03 -04:00
parent b42aa0b54b
commit 9ac465af85
11 changed files with 1813 additions and 8 deletions

View file

@ -156,7 +156,7 @@ ul.task-list li input[type="checkbox"] {
<!-- margin-sidebar -->
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
<h5 class="quarto-listing-category-title">Categories</h5><div class="quarto-listing-category category-default"><div class="category" data-category="">All <span class="quarto-category-count">(6)</span></div></div></div>
<h5 class="quarto-listing-category-title">Categories</h5><div class="quarto-listing-category category-default"><div class="category" data-category="">All <span class="quarto-category-count">(8)</span></div><div class="category" data-category="Distill">Distill <span class="quarto-category-count">(1)</span></div><div class="category" data-category="TidyTuesday">TidyTuesday <span class="quarto-category-count">(1)</span></div></div></div>
<!-- main -->
<main class="content quarto-banner-title-block column-page-left" id="quarto-document-content">
@ -169,7 +169,77 @@ ul.task-list li input[type="checkbox"] {
<div class="quarto-listing quarto-listing-container-default" id="listing-listing">
<div class="list quarto-listing-default">
<div class="quarto-post image-right" data-index="0" data-listing-date-sort="1595649600000" data-listing-file-modified-sort="1697114923312" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="4">
<div class="quarto-post image-right" data-index="0" data-categories="TidyTuesday" data-listing-date-sort="1614315600000" data-listing-file-modified-sort="1697115484734" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="12">
<div class="thumbnail">
<p><a href="./posts/2021-02-26_tidytuesday-hbcu-enrollment/tidytuesday-2021-week-6-hbcu-enrolment.html"> <p class="card-img-top"><img src="posts\2021-02-26_tidytuesday-hbcu-enrollment\tidytuesday-2021-week-6-hbcu-enrolment_files\figure-html\unnamed-chunk-10-1.png" class="thumbnail-image card-img"/></p> </a></p>
</div>
<div class="body">
<a href="./posts/2021-02-26_tidytuesday-hbcu-enrollment/tidytuesday-2021-week-6-hbcu-enrolment.html">
<h3 class="no-anchor listing-title">
TidyTuesday 2021 Week 6: HBCU Enrollment
</h3>
<div class="listing-subtitle">
<p>TidyTuesday 2021 Week 6: HBCU Enrollment. Posts looks at tidying the data ,as well as making some graphs about the data.</p>
</div>
</a>
<div class="listing-categories">
<div class="listing-category" onclick="window.quartoListingCategory('TidyTuesday'); return false;">
TidyTuesday
</div>
</div>
<a href="./posts/2021-02-26_tidytuesday-hbcu-enrollment/tidytuesday-2021-week-6-hbcu-enrolment.html">
<div class="listing-description">
Recently I was struggling to find a data project to work on, I felt a bit stuck with some of my current projects, so I begun to scour the internet to find something to work…
</div>
</a>
</div>
<div class="metadata">
<a href="./posts/2021-02-26_tidytuesday-hbcu-enrollment/tidytuesday-2021-week-6-hbcu-enrolment.html">
<div class="listing-date">
Feb 26, 2021
</div>
<div class="listing-author">
Kyle Belanger
</div>
</a>
</div>
</div>
<div class="quarto-post image-right" data-index="1" data-categories="Distill" data-listing-date-sort="1610427600000" data-listing-file-modified-sort="1697115793517" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="3">
<div class="thumbnail">
<p><a href="./posts/2021-01-12_blogdown-to-distill/creating-a-distill-blog.html"> <div class="listing-item-img-placeholder card-img-top" >&nbsp;</div> </a></p>
</div>
<div class="body">
<a href="./posts/2021-01-12_blogdown-to-distill/creating-a-distill-blog.html">
<h3 class="no-anchor listing-title">
Converting From Blogdown to Distill
</h3>
<div class="listing-subtitle">
<p>A meta post on transferring from a blogdown to distill blog site</p>
</div>
</a>
<div class="listing-categories">
<div class="listing-category" onclick="window.quartoListingCategory('Distill'); return false;">
Distill
</div>
</div>
<a href="./posts/2021-01-12_blogdown-to-distill/creating-a-distill-blog.html">
<div class="listing-description">
I have since converted this blog to a quarto blog, but am leaving this post up in case anyone finds it useful
</div>
</a>
</div>
<div class="metadata">
<a href="./posts/2021-01-12_blogdown-to-distill/creating-a-distill-blog.html">
<div class="listing-date">
Jan 12, 2021
</div>
<div class="listing-author">
Kyle Belanger
</div>
</a>
</div>
</div>
<div class="quarto-post image-right" data-index="2" data-listing-date-sort="1595649600000" data-listing-file-modified-sort="1697114923312" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="4">
<div class="thumbnail">
<p><a href="./posts/2020-07-25_diabetes-data-collection-and-cleaning/diabetes-in-rural-north-carolina-data-collection-and-cleaning.html"> <p class="card-img-top"><img src="posts\2020-07-25_diabetes-data-collection-and-cleaning\data-cleaning.png" class="thumbnail-image card-img"/></p> </a></p>
</div>
@ -197,7 +267,7 @@ Kyle Belanger
</a>
</div>
</div>
<div class="quarto-post image-right" data-index="1" data-listing-date-sort="1592798400000" data-listing-file-modified-sort="1697115048321" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="3">
<div class="quarto-post image-right" data-index="3" data-listing-date-sort="1592798400000" data-listing-file-modified-sort="1697115048321" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="3">
<div class="thumbnail">
<p><a href="./posts/2020-06-22_excel-data-multiple-headers/importing-excel-data-with-multiple-header-rows.html"> <p class="card-img-top"><img src="posts\2020-06-22_excel-data-multiple-headers\example_data_img1.png" alt="image of example data" class="thumbnail-image card-img"/></p> </a></p>
</div>
@ -225,7 +295,7 @@ Kyle Belanger
</a>
</div>
</div>
<div class="quarto-post image-right" data-index="2" data-listing-date-sort="1581570000000" data-listing-file-modified-sort="1697056704620" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="11">
<div class="quarto-post image-right" data-index="4" data-listing-date-sort="1581570000000" data-listing-file-modified-sort="1697056704620" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="11">
<div class="thumbnail">
<p><a href="./posts/2020-02-13_basic-who-TB-data/basic-exploration-of-who-tuberculosis-data.html"> <p class="card-img-top"><img src="posts\2020-02-13_basic-who-TB-data\basic-exploration-of-who-tuberculosis-data_files\figure-html\unnamed-chunk-5-1.png" class="thumbnail-image card-img"/></p> </a></p>
</div>
@ -253,7 +323,7 @@ Kyle Belanger
</a>
</div>
</div>
<div class="quarto-post image-right" data-index="3" data-listing-date-sort="1581310800000" data-listing-file-modified-sort="1697114568395" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="8">
<div class="quarto-post image-right" data-index="5" data-listing-date-sort="1581310800000" data-listing-file-modified-sort="1697114568395" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="8">
<div class="thumbnail">
<p><a href="./posts/2020-02-10_line-graphs-and-interactivity/line-graphs-and-interactivity.html"> <p class="card-img-top"><img src="posts\2020-02-10_line-graphs-and-interactivity\flu_surveillance.png" alt="Example Line Graph" class="thumbnail-image card-img"/></p> </a></p>
</div>
@ -281,7 +351,7 @@ Kyle Belanger
</a>
</div>
</div>
<div class="quarto-post image-right" data-index="4" data-listing-date-sort="1580274000000" data-listing-file-modified-sort="1697114439706" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="3">
<div class="quarto-post image-right" data-index="6" data-listing-date-sort="1580274000000" data-listing-file-modified-sort="1697114439706" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="3">
<div class="thumbnail">
<p><a href="./posts/2020-01-29_facets-and-humility/facets-and-a-lesson-in-humility.html"> <p class="card-img-top"><img src="posts\2020-01-29_facets-and-humility\WHO_LIFE.png" class="thumbnail-image card-img"/></p> </a></p>
</div>
@ -309,7 +379,7 @@ Kyle Belanger
</a>
</div>
</div>
<div class="quarto-post image-right" data-index="5" data-listing-date-sort="1579842000000" data-listing-file-modified-sort="1697052101192" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="2">
<div class="quarto-post image-right" data-index="7" data-listing-date-sort="1579842000000" data-listing-file-modified-sort="1697052101192" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="2">
<div class="thumbnail">
<p><a href="./posts/2020-01-04_my-start-to-r/my-start-to-r.html"> <p class="card-img-top"><img src="posts\2020-01-04_my-start-to-r\my-start-to-r_files\figure-html\unnamed-chunk-5-1.png" class="thumbnail-image card-img"/></p> </a></p>
</div>

View file

@ -2,6 +2,8 @@
{
"listing": "/blog.html",
"items": [
"/posts/2021-02-26_tidytuesday-hbcu-enrollment/tidytuesday-2021-week-6-hbcu-enrolment.html",
"/posts/2021-01-12_blogdown-to-distill/creating-a-distill-blog.html",
"/posts/2020-07-25_diabetes-data-collection-and-cleaning/diabetes-in-rural-north-carolina-data-collection-and-cleaning.html",
"/posts/2020-06-22_excel-data-multiple-headers/importing-excel-data-with-multiple-header-rows.html",
"/posts/2020-02-13_basic-who-TB-data/basic-exploration-of-who-tuberculosis-data.html",

View file

@ -0,0 +1,504 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.3.450">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="author" content="Kyle Belanger">
<meta name="dcterms.date" content="2021-01-12">
<title>Kyle Belanger - Converting From Blogdown to Distill</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}
/* CSS for syntax highlighting */
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
}
pre.numberSource { margin-left: 3em; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
</style>
<script src="../../site_libs/quarto-nav/quarto-nav.js"></script>
<script src="../../site_libs/quarto-nav/headroom.min.js"></script>
<script src="../../site_libs/clipboard/clipboard.min.js"></script>
<script src="../../site_libs/quarto-search/autocomplete.umd.js"></script>
<script src="../../site_libs/quarto-search/fuse.min.js"></script>
<script src="../../site_libs/quarto-search/quarto-search.js"></script>
<meta name="quarto:offset" content="../../">
<script src="../../site_libs/quarto-html/quarto.js"></script>
<script src="../../site_libs/quarto-html/popper.min.js"></script>
<script src="../../site_libs/quarto-html/tippy.umd.min.js"></script>
<script src="../../site_libs/quarto-html/anchor.min.js"></script>
<link href="../../site_libs/quarto-html/tippy.css" rel="stylesheet">
<link href="../../site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="../../site_libs/bootstrap/bootstrap.min.js"></script>
<link href="../../site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="../../site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
<script id="quarto-search-options" type="application/json">{
"location": "navbar",
"copy-button": false,
"collapse-after": 3,
"panel-placement": "end",
"type": "overlay",
"limit": 20,
"language": {
"search-no-results-text": "No results",
"search-matching-documents-text": "matching documents",
"search-copy-link-title": "Copy link to search",
"search-hide-matches-text": "Hide additional matches",
"search-more-match-text": "more match in this document",
"search-more-matches-text": "more matches in this document",
"search-clear-button-title": "Clear",
"search-detached-cancel-button-title": "Cancel",
"search-submit-button-title": "Submit",
"search-label": "Search"
}
}</script>
<link rel="stylesheet" href="../../styles.css">
</head>
<body class="floating nav-fixed">
<div id="quarto-search-results"></div>
<header id="quarto-header" class="headroom fixed-top">
<nav class="navbar navbar-expand-lg navbar-dark ">
<div class="navbar-container container-fluid">
<div class="navbar-brand-container">
<a class="navbar-brand" href="../../index.html">
<span class="navbar-title">Kyle Belanger</span>
</a>
</div>
<div id="quarto-search" class="" title="Search"></div>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav navbar-nav-scroll ms-auto">
<li class="nav-item">
<a class="nav-link" href="../../blog.html" rel="" target="">
<span class="menu-text">Posts</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="../../kyle_resume.pdf" rel="" target="">
<span class="menu-text">Resume</span></a>
</li>
<li class="nav-item compact">
<a class="nav-link" href="https://github.com/mmmmtoasty19" rel="" target=""><i class="bi bi-github" role="img">
</i>
<span class="menu-text"></span></a>
</li>
</ul>
<div class="quarto-navbar-tools">
</div>
</div> <!-- /navcollapse -->
</div> <!-- /container-fluid -->
</nav>
</header>
<!-- content -->
<header id="title-block-header" class="quarto-title-block default toc-left page-columns page-full">
<div class="quarto-title-banner page-columns page-full">
<div class="quarto-title column-body">
<h1 class="title">Converting From Blogdown to Distill</h1>
<p class="subtitle lead"></p><p>A meta post on transferring from a blogdown to distill blog site</p><p></p>
<div class="quarto-categories">
<div class="quarto-category">Distill</div>
</div>
</div>
</div>
<div class="quarto-title-meta">
<div>
<div class="quarto-title-meta-heading">Author</div>
<div class="quarto-title-meta-contents">
<p><a href="https://kyleb.rbind.io/">Kyle Belanger</a> </p>
</div>
</div>
<div>
<div class="quarto-title-meta-heading">Published</div>
<div class="quarto-title-meta-contents">
<p class="date">January 12, 2021</p>
</div>
</div>
</div>
</header><div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article page-navbar">
<!-- sidebar -->
<nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal sidebar-navigation floating overflow-auto">
<nav id="TOC" role="doc-toc" class="toc-active">
<h2 id="toc-title">Table of contents</h2>
<ul>
<li><a href="#authors-note" id="toc-authors-note" class="nav-link active" data-scroll-target="#authors-note">Authors Note</a></li>
<li><a href="#introduction" id="toc-introduction" class="nav-link" data-scroll-target="#introduction">Introduction</a></li>
<li><a href="#challenges" id="toc-challenges" class="nav-link" data-scroll-target="#challenges">Challenges</a></li>
<li><a href="#going-outside-the-box" id="toc-going-outside-the-box" class="nav-link" data-scroll-target="#going-outside-the-box">Going Outside the Box</a>
<ul class="collapse">
<li><a href="#code-folding" id="toc-code-folding" class="nav-link" data-scroll-target="#code-folding">Code Folding</a></li>
<li><a href="#customizing-the-home-page" id="toc-customizing-the-home-page" class="nav-link" data-scroll-target="#customizing-the-home-page">Customizing the Home Page</a></li>
</ul></li>
<li><a href="#final-thoughts" id="toc-final-thoughts" class="nav-link" data-scroll-target="#final-thoughts">Final Thoughts</a></li>
</ul>
</nav>
</nav>
<div id="quarto-sidebar-glass" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass"></div>
<!-- margin-sidebar -->
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
</div>
<!-- main -->
<main class="content quarto-banner-title-block" id="quarto-document-content">
<section id="authors-note" class="level1">
<h1>Authors Note</h1>
<p>I have since converted this blog to a quarto blog, but am leaving this post up in case anyone finds it useful</p>
</section>
<section id="introduction" class="level1">
<h1>Introduction</h1>
<p>This metapost describes changing my personal blog from a blogdown site to a distill blog site. I will not be going over starting a site from scratch as there are already several great resources for doing this. What I will be going over is some of the challenges and some of the changes and tips I have found. If you are looking to start a site from scratch, check out these great resources:</p>
<ul>
<li>The Distill for Rmarkdown page on creating a <a href="https://rstudio.github.io/distill/blog.html">blog</a></li>
<li>This excellent post from Shamindra Shrotriya on setting up a <a href="https://www.shamindras.com/posts/2019-07-11-shrotriya2019distillpt1/">blog</a></li>
<li>This post from the Mockup <a href="https://themockup.blog/posts/2020-08-01-building-a-blog-with-distill/">blog</a></li>
</ul>
<p>This last post goes into some of the pros and cons of using distill instead of blogdown. If you want simplicity, go with distill without much customization. If you want the ability for a lot of customization and dont mind being frustrated with Hugo, go with blogdown.</p>
</section>
<section id="challenges" class="level1">
<h1>Challenges</h1>
<p>The good thing about switching from blogdown to distill was I had very few challenges! The distill documentation, combined with the two posts I listed, helped me with most of my troubles. The only issue I ran into was distill contains a function called <code>import_post()</code>, which according to the docs, only needs a published URL to work. I could never solve why, but I could not pull in the posts from my old blogdown site. This wasnt a big deal as I had the original rmarkdown documents, but this could pose an issue if you didnt.</p>
</section>
<section id="going-outside-the-box" class="level1">
<h1>Going Outside the Box</h1>
<section id="code-folding" class="level2">
<h2 class="anchored" data-anchor-id="code-folding">Code Folding</h2>
<p>When I converted my blog on 12/30/2020, code folding was not included as an option by default in distill. At that time, an excellent package called <a href="https://github.com/ijlyttle/codefolder">Codefolder</a> added the functionality. Since going live with the blog, code folding has been added to distill.<a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a> Code folding is available for either the whole document or individual code sections. The default caption is “Show Code”, but instead of typing <code>code_folding=TRUE</code>, you can provide a string to change the caption.</p>
<div class="cell" data-code_folding="Lets See It">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Some awesome code </span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="co"># That does awesome things</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="customizing-the-home-page" class="level2">
<h2 class="anchored" data-anchor-id="customizing-the-home-page">Customizing the Home Page</h2>
<p>By default, a distill blogs home page will be the blog index page. I chose to edit my home page to be a landing page for myself and then have the blog index as a separate page. When creating a new blog, this is the default YAML header for your index page.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="pp">---</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="fu">title</span><span class="kw">:</span><span class="at"> </span><span class="st">"New Site"</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="fu">site</span><span class="kw">:</span><span class="at"> distill::distill_website</span></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a><span class="fu">listing</span><span class="kw">:</span><span class="at"> posts</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a><span class="pp">---</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>The critical piece here is the line <code>site: distill::distill_website</code>. This line is what is needed to render the website. For my home page, I decided to use the package <a href="https://github.com/seankross/postcards">Postcard</a>, which is used to generate simple landing pages. I wont go into every step as there is already a great post by <a href="https://alison.rbind.io/post/2020-12-22-postcards-distill/">Alison Hill</a> on how to do that. However, I will point out the most crucial part of the new index page the YAML header needs to contain these two lines.</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="fu">output</span><span class="kw">:</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="at"> postcards::trestles</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="fu">site</span><span class="kw">:</span><span class="at"> distill::distill_website</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</section>
</section>
<section id="final-thoughts" class="level1">
<h1>Final Thoughts</h1>
<p>I have enjoyed the simplicity of Distill. While not nearly as customizable as blogdown, getting a blog site up and running in under an hour is pretty lovely. I hope to keep exploring what Distill has to offer and keep posting my updates!</p>
</section>
<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document" role="doc-endnotes"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>
<ol>
<li id="fn1"><p>Note that as of publishing, code folding is only available in the development version of distill<a href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
</ol>
</section><section class="quarto-appendix-contents"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div id="quarto-reuse" class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">https://creativecommons.org/licenses/by/4.0/</a></div></div></section><section class="quarto-appendix-contents"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{belanger2021,
author = {Belanger, Kyle},
title = {Converting {From} {Blogdown} to {Distill}},
date = {2021-01-12},
langid = {en}
}
</code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-belanger2021" class="csl-entry quarto-appendix-citeas" role="listitem">
Belanger, Kyle. 2021. <span>“Converting From Blogdown to
Distill.”</span> January 12, 2021.
</div></div></section></div></main> <!-- /main -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const isCodeAnnotation = (el) => {
for (const clz of el.classList) {
if (clz.startsWith('code-annotation-')) {
return true;
}
}
return false;
}
const clipboard = new window.ClipboardJS('.code-copy-button', {
text: function(trigger) {
const codeEl = trigger.previousElementSibling.cloneNode(true);
for (const childEl of codeEl.children) {
if (isCodeAnnotation(childEl)) {
childEl.remove();
}
}
return codeEl.innerText;
}
});
clipboard.on('success', function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
let tooltip;
if (window.bootstrap) {
button.setAttribute("data-bs-toggle", "tooltip");
button.setAttribute("data-bs-placement", "left");
button.setAttribute("data-bs-title", "Copied!");
tooltip = new bootstrap.Tooltip(button,
{ trigger: "manual",
customClass: "code-copy-button-tooltip",
offset: [0, -8]});
tooltip.show();
}
setTimeout(function() {
if (tooltip) {
tooltip.hide();
button.removeAttribute("data-bs-title");
button.removeAttribute("data-bs-toggle");
button.removeAttribute("data-bs-placement");
}
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
});
function tippyHover(el, contentFn) {
const config = {
allowHTML: true,
content: contentFn,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start'
};
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
// use id or data attribute instead here
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
return note.innerHTML;
});
}
let selectedAnnoteEl;
const selectorForAnnotation = ( cell, annotation) => {
let cellAttr = 'data-code-cell="' + cell + '"';
let lineAttr = 'data-code-annotation="' + annotation + '"';
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
return selector;
}
const selectCodeLines = (annoteEl) => {
const doc = window.document;
const targetCell = annoteEl.getAttribute("data-target-cell");
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
const lineIds = lines.map((line) => {
return targetCell + "-" + line;
})
let top = null;
let height = null;
let parent = null;
if (lineIds.length > 0) {
//compute the position of the single el (top and bottom and make a div)
const el = window.document.getElementById(lineIds[0]);
top = el.offsetTop;
height = el.offsetHeight;
parent = el.parentElement.parentElement;
if (lineIds.length > 1) {
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
height = bottom - top;
}
if (top !== null && height !== null && parent !== null) {
// cook up a div (if necessary) and position it
let div = window.document.getElementById("code-annotation-line-highlight");
if (div === null) {
div = window.document.createElement("div");
div.setAttribute("id", "code-annotation-line-highlight");
div.style.position = 'absolute';
parent.appendChild(div);
}
div.style.top = top - 2 + "px";
div.style.height = height + 4 + "px";
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
if (gutterDiv === null) {
gutterDiv = window.document.createElement("div");
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
gutterDiv.style.position = 'absolute';
const codeCell = window.document.getElementById(targetCell);
const gutter = codeCell.querySelector('.code-annotation-gutter');
gutter.appendChild(gutterDiv);
}
gutterDiv.style.top = top - 2 + "px";
gutterDiv.style.height = height + 4 + "px";
}
selectedAnnoteEl = annoteEl;
}
};
const unselectCodeLines = () => {
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
elementsIds.forEach((elId) => {
const div = window.document.getElementById(elId);
if (div) {
div.remove();
}
});
selectedAnnoteEl = undefined;
};
// Attach click handler to the DT
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
for (const annoteDlNode of annoteDls) {
annoteDlNode.addEventListener('click', (event) => {
const clickedEl = event.target;
if (clickedEl !== selectedAnnoteEl) {
unselectCodeLines();
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
if (activeEl) {
activeEl.classList.remove('code-annotation-active');
}
selectCodeLines(clickedEl);
clickedEl.classList.add('code-annotation-active');
} else {
// Unselect the line
unselectCodeLines();
clickedEl.classList.remove('code-annotation-active');
}
});
}
const findCites = (el) => {
const parentEl = el.parentElement;
if (parentEl) {
const cites = parentEl.dataset.cites;
if (cites) {
return {
el,
cites: cites.split(' ')
};
} else {
return findCites(el.parentElement)
}
} else {
return undefined;
}
};
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const citeInfo = findCites(ref);
if (citeInfo) {
tippyHover(citeInfo.el, function() {
var popup = window.document.createElement('div');
citeInfo.cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');
var biblioDiv = window.document.getElementById('ref-' + cite);
if (biblioDiv) {
citeDiv.innerHTML = biblioDiv.innerHTML;
}
popup.appendChild(citeDiv);
});
return popup.innerHTML;
});
}
}
});
</script>
</div> <!-- /content -->
</body></html>

View file

@ -0,0 +1,769 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.3.450">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="author" content="Kyle Belanger">
<meta name="dcterms.date" content="2021-02-26">
<title>Kyle Belanger - TidyTuesday 2021 Week 6: HBCU Enrollment</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}
/* CSS for syntax highlighting */
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
}
pre.numberSource { margin-left: 3em; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
</style>
<script src="../../site_libs/quarto-nav/quarto-nav.js"></script>
<script src="../../site_libs/quarto-nav/headroom.min.js"></script>
<script src="../../site_libs/clipboard/clipboard.min.js"></script>
<script src="../../site_libs/quarto-search/autocomplete.umd.js"></script>
<script src="../../site_libs/quarto-search/fuse.min.js"></script>
<script src="../../site_libs/quarto-search/quarto-search.js"></script>
<meta name="quarto:offset" content="../../">
<script src="../../site_libs/quarto-html/quarto.js"></script>
<script src="../../site_libs/quarto-html/popper.min.js"></script>
<script src="../../site_libs/quarto-html/tippy.umd.min.js"></script>
<script src="../../site_libs/quarto-html/anchor.min.js"></script>
<link href="../../site_libs/quarto-html/tippy.css" rel="stylesheet">
<link href="../../site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="../../site_libs/bootstrap/bootstrap.min.js"></script>
<link href="../../site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="../../site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
<script id="quarto-search-options" type="application/json">{
"location": "navbar",
"copy-button": false,
"collapse-after": 3,
"panel-placement": "end",
"type": "overlay",
"limit": 20,
"language": {
"search-no-results-text": "No results",
"search-matching-documents-text": "matching documents",
"search-copy-link-title": "Copy link to search",
"search-hide-matches-text": "Hide additional matches",
"search-more-match-text": "more match in this document",
"search-more-matches-text": "more matches in this document",
"search-clear-button-title": "Clear",
"search-detached-cancel-button-title": "Cancel",
"search-submit-button-title": "Submit",
"search-label": "Search"
}
}</script>
<link rel="stylesheet" href="../../styles.css">
</head>
<body class="floating nav-fixed">
<div id="quarto-search-results"></div>
<header id="quarto-header" class="headroom fixed-top">
<nav class="navbar navbar-expand-lg navbar-dark ">
<div class="navbar-container container-fluid">
<div class="navbar-brand-container">
<a class="navbar-brand" href="../../index.html">
<span class="navbar-title">Kyle Belanger</span>
</a>
</div>
<div id="quarto-search" class="" title="Search"></div>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav navbar-nav-scroll ms-auto">
<li class="nav-item">
<a class="nav-link" href="../../blog.html" rel="" target="">
<span class="menu-text">Posts</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="../../kyle_resume.pdf" rel="" target="">
<span class="menu-text">Resume</span></a>
</li>
<li class="nav-item compact">
<a class="nav-link" href="https://github.com/mmmmtoasty19" rel="" target=""><i class="bi bi-github" role="img">
</i>
<span class="menu-text"></span></a>
</li>
</ul>
<div class="quarto-navbar-tools">
</div>
</div> <!-- /navcollapse -->
</div> <!-- /container-fluid -->
</nav>
</header>
<!-- content -->
<header id="title-block-header" class="quarto-title-block default toc-left page-columns page-full">
<div class="quarto-title-banner page-columns page-full">
<div class="quarto-title column-body">
<h1 class="title">TidyTuesday 2021 Week 6: HBCU Enrollment</h1>
<p class="subtitle lead"></p><p>TidyTuesday 2021 Week 6: HBCU Enrollment. Posts looks at tidying the data ,as well as making some graphs about the data.</p><p></p>
<div class="quarto-categories">
<div class="quarto-category">TidyTuesday</div>
</div>
</div>
</div>
<div class="quarto-title-meta">
<div>
<div class="quarto-title-meta-heading">Author</div>
<div class="quarto-title-meta-contents">
<p><a href="https://kyleb.rbind.io/">Kyle Belanger</a> </p>
</div>
</div>
<div>
<div class="quarto-title-meta-heading">Published</div>
<div class="quarto-title-meta-contents">
<p class="date">February 26, 2021</p>
</div>
</div>
</div>
</header><div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article page-navbar">
<!-- sidebar -->
<nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal sidebar-navigation floating overflow-auto">
<nav id="TOC" role="doc-toc" class="toc-active">
<h2 id="toc-title">Table of contents</h2>
<ul>
<li><a href="#introduction" id="toc-introduction" class="nav-link active" data-scroll-target="#introduction">Introduction</a></li>
<li><a href="#load-data" id="toc-load-data" class="nav-link" data-scroll-target="#load-data">Load Data</a></li>
<li><a href="#load-malefemale-data" id="toc-load-malefemale-data" class="nav-link" data-scroll-target="#load-malefemale-data">Load Male/Female Data</a></li>
<li><a href="#conclusion" id="toc-conclusion" class="nav-link" data-scroll-target="#conclusion">Conclusion</a></li>
</ul>
</nav>
</nav>
<div id="quarto-sidebar-glass" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass"></div>
<!-- margin-sidebar -->
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
</div>
<!-- main -->
<main class="content quarto-banner-title-block" id="quarto-document-content">
<section id="introduction" class="level1">
<h1>Introduction</h1>
<p>Recently I was struggling to find a data project to work on, I felt a bit stuck with some of my current projects, so I begun to scour the internet to find something to work on. I stumbled upon (TidyTuesday)[https://github.com/rfordatascience/tidytuesday] a weekly project where untidy data is posted from various sources, for the goal of practicing cleaning and visualizing. There is not right or wrong answers for TidyTuesday, this was exactly what I was looking for! This week (well by the time this was posted, a few weeks ago) the data set was about Historically Black Colleges and Universities. Within the posted data there were a few different data sets, I chose to work with the set dealing with High school Graduation rates, throughout this post I will explain my steps for cleaning and then present a few different graphs. It should also be noted that in the first section my code blocks will build upon themselves, so the same code will be duplicated as I add more steps to it.</p>
</section>
<section id="load-data" class="level1">
<h1>Load Data</h1>
<p>In this first block we will load some required libraries as well as load in the raw data. This dataset contains data for Highschool graduation rates by race. One thing to point out here is the use of <code>import::from()</code>, will its use here is a bit overkill, it was more for my practice. In this case I am importing the function <code>%nin</code> from the <em>Hmisc</em> package, which in the opposite of the function <code>%in%</code> from base R.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(dplyr)</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(ggplot2)</span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a>import<span class="sc">::</span><span class="fu">from</span>(Hmisc, <span class="st">`</span><span class="at">%nin%</span><span class="st">`</span>)</span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a>hs_students_raw <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_xlsx</span>(<span class="st">"104.10.xlsx"</span>, <span class="at">sheet =</span> <span class="dv">1</span>)</span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a><span class="fu">glimpse</span>(hs_students_raw)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 48
Columns: 19
$ Total &lt;dbl&gt; 1910…
$ `Total, percent of all persons age 25 and over` &lt;dbl&gt; 13.5…
$ `Standard Errors - Total, percent of all persons age 25 and over` &lt;chr&gt; "(—)…
$ White1 &lt;chr&gt; "—",…
$ `Standard Errors - White1` &lt;chr&gt; "(†)…
$ Black1 &lt;chr&gt; "—",…
$ `Standard Errors - Black1` &lt;chr&gt; "(†)…
$ Hispanic &lt;chr&gt; "—",…
$ `Standard Errors - Hispanic` &lt;chr&gt; "(†)…
$ `Total - Asian/Pacific Islander` &lt;chr&gt; "—",…
$ `Standard Errors - Total - Asian/Pacific Islander` &lt;chr&gt; "(†)…
$ `Asian/Pacific Islander - Asian` &lt;chr&gt; "—",…
$ `Standard Errors - Asian/Pacific Islander - Asian` &lt;chr&gt; "(†)…
$ `Asian/Pacific Islander - Pacific Islander` &lt;chr&gt; "—",…
$ `Standard Errors - Asian/Pacific Islander - Pacific Islander` &lt;chr&gt; "(†)…
$ `American Indian/\r\nAlaska Native` &lt;chr&gt; "—",…
$ `Standard Errors - American Indian/\r\nAlaska Native` &lt;chr&gt; "(†)…
$ `Two or more race` &lt;chr&gt; "—",…
$ `Standard Errors - Two or more race` &lt;chr&gt; "(†)…</code></pre>
</div>
</div>
<p>Now we are going to start cleaning the data. First I am going to filter for years 1985 and up, prior to this year the data set is a bit spardic, so to keep it clean I am only going to look at 1985 and up. There are also 3 odd years (19103,19203,19303) that I am not sure what those are so I will remove that data as well.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>hs_students <span class="ot">&lt;-</span> hs_students_raw <span class="sc">%&gt;%</span> </span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Total <span class="sc">&gt;=</span> <span class="dv">1985</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Total <span class="sc">%nin%</span> <span class="fu">c</span>(<span class="dv">19103</span>, <span class="dv">19203</span>, <span class="dv">19303</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Next I am going to convert all columns to be numeric, because of some blanks in the original import all of the columns read in as characters instead of numeric.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>hs_students <span class="ot">&lt;-</span> hs_students_raw <span class="sc">%&gt;%</span> </span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Total <span class="sc">&gt;=</span> <span class="dv">1985</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Total <span class="sc">%nin%</span> <span class="fu">c</span>(<span class="dv">19103</span>, <span class="dv">19203</span>, <span class="dv">19303</span>)) <span class="sc">%&gt;%</span> </span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="fu">across</span>(<span class="fu">everything</span>(), as.numeric))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Next I am going to rename the columns. First I rename the column Total, into year, as this column holds the year! Then I use <code>stringr::str_remove_all</code> to remove the long phrase percent of all persons age 25 and over, as well as the number 1. For some reason the Black and White columns each have a number 1 at the end, I think this is for some sort of footnote but we will just remove it.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>hs_students <span class="ot">&lt;-</span> hs_students_raw <span class="sc">%&gt;%</span> </span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Total <span class="sc">&gt;=</span> <span class="dv">1985</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Total <span class="sc">%nin%</span> <span class="fu">c</span>(<span class="dv">19103</span>, <span class="dv">19203</span>, <span class="dv">19303</span>)) <span class="sc">%&gt;%</span> </span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="fu">across</span>(<span class="fu">everything</span>(), as.numeric)) <span class="sc">%&gt;%</span> </span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">rename</span>(<span class="at">year =</span> Total) <span class="sc">%&gt;%</span> </span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">rename_with</span>(</span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a> <span class="sc">~</span>stringr<span class="sc">::</span><span class="fu">str_remove_all</span>(</span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a> .</span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a> ,<span class="st">", percent of all persons age 25 and over|1"</span></span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a> )</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Then I am going to drop the column Total - Asian/Pacific Islander, each of these races is stored in a seperate column so if I needed the total later for some reason I could calculate it. I am also going to drop the string “Asian/Pacific Islander -”, from the begin of each of those columns, so they will now tell me just which race each column refers too.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>hs_students <span class="ot">&lt;-</span> hs_students_raw <span class="sc">%&gt;%</span> </span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Total <span class="sc">&gt;=</span> <span class="dv">1985</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Total <span class="sc">%nin%</span> <span class="fu">c</span>(<span class="dv">19103</span>, <span class="dv">19203</span>, <span class="dv">19303</span>)) <span class="sc">%&gt;%</span> </span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="fu">across</span>(<span class="fu">everything</span>(), as.numeric)) <span class="sc">%&gt;%</span> </span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">rename</span>(<span class="at">year =</span> Total) <span class="sc">%&gt;%</span> </span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">rename_with</span>(</span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a> <span class="sc">~</span>stringr<span class="sc">::</span><span class="fu">str_remove_all</span>(</span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a> .</span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a> ,<span class="st">", percent of all persons age 25 and over|1"</span></span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">%&gt;%</span> </span>
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(<span class="sc">-</span><span class="fu">contains</span>(<span class="st">"Total - Asian/Pacific Islander"</span>)) <span class="sc">%&gt;%</span> </span>
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true" tabindex="-1"></a> <span class="fu">rename_with</span>(</span>
<span id="cb6-14"><a href="#cb6-14" aria-hidden="true" tabindex="-1"></a> <span class="sc">~</span>stringr<span class="sc">::</span><span class="fu">str_remove_all</span>(</span>
<span id="cb6-15"><a href="#cb6-15" aria-hidden="true" tabindex="-1"></a> .</span>
<span id="cb6-16"><a href="#cb6-16" aria-hidden="true" tabindex="-1"></a> ,<span class="st">"Asian/Pacific Islander - "</span></span>
<span id="cb6-17"><a href="#cb6-17" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb6-18"><a href="#cb6-18" aria-hidden="true" tabindex="-1"></a> )</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>I now simply pivot the data longer. A nice trick I learned since I want to pivot everything expect the year column is to use the minus sign to select every column expect the year column in the pivot.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>hs_students_long <span class="ot">&lt;-</span> hs_students <span class="sc">%&gt;%</span> </span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> tidyr<span class="sc">::</span><span class="fu">pivot_longer</span>(<span class="sc">-</span>year)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>With the data now in long form I am going to separate the automatically generate name column into two columns titled, stat and race. The data contains both the percent that graduated and the standard error. Then I replace all the NAs in the stat column with Total, as these are the total percentage and the other rows will be the standard error. Last I dropped the s from standard errors to make it singular.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>hs_students_long <span class="ot">&lt;-</span> hs_students <span class="sc">%&gt;%</span> </span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> tidyr<span class="sc">::</span><span class="fu">pivot_longer</span>(<span class="sc">-</span>year) <span class="sc">%&gt;%</span> </span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a> tidyr<span class="sc">::</span><span class="fu">separate</span>(name, <span class="fu">c</span>(<span class="st">"stat"</span>, <span class="st">"race"</span>), <span class="at">sep =</span> <span class="st">"- "</span>, <span class="at">fill =</span> <span class="st">"left"</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a> tidyr<span class="sc">::</span><span class="fu">replace_na</span>(<span class="fu">list</span>(<span class="at">stat =</span> <span class="st">"Total"</span>)) <span class="sc">%&gt;%</span> </span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(</span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">across</span>(</span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a> stat</span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a> ,<span class="sc">~</span>stringr<span class="sc">::</span><span class="fu">str_replace</span>(</span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true" tabindex="-1"></a> .</span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true" tabindex="-1"></a> ,<span class="st">"Standard Errors"</span></span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true" tabindex="-1"></a> ,<span class="st">"Standard Error"</span></span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb8-13"><a href="#cb8-13" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb8-14"><a href="#cb8-14" aria-hidden="true" tabindex="-1"></a> )</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>I know pivot the date back to wide form, and use the <em>Janitor</em> package to clean the column names. This puts them in lowercase with _ for spaces.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>hs_students_wide <span class="ot">&lt;-</span> hs_students_long <span class="sc">%&gt;%</span> </span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a> tidyr<span class="sc">::</span><span class="fu">pivot_wider</span>(<span class="at">names_from =</span> stat, <span class="at">values_from =</span> value) <span class="sc">%&gt;%</span> </span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a> janitor<span class="sc">::</span><span class="fu">clean_names</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>To make graphing a bit easier with the <em>scales</em> package, I divide both columns by 100. We will see why in the graphs.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>hs_students_wide <span class="ot">&lt;-</span> hs_students_long <span class="sc">%&gt;%</span> </span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a> tidyr<span class="sc">::</span><span class="fu">pivot_wider</span>(<span class="at">names_from =</span> stat, <span class="at">values_from =</span> value) <span class="sc">%&gt;%</span> </span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a> janitor<span class="sc">::</span><span class="fu">clean_names</span>() <span class="sc">%&gt;%</span> </span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="fu">across</span>(total<span class="sc">:</span>standard_error, <span class="sc">~</span>.x<span class="sc">/</span><span class="dv">100</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Its now time to graph. Notice the use <code>scales::label_percent()</code> as the labels value for the y axis. If the numbers were left as the default values (75 vs 0.75) the percentages would have been 750%, which is obviously very wrong! I also use geom_ribbon to draw the standard error bars around each line. Notice the use of color = NA, by default the ribbon has outlines, I did not like this so doing color = NA turns them off. (It should be noted there are a few other solutions to turning them off but this seemed the easiest to me). Last we see the use of the aesthetics argument in scale_color_brewer. By setting this we match the color and fill to be the same color, without setting this, the colors of the error bars and lines dont match!</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>hs_students_wide <span class="ot">&lt;-</span> hs_students_wide <span class="sc">%&gt;%</span> </span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(</span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a> <span class="at">ymax =</span> total <span class="sc">-</span> standard_error</span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a> ,<span class="at">ymin =</span> total <span class="sc">+</span> standard_error</span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a>g1 <span class="ot">&lt;-</span> hs_students_wide <span class="sc">%&gt;%</span> </span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(race <span class="sc">!=</span> <span class="st">"Total"</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x =</span> year, <span class="at">y =</span> total, <span class="at">group =</span> race, <span class="at">color =</span> race)) <span class="sc">+</span></span>
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_ribbon</span>(<span class="fu">aes</span>(<span class="at">ymax =</span> ymax, <span class="at">ymin =</span> ymin, <span class="at">fill =</span> race), <span class="at">alpha =</span> <span class="fl">0.3</span>, <span class="at">color =</span> <span class="cn">NA</span>) <span class="sc">+</span></span>
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_line</span>() <span class="sc">+</span></span>
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_x_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">1985</span>,<span class="dv">2016</span>,<span class="dv">3</span>)) <span class="sc">+</span></span>
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_y_continuous</span>(<span class="at">labels =</span> scales<span class="sc">::</span><span class="fu">label_percent</span>()) <span class="sc">+</span></span>
<span id="cb11-14"><a href="#cb11-14" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_color_brewer</span>(<span class="at">palette =</span> <span class="st">"Dark2"</span>, <span class="at">aesthetics =</span> <span class="fu">c</span>(<span class="st">"color"</span>, <span class="st">"fill"</span>)) <span class="sc">+</span></span>
<span id="cb11-15"><a href="#cb11-15" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_bw</span>() <span class="sc">+</span></span>
<span id="cb11-16"><a href="#cb11-16" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(</span>
<span id="cb11-17"><a href="#cb11-17" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> <span class="cn">NULL</span></span>
<span id="cb11-18"><a href="#cb11-18" aria-hidden="true" tabindex="-1"></a> ,<span class="at">y =</span> <span class="cn">NULL</span></span>
<span id="cb11-19"><a href="#cb11-19" aria-hidden="true" tabindex="-1"></a> ,<span class="at">title =</span> glue<span class="sc">::</span><span class="fu">glue</span>(<span class="st">"Percentage of High School Graduates by Race"</span></span>
<span id="cb11-20"><a href="#cb11-20" aria-hidden="true" tabindex="-1"></a> ,<span class="st">"</span><span class="sc">\n</span><span class="st">"</span></span>
<span id="cb11-21"><a href="#cb11-21" aria-hidden="true" tabindex="-1"></a> ,<span class="st">"1985 - 2016"</span>)</span>
<span id="cb11-22"><a href="#cb11-22" aria-hidden="true" tabindex="-1"></a> ,<span class="at">color =</span> <span class="st">"Race"</span> </span>
<span id="cb11-23"><a href="#cb11-23" aria-hidden="true" tabindex="-1"></a> ,<span class="at">fill =</span> <span class="st">"Race"</span></span>
<span id="cb11-24"><a href="#cb11-24" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">+</span></span>
<span id="cb11-25"><a href="#cb11-25" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(</span>
<span id="cb11-26"><a href="#cb11-26" aria-hidden="true" tabindex="-1"></a> <span class="at">plot.title =</span> <span class="fu">element_text</span>(<span class="at">hjust =</span> <span class="fl">0.5</span>)</span>
<span id="cb11-27"><a href="#cb11-27" aria-hidden="true" tabindex="-1"></a> ,<span class="at">legend.title =</span> <span class="fu">element_text</span>(<span class="at">hjust =</span> <span class="fl">0.5</span>)</span>
<span id="cb11-28"><a href="#cb11-28" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb11-29"><a href="#cb11-29" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb11-30"><a href="#cb11-30" aria-hidden="true" tabindex="-1"></a>g1</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="tidytuesday-2021-week-6-hbcu-enrolment_files/figure-html/unnamed-chunk-10-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="load-malefemale-data" class="level1">
<h1>Load Male/Female Data</h1>
<p>Now the file also contains the same information but split by male and female. I am going to load in that data.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a>male_hs_raw <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"104.10.xlsx"</span>, <span class="at">sheet =</span> <span class="dv">3</span>)</span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a>female_hs_raw <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"104.10.xlsx"</span>, <span class="at">sheet =</span> <span class="dv">5</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Here I will use the same manipulations as above, the only addition is adding a column for sex.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>male_hs <span class="ot">&lt;-</span> male_hs_raw <span class="sc">%&gt;%</span> </span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Total <span class="sc">&gt;=</span> <span class="dv">1985</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Total <span class="sc">%nin%</span> <span class="fu">c</span>(<span class="dv">19103</span>, <span class="dv">19203</span>, <span class="dv">19303</span>)) <span class="sc">%&gt;%</span> </span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="fu">across</span>(<span class="fu">everything</span>(), as.numeric)) <span class="sc">%&gt;%</span> </span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">rename</span>(<span class="at">year =</span> Total) <span class="sc">%&gt;%</span> </span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">rename_with</span>(</span>
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true" tabindex="-1"></a> <span class="sc">~</span>stringr<span class="sc">::</span><span class="fu">str_remove_all</span>(</span>
<span id="cb13-8"><a href="#cb13-8" aria-hidden="true" tabindex="-1"></a> .</span>
<span id="cb13-9"><a href="#cb13-9" aria-hidden="true" tabindex="-1"></a> ,<span class="st">", percent of all persons age 25 and over|1"</span></span>
<span id="cb13-10"><a href="#cb13-10" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb13-11"><a href="#cb13-11" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">%&gt;%</span> </span>
<span id="cb13-12"><a href="#cb13-12" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(<span class="sc">-</span><span class="fu">contains</span>(<span class="st">"Total - Asian/Pacific Islander"</span>)) <span class="sc">%&gt;%</span> </span>
<span id="cb13-13"><a href="#cb13-13" aria-hidden="true" tabindex="-1"></a> <span class="fu">rename_with</span>(</span>
<span id="cb13-14"><a href="#cb13-14" aria-hidden="true" tabindex="-1"></a> <span class="sc">~</span>stringr<span class="sc">::</span><span class="fu">str_remove_all</span>(</span>
<span id="cb13-15"><a href="#cb13-15" aria-hidden="true" tabindex="-1"></a> .</span>
<span id="cb13-16"><a href="#cb13-16" aria-hidden="true" tabindex="-1"></a> ,<span class="st">"Asian/Pacific Islander - "</span></span>
<span id="cb13-17"><a href="#cb13-17" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb13-18"><a href="#cb13-18" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">%&gt;%</span> </span>
<span id="cb13-19"><a href="#cb13-19" aria-hidden="true" tabindex="-1"></a> tidyr<span class="sc">::</span><span class="fu">pivot_longer</span>(<span class="sc">-</span>year) <span class="sc">%&gt;%</span> </span>
<span id="cb13-20"><a href="#cb13-20" aria-hidden="true" tabindex="-1"></a> tidyr<span class="sc">::</span><span class="fu">separate</span>(name, <span class="fu">c</span>(<span class="st">"stat"</span>, <span class="st">"race"</span>), <span class="at">sep =</span> <span class="st">"- "</span>, <span class="at">fill =</span> <span class="st">"left"</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb13-21"><a href="#cb13-21" aria-hidden="true" tabindex="-1"></a> tidyr<span class="sc">::</span><span class="fu">replace_na</span>(<span class="fu">list</span>(<span class="at">stat =</span> <span class="st">"Total"</span>)) <span class="sc">%&gt;%</span> </span>
<span id="cb13-22"><a href="#cb13-22" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(</span>
<span id="cb13-23"><a href="#cb13-23" aria-hidden="true" tabindex="-1"></a> <span class="fu">across</span>(</span>
<span id="cb13-24"><a href="#cb13-24" aria-hidden="true" tabindex="-1"></a> stat</span>
<span id="cb13-25"><a href="#cb13-25" aria-hidden="true" tabindex="-1"></a> ,<span class="sc">~</span>stringr<span class="sc">::</span><span class="fu">str_replace</span>(</span>
<span id="cb13-26"><a href="#cb13-26" aria-hidden="true" tabindex="-1"></a> .</span>
<span id="cb13-27"><a href="#cb13-27" aria-hidden="true" tabindex="-1"></a> ,<span class="st">"Standard Errors"</span></span>
<span id="cb13-28"><a href="#cb13-28" aria-hidden="true" tabindex="-1"></a> ,<span class="st">"Standard Error"</span></span>
<span id="cb13-29"><a href="#cb13-29" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb13-30"><a href="#cb13-30" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb13-31"><a href="#cb13-31" aria-hidden="true" tabindex="-1"></a> ,<span class="at">sex =</span> <span class="st">"Male"</span></span>
<span id="cb13-32"><a href="#cb13-32" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb13-33"><a href="#cb13-33" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-34"><a href="#cb13-34" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-35"><a href="#cb13-35" aria-hidden="true" tabindex="-1"></a>female_hs <span class="ot">&lt;-</span> female_hs_raw <span class="sc">%&gt;%</span> </span>
<span id="cb13-36"><a href="#cb13-36" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Total <span class="sc">&gt;=</span> <span class="dv">1985</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb13-37"><a href="#cb13-37" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Total <span class="sc">%nin%</span> <span class="fu">c</span>(<span class="dv">19103</span>, <span class="dv">19203</span>, <span class="dv">19303</span>)) <span class="sc">%&gt;%</span> </span>
<span id="cb13-38"><a href="#cb13-38" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="fu">across</span>(<span class="fu">everything</span>(), as.numeric)) <span class="sc">%&gt;%</span> </span>
<span id="cb13-39"><a href="#cb13-39" aria-hidden="true" tabindex="-1"></a> <span class="fu">rename</span>(<span class="at">year =</span> Total) <span class="sc">%&gt;%</span> </span>
<span id="cb13-40"><a href="#cb13-40" aria-hidden="true" tabindex="-1"></a> <span class="fu">rename_with</span>(</span>
<span id="cb13-41"><a href="#cb13-41" aria-hidden="true" tabindex="-1"></a> <span class="sc">~</span>stringr<span class="sc">::</span><span class="fu">str_remove_all</span>(</span>
<span id="cb13-42"><a href="#cb13-42" aria-hidden="true" tabindex="-1"></a> .</span>
<span id="cb13-43"><a href="#cb13-43" aria-hidden="true" tabindex="-1"></a> ,<span class="st">", percent of all persons age 25 and over|1"</span></span>
<span id="cb13-44"><a href="#cb13-44" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb13-45"><a href="#cb13-45" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">%&gt;%</span> </span>
<span id="cb13-46"><a href="#cb13-46" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(<span class="sc">-</span><span class="fu">contains</span>(<span class="st">"Total - Asian/Pacific Islander"</span>)) <span class="sc">%&gt;%</span> </span>
<span id="cb13-47"><a href="#cb13-47" aria-hidden="true" tabindex="-1"></a> <span class="fu">rename_with</span>(</span>
<span id="cb13-48"><a href="#cb13-48" aria-hidden="true" tabindex="-1"></a> <span class="sc">~</span>stringr<span class="sc">::</span><span class="fu">str_remove_all</span>(</span>
<span id="cb13-49"><a href="#cb13-49" aria-hidden="true" tabindex="-1"></a> .</span>
<span id="cb13-50"><a href="#cb13-50" aria-hidden="true" tabindex="-1"></a> ,<span class="st">"Asian/Pacific Islander - "</span></span>
<span id="cb13-51"><a href="#cb13-51" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb13-52"><a href="#cb13-52" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">%&gt;%</span> </span>
<span id="cb13-53"><a href="#cb13-53" aria-hidden="true" tabindex="-1"></a> tidyr<span class="sc">::</span><span class="fu">pivot_longer</span>(<span class="sc">-</span>year) <span class="sc">%&gt;%</span> </span>
<span id="cb13-54"><a href="#cb13-54" aria-hidden="true" tabindex="-1"></a> tidyr<span class="sc">::</span><span class="fu">separate</span>(name, <span class="fu">c</span>(<span class="st">"stat"</span>, <span class="st">"race"</span>), <span class="at">sep =</span> <span class="st">"- "</span>, <span class="at">fill =</span> <span class="st">"left"</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb13-55"><a href="#cb13-55" aria-hidden="true" tabindex="-1"></a> tidyr<span class="sc">::</span><span class="fu">replace_na</span>(<span class="fu">list</span>(<span class="at">stat =</span> <span class="st">"Total"</span>)) <span class="sc">%&gt;%</span> </span>
<span id="cb13-56"><a href="#cb13-56" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(</span>
<span id="cb13-57"><a href="#cb13-57" aria-hidden="true" tabindex="-1"></a> <span class="fu">across</span>(</span>
<span id="cb13-58"><a href="#cb13-58" aria-hidden="true" tabindex="-1"></a> stat</span>
<span id="cb13-59"><a href="#cb13-59" aria-hidden="true" tabindex="-1"></a> ,<span class="sc">~</span>stringr<span class="sc">::</span><span class="fu">str_replace</span>(</span>
<span id="cb13-60"><a href="#cb13-60" aria-hidden="true" tabindex="-1"></a> .</span>
<span id="cb13-61"><a href="#cb13-61" aria-hidden="true" tabindex="-1"></a> ,<span class="st">"Standard Errors"</span></span>
<span id="cb13-62"><a href="#cb13-62" aria-hidden="true" tabindex="-1"></a> ,<span class="st">"Standard Error"</span></span>
<span id="cb13-63"><a href="#cb13-63" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb13-64"><a href="#cb13-64" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb13-65"><a href="#cb13-65" aria-hidden="true" tabindex="-1"></a> ,<span class="at">sex =</span> <span class="st">"Female"</span></span>
<span id="cb13-66"><a href="#cb13-66" aria-hidden="true" tabindex="-1"></a> )</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Here we will combine the two data frames and then pivot to our final graphing form.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb14"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a>male_female_hs_wide <span class="ot">&lt;-</span> male_hs <span class="sc">%&gt;%</span> </span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">bind_rows</span>(female_hs) <span class="sc">%&gt;%</span> </span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a> tidyr<span class="sc">::</span><span class="fu">pivot_wider</span>(<span class="at">names_from =</span> stat, <span class="at">values_from =</span> value) <span class="sc">%&gt;%</span> </span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a> janitor<span class="sc">::</span><span class="fu">clean_names</span>() <span class="sc">%&gt;%</span> </span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="fu">across</span>(total<span class="sc">:</span>standard_error, <span class="sc">~</span>.x<span class="sc">/</span><span class="dv">100</span>)) <span class="sc">%&gt;%</span> </span>
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(</span>
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true" tabindex="-1"></a> <span class="at">ymax =</span> total <span class="sc">-</span> standard_error</span>
<span id="cb14-8"><a href="#cb14-8" aria-hidden="true" tabindex="-1"></a> ,<span class="at">ymin =</span> total <span class="sc">+</span> standard_error</span>
<span id="cb14-9"><a href="#cb14-9" aria-hidden="true" tabindex="-1"></a> )</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Lets first graph the total for Male and Female graduation rates.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a>g2 <span class="ot">&lt;-</span> male_female_hs_wide <span class="sc">%&gt;%</span> </span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(race <span class="sc">==</span> <span class="st">"Total"</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x =</span> year, <span class="at">y =</span> total, <span class="at">group =</span> sex, <span class="at">color =</span> sex)) <span class="sc">+</span></span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_ribbon</span>(<span class="fu">aes</span>(<span class="at">ymax =</span> ymax, <span class="at">ymin =</span> ymin, <span class="at">fill =</span> sex), <span class="at">alpha =</span> <span class="fl">0.3</span>, <span class="at">color =</span> <span class="cn">NA</span>) <span class="sc">+</span></span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_line</span>() <span class="sc">+</span></span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_x_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">1985</span>,<span class="dv">2016</span>,<span class="dv">3</span>)) <span class="sc">+</span></span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_y_continuous</span>(<span class="at">labels =</span> scales<span class="sc">::</span><span class="fu">label_percent</span>()) <span class="sc">+</span></span>
<span id="cb15-8"><a href="#cb15-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_color_brewer</span>(<span class="at">palette =</span> <span class="st">"Dark2"</span>, <span class="at">aesthetics =</span> <span class="fu">c</span>(<span class="st">"color"</span>, <span class="st">"fill"</span>)) <span class="sc">+</span></span>
<span id="cb15-9"><a href="#cb15-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_bw</span>() <span class="sc">+</span></span>
<span id="cb15-10"><a href="#cb15-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(</span>
<span id="cb15-11"><a href="#cb15-11" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> <span class="cn">NULL</span></span>
<span id="cb15-12"><a href="#cb15-12" aria-hidden="true" tabindex="-1"></a> ,<span class="at">y =</span> <span class="cn">NULL</span></span>
<span id="cb15-13"><a href="#cb15-13" aria-hidden="true" tabindex="-1"></a> ,<span class="at">title =</span> glue<span class="sc">::</span><span class="fu">glue</span>(<span class="st">"Percentage of High School Graduates by Sex"</span></span>
<span id="cb15-14"><a href="#cb15-14" aria-hidden="true" tabindex="-1"></a> ,<span class="st">"</span><span class="sc">\n</span><span class="st">"</span></span>
<span id="cb15-15"><a href="#cb15-15" aria-hidden="true" tabindex="-1"></a> ,<span class="st">"1985 - 2016"</span>)</span>
<span id="cb15-16"><a href="#cb15-16" aria-hidden="true" tabindex="-1"></a> ,<span class="at">color =</span> <span class="st">"Sex"</span> </span>
<span id="cb15-17"><a href="#cb15-17" aria-hidden="true" tabindex="-1"></a> ,<span class="at">fill =</span> <span class="st">"Sex"</span></span>
<span id="cb15-18"><a href="#cb15-18" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">+</span></span>
<span id="cb15-19"><a href="#cb15-19" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(</span>
<span id="cb15-20"><a href="#cb15-20" aria-hidden="true" tabindex="-1"></a> <span class="at">plot.title =</span> <span class="fu">element_text</span>(<span class="at">hjust =</span> <span class="fl">0.5</span>)</span>
<span id="cb15-21"><a href="#cb15-21" aria-hidden="true" tabindex="-1"></a> ,<span class="at">legend.title =</span> <span class="fu">element_text</span>(<span class="at">hjust =</span> <span class="fl">0.5</span>)</span>
<span id="cb15-22"><a href="#cb15-22" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb15-23"><a href="#cb15-23" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-24"><a href="#cb15-24" aria-hidden="true" tabindex="-1"></a>g2</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="tidytuesday-2021-week-6-hbcu-enrolment_files/figure-html/unnamed-chunk-14-1.png" class="img-fluid" width="672"></p>
</div>
</div>
<p>Now I am going to graph by Sex and Race.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb16"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a>race_filter <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"White"</span>, <span class="st">"Black"</span>, <span class="st">"Hispanic"</span>)</span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a>make_label <span class="ot">&lt;-</span> <span class="cf">function</span>(label){</span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true" tabindex="-1"></a> <span class="co"># browser()</span></span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true" tabindex="-1"></a> result <span class="ot">&lt;-</span> stringr<span class="sc">::</span><span class="fu">str_split</span>(label, <span class="st">"</span><span class="sc">\\</span><span class="st">."</span>)</span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">unlist</span>(<span class="fu">lapply</span>(result, <span class="cf">function</span>(x) <span class="fu">paste</span>(x[<span class="dv">2</span>],x[<span class="dv">1</span>])))</span>
<span id="cb16-7"><a href="#cb16-7" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb16-8"><a href="#cb16-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-9"><a href="#cb16-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-10"><a href="#cb16-10" aria-hidden="true" tabindex="-1"></a>g2 <span class="ot">&lt;-</span> male_female_hs_wide <span class="sc">%&gt;%</span> </span>
<span id="cb16-11"><a href="#cb16-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(race <span class="sc">%in%</span> race_filter) <span class="sc">%&gt;%</span> </span>
<span id="cb16-12"><a href="#cb16-12" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x =</span> year, <span class="at">y =</span> total, <span class="at">group =</span> <span class="fu">interaction</span>(sex,race), <span class="at">color =</span> <span class="fu">interaction</span>(sex,race))) <span class="sc">+</span></span>
<span id="cb16-13"><a href="#cb16-13" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_ribbon</span>(<span class="fu">aes</span>(<span class="at">ymax =</span> ymax, <span class="at">ymin =</span> ymin, <span class="at">fill =</span> <span class="fu">interaction</span>(sex,race)), <span class="at">alpha =</span> <span class="fl">0.3</span>, <span class="at">color =</span> <span class="cn">NA</span>) <span class="sc">+</span></span>
<span id="cb16-14"><a href="#cb16-14" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_line</span>() <span class="sc">+</span></span>
<span id="cb16-15"><a href="#cb16-15" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_x_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">1985</span>,<span class="dv">2016</span>,<span class="dv">3</span>)) <span class="sc">+</span></span>
<span id="cb16-16"><a href="#cb16-16" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_y_continuous</span>(<span class="at">labels =</span> scales<span class="sc">::</span><span class="fu">label_percent</span>()) <span class="sc">+</span></span>
<span id="cb16-17"><a href="#cb16-17" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_color_brewer</span>(<span class="at">palette =</span> <span class="st">"Dark2"</span>, <span class="at">aesthetics =</span> <span class="fu">c</span>(<span class="st">"color"</span>, <span class="st">"fill"</span>), <span class="at">labels =</span> make_label) <span class="sc">+</span></span>
<span id="cb16-18"><a href="#cb16-18" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_bw</span>() <span class="sc">+</span></span>
<span id="cb16-19"><a href="#cb16-19" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(</span>
<span id="cb16-20"><a href="#cb16-20" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> <span class="cn">NULL</span></span>
<span id="cb16-21"><a href="#cb16-21" aria-hidden="true" tabindex="-1"></a> ,<span class="at">y =</span> <span class="cn">NULL</span></span>
<span id="cb16-22"><a href="#cb16-22" aria-hidden="true" tabindex="-1"></a> ,<span class="at">title =</span> glue<span class="sc">::</span><span class="fu">glue</span>(<span class="st">"Percentage of High School Graduates by Race and Sex"</span></span>
<span id="cb16-23"><a href="#cb16-23" aria-hidden="true" tabindex="-1"></a> ,<span class="st">"</span><span class="sc">\n</span><span class="st">"</span></span>
<span id="cb16-24"><a href="#cb16-24" aria-hidden="true" tabindex="-1"></a> ,<span class="st">"1985 - 2016"</span>)</span>
<span id="cb16-25"><a href="#cb16-25" aria-hidden="true" tabindex="-1"></a> ,<span class="at">color =</span> <span class="st">"Race &amp; Sex"</span> </span>
<span id="cb16-26"><a href="#cb16-26" aria-hidden="true" tabindex="-1"></a> ,<span class="at">fill =</span> <span class="st">"Race &amp; Sex"</span></span>
<span id="cb16-27"><a href="#cb16-27" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">+</span></span>
<span id="cb16-28"><a href="#cb16-28" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(</span>
<span id="cb16-29"><a href="#cb16-29" aria-hidden="true" tabindex="-1"></a> <span class="at">plot.title =</span> <span class="fu">element_text</span>(<span class="at">hjust =</span> <span class="fl">0.5</span>)</span>
<span id="cb16-30"><a href="#cb16-30" aria-hidden="true" tabindex="-1"></a> ,<span class="at">legend.title =</span> <span class="fu">element_text</span>(<span class="at">hjust =</span> <span class="fl">0.5</span>)</span>
<span id="cb16-31"><a href="#cb16-31" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb16-32"><a href="#cb16-32" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-33"><a href="#cb16-33" aria-hidden="true" tabindex="-1"></a>g2</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="tidytuesday-2021-week-6-hbcu-enrolment_files/figure-html/unnamed-chunk-15-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="conclusion" class="level1">
<h1>Conclusion</h1>
<p>While I am sure there is much more that could be done with this data this is where I am going to stop for today. Our graphs clearly show a divide in graduation rates by race, however Sex does not seem to have much of an effect on graduation rates.</p>
</section>
<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div id="quarto-reuse" class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">https://creativecommons.org/licenses/by/4.0/</a></div></div></section><section class="quarto-appendix-contents"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{belanger2021,
author = {Belanger, Kyle},
title = {TidyTuesday 2021 {Week} 6: {HBCU} {Enrollment}},
date = {2021-02-26},
langid = {en}
}
</code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-belanger2021" class="csl-entry quarto-appendix-citeas" role="listitem">
Belanger, Kyle. 2021. <span>“TidyTuesday 2021 Week 6: HBCU
Enrollment.”</span> February 26, 2021.
</div></div></section></div></main> <!-- /main -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const isCodeAnnotation = (el) => {
for (const clz of el.classList) {
if (clz.startsWith('code-annotation-')) {
return true;
}
}
return false;
}
const clipboard = new window.ClipboardJS('.code-copy-button', {
text: function(trigger) {
const codeEl = trigger.previousElementSibling.cloneNode(true);
for (const childEl of codeEl.children) {
if (isCodeAnnotation(childEl)) {
childEl.remove();
}
}
return codeEl.innerText;
}
});
clipboard.on('success', function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
let tooltip;
if (window.bootstrap) {
button.setAttribute("data-bs-toggle", "tooltip");
button.setAttribute("data-bs-placement", "left");
button.setAttribute("data-bs-title", "Copied!");
tooltip = new bootstrap.Tooltip(button,
{ trigger: "manual",
customClass: "code-copy-button-tooltip",
offset: [0, -8]});
tooltip.show();
}
setTimeout(function() {
if (tooltip) {
tooltip.hide();
button.removeAttribute("data-bs-title");
button.removeAttribute("data-bs-toggle");
button.removeAttribute("data-bs-placement");
}
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
});
function tippyHover(el, contentFn) {
const config = {
allowHTML: true,
content: contentFn,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start'
};
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
// use id or data attribute instead here
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
return note.innerHTML;
});
}
let selectedAnnoteEl;
const selectorForAnnotation = ( cell, annotation) => {
let cellAttr = 'data-code-cell="' + cell + '"';
let lineAttr = 'data-code-annotation="' + annotation + '"';
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
return selector;
}
const selectCodeLines = (annoteEl) => {
const doc = window.document;
const targetCell = annoteEl.getAttribute("data-target-cell");
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
const lineIds = lines.map((line) => {
return targetCell + "-" + line;
})
let top = null;
let height = null;
let parent = null;
if (lineIds.length > 0) {
//compute the position of the single el (top and bottom and make a div)
const el = window.document.getElementById(lineIds[0]);
top = el.offsetTop;
height = el.offsetHeight;
parent = el.parentElement.parentElement;
if (lineIds.length > 1) {
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
height = bottom - top;
}
if (top !== null && height !== null && parent !== null) {
// cook up a div (if necessary) and position it
let div = window.document.getElementById("code-annotation-line-highlight");
if (div === null) {
div = window.document.createElement("div");
div.setAttribute("id", "code-annotation-line-highlight");
div.style.position = 'absolute';
parent.appendChild(div);
}
div.style.top = top - 2 + "px";
div.style.height = height + 4 + "px";
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
if (gutterDiv === null) {
gutterDiv = window.document.createElement("div");
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
gutterDiv.style.position = 'absolute';
const codeCell = window.document.getElementById(targetCell);
const gutter = codeCell.querySelector('.code-annotation-gutter');
gutter.appendChild(gutterDiv);
}
gutterDiv.style.top = top - 2 + "px";
gutterDiv.style.height = height + 4 + "px";
}
selectedAnnoteEl = annoteEl;
}
};
const unselectCodeLines = () => {
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
elementsIds.forEach((elId) => {
const div = window.document.getElementById(elId);
if (div) {
div.remove();
}
});
selectedAnnoteEl = undefined;
};
// Attach click handler to the DT
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
for (const annoteDlNode of annoteDls) {
annoteDlNode.addEventListener('click', (event) => {
const clickedEl = event.target;
if (clickedEl !== selectedAnnoteEl) {
unselectCodeLines();
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
if (activeEl) {
activeEl.classList.remove('code-annotation-active');
}
selectCodeLines(clickedEl);
clickedEl.classList.add('code-annotation-active');
} else {
// Unselect the line
unselectCodeLines();
clickedEl.classList.remove('code-annotation-active');
}
});
}
const findCites = (el) => {
const parentEl = el.parentElement;
if (parentEl) {
const cites = parentEl.dataset.cites;
if (cites) {
return {
el,
cites: cites.split(' ')
};
} else {
return findCites(el.parentElement)
}
} else {
return undefined;
}
};
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const citeInfo = findCites(ref);
if (citeInfo) {
tippyHover(citeInfo.el, function() {
var popup = window.document.createElement('div');
citeInfo.cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');
var biblioDiv = window.document.getElementById('ref-' + cite);
if (biblioDiv) {
citeDiv.innerHTML = biblioDiv.innerHTML;
}
popup.appendChild(citeDiv);
});
return popup.innerHTML;
});
}
}
});
</script>
</div> <!-- /content -->
</body></html>

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,63 @@
---
title: "Converting From Blogdown to Distill"
subtitle: |
A meta post on transferring from a blogdown to distill blog site
date: 01-12-2021
categories:
- Distill
---
# Authors Note
I have since converted this blog to a quarto blog, but am leaving this post up in case anyone finds it useful
# Introduction
This metapost describes changing my personal blog from a blogdown site to a distill blog site. I will not be going over starting a site from scratch as there are already several great resources for doing this. What I will be going over is some of the challenges and some of the changes and tips I have found. If you are looking to start a site from scratch, check out these great resources:
- The Distill for Rmarkdown page on creating a [blog](https://rstudio.github.io/distill/blog.html)
- This excellent post from Shamindra Shrotriya on setting up a [blog](https://www.shamindras.com/posts/2019-07-11-shrotriya2019distillpt1/)
- This post from the Mockup [blog](https://themockup.blog/posts/2020-08-01-building-a-blog-with-distill/)
This last post goes into some of the pros and cons of using distill instead of blogdown. If you want simplicity, go with distill without much customization. If you want the ability for a lot of customization and don't mind being frustrated with Hugo, go with blogdown.
# Challenges
The good thing about switching from blogdown to distill was I had very few challenges! The distill documentation, combined with the two posts I listed, helped me with most of my troubles. The only issue I ran into was distill contains a function called `import_post()`, which according to the docs, only needs a published URL to work. I could never solve why, but I could not pull in the posts from my old blogdown site. This wasn't a big deal as I had the original rmarkdown documents, but this could pose an issue if you didn't.
# Going Outside the Box
## Code Folding
When I converted my blog on 12/30/2020, code folding was not included as an option by default in distill. At that time, an excellent package called [Codefolder](https://github.com/ijlyttle/codefolder) added the functionality. Since going live with the blog, code folding has been added to distill.^[Note that as of publishing, code folding is only available in the development version of distill] Code folding is available for either the whole document or individual code sections. The default caption is "Show Code", but instead of typing `code_folding=TRUE`, you can provide a string to change the caption.
```{r, code_folding="Lets See It",echo=TRUE}
# Some awesome code
# That does awesome things
```
## Customizing the Home Page
By default, a distill blog's home page will be the blog index page. I chose to edit my home page to be a landing page for myself and then have the blog index as a separate page. When creating a new blog, this is the default YAML header for your index page.
```{.yaml}
---
title: "New Site"
site: distill::distill_website
listing: posts
---
```
The critical piece here is the line `site: distill::distill_website`. This line is what is needed to render the website. For my home page, I decided to use the package [Postcard](https://github.com/seankross/postcards), which is used to generate simple landing pages. I won't go into every step as there is already a great post by [Alison Hill](https://alison.rbind.io/post/2020-12-22-postcards-distill/) on how to do that. However, I will point out the most crucial part of the new index page the YAML header needs to contain these two lines.
```{.yaml}
output:
postcards::trestles
site: distill::distill_website
```
# Final Thoughts
I have enjoyed the simplicity of Distill. While not nearly as customizable as blogdown, getting a blog site up and running in under an hour is pretty lovely. I hope to keep exploring what Distill has to offer and keep posting my updates!

View file

@ -0,0 +1,362 @@
---
title: "TidyTuesday 2021 Week 6: HBCU Enrollment"
subtitle: |
TidyTuesday 2021 Week 6: HBCU Enrollment. Posts looks at tidying the data
,as well as making some graphs about the data.
date: 02-26-2021
categories:
- TidyTuesday
---
# Introduction
Recently I was struggling to find a data project to work on, I felt a bit stuck with some of my current projects, so I begun to scour the internet to find something to work on. I stumbled upon (TidyTuesday)[https://github.com/rfordatascience/tidytuesday] a weekly project where untidy data is posted from various sources, for the goal of practicing cleaning and visualizing. There is not right or wrong answers for TidyTuesday, this was exactly what I was looking for! This week (well by the time this was posted, a few weeks ago) the data set was about Historically Black Colleges and Universities. Within the posted data there were a few different data sets, I chose to work with the set dealing with High school Graduation rates, throughout this post I will explain my steps for cleaning and then present a few different graphs. It should also be noted that in the first section my code blocks will build upon themselves, so the same code will be duplicated as I add more steps to it.
# Load Data
In this first block we will load some required libraries as well as load in the raw data. This dataset contains data for Highschool graduation rates by race. One thing to point out here is the use of `import::from()`, will its use here is a bit overkill, it was more for my practice. In this case I am importing the function `%nin` from the *Hmisc* package, which in the opposite of the function `%in%` from base R.
```{r}
library(dplyr)
library(ggplot2)
import::from(Hmisc, `%nin%`)
hs_students_raw <- readxl::read_xlsx("104.10.xlsx", sheet = 1)
glimpse(hs_students_raw)
```
Now we are going to start cleaning the data. First I am going to filter for years 1985 and up, prior to this year the data set is a bit spardic, so to keep it clean I am only going to look at 1985 and up. There are also 3 odd years (19103,19203,19303) that I am not sure what those are so I will remove that data as well.
```{r}
hs_students <- hs_students_raw %>%
filter(Total >= 1985) %>%
filter(Total %nin% c(19103, 19203, 19303))
```
Next I am going to convert all columns to be numeric, because of some blanks in the original import all of the columns read in as characters instead of numeric.
```{r}
hs_students <- hs_students_raw %>%
filter(Total >= 1985) %>%
filter(Total %nin% c(19103, 19203, 19303)) %>%
mutate(across(everything(), as.numeric))
```
Next I am going to rename the columns. First I rename the column Total, into year, as this column holds the year! Then I use `stringr::str_remove_all` to remove the long phrase 'percent of all persons age 25 and over', as well as the number 1. For some reason the Black and White columns each have a number 1 at the end, I think this is for some sort of footnote but we will just remove it.
```{r}
hs_students <- hs_students_raw %>%
filter(Total >= 1985) %>%
filter(Total %nin% c(19103, 19203, 19303)) %>%
mutate(across(everything(), as.numeric)) %>%
rename(year = Total) %>%
rename_with(
~stringr::str_remove_all(
.
,", percent of all persons age 25 and over|1"
)
)
```
Then I am going to drop the column 'Total - Asian/Pacific Islander', each of these races is stored in a seperate column so if I needed the total later for some reason I could calculate it. I am also going to drop the string "Asian/Pacific Islander - ", from the begin of each of those columns, so they will now tell me just which race each column refers too.
```{r}
hs_students <- hs_students_raw %>%
filter(Total >= 1985) %>%
filter(Total %nin% c(19103, 19203, 19303)) %>%
mutate(across(everything(), as.numeric)) %>%
rename(year = Total) %>%
rename_with(
~stringr::str_remove_all(
.
,", percent of all persons age 25 and over|1"
)
) %>%
select(-contains("Total - Asian/Pacific Islander")) %>%
rename_with(
~stringr::str_remove_all(
.
,"Asian/Pacific Islander - "
)
)
```
I now simply pivot the data longer. A nice trick I learned since I want to pivot everything expect the year column is to use the minus sign to select every column expect the year column in the pivot.
```{r}
hs_students_long <- hs_students %>%
tidyr::pivot_longer(-year)
```
With the data now in long form I am going to separate the automatically generate name column into two columns titled, stat and race. The data contains both the percent that graduated and the standard error. Then I replace all the NA's in the stat column with Total, as these are the total percentage and the other rows will be the standard error. Last I dropped the s from standard errors to make it singular.
```{r}
hs_students_long <- hs_students %>%
tidyr::pivot_longer(-year) %>%
tidyr::separate(name, c("stat", "race"), sep = "- ", fill = "left") %>%
tidyr::replace_na(list(stat = "Total")) %>%
mutate(
across(
stat
,~stringr::str_replace(
.
,"Standard Errors"
,"Standard Error"
)
)
)
```
I know pivot the date back to wide form, and use the *Janitor* package to clean the column names. This puts them in lowercase with _ for spaces.
```{r}
hs_students_wide <- hs_students_long %>%
tidyr::pivot_wider(names_from = stat, values_from = value) %>%
janitor::clean_names()
```
To make graphing a bit easier with the *scales* package, I divide both columns by 100. We will see why in the graphs.
```{r}
hs_students_wide <- hs_students_long %>%
tidyr::pivot_wider(names_from = stat, values_from = value) %>%
janitor::clean_names() %>%
mutate(across(total:standard_error, ~.x/100))
```
It's now time to graph. Notice the use `scales::label_percent()` as the labels value for the y axis. If the numbers were left as the default values (75 vs 0.75) the percentages would have been 750%, which is obviously very wrong! I also use geom_ribbon to draw the standard error bars around each line. Notice the use of color = NA, by default the ribbon has outlines, I did not like this so doing color = NA turns them off. (It should be noted there are a few other solutions to turning them off but this seemed the easiest to me). Last we see the use of the aesthetics argument in scale_color_brewer. By setting this we match the color and fill to be the same color, without setting this, the colors of the error bars and lines don't match!
```{r}
hs_students_wide <- hs_students_wide %>%
mutate(
ymax = total - standard_error
,ymin = total + standard_error
)
g1 <- hs_students_wide %>%
filter(race != "Total") %>%
ggplot(aes(x = year, y = total, group = race, color = race)) +
geom_ribbon(aes(ymax = ymax, ymin = ymin, fill = race), alpha = 0.3, color = NA) +
geom_line() +
scale_x_continuous(breaks = seq(1985,2016,3)) +
scale_y_continuous(labels = scales::label_percent()) +
scale_color_brewer(palette = "Dark2", aesthetics = c("color", "fill")) +
theme_bw() +
labs(
x = NULL
,y = NULL
,title = glue::glue("Percentage of High School Graduates by Race"
,"\n"
,"1985 - 2016")
,color = "Race"
,fill = "Race"
) +
theme(
plot.title = element_text(hjust = 0.5)
,legend.title = element_text(hjust = 0.5)
)
g1
```
# Load Male/Female Data
Now the file also contains the same information but split by male and female. I am going to load in that data.
```{r}
male_hs_raw <- readxl::read_excel("104.10.xlsx", sheet = 3)
female_hs_raw <- readxl::read_excel("104.10.xlsx", sheet = 5)
```
Here I will use the same manipulations as above, the only addition is adding a column for sex.
```{r}
male_hs <- male_hs_raw %>%
filter(Total >= 1985) %>%
filter(Total %nin% c(19103, 19203, 19303)) %>%
mutate(across(everything(), as.numeric)) %>%
rename(year = Total) %>%
rename_with(
~stringr::str_remove_all(
.
,", percent of all persons age 25 and over|1"
)
) %>%
select(-contains("Total - Asian/Pacific Islander")) %>%
rename_with(
~stringr::str_remove_all(
.
,"Asian/Pacific Islander - "
)
) %>%
tidyr::pivot_longer(-year) %>%
tidyr::separate(name, c("stat", "race"), sep = "- ", fill = "left") %>%
tidyr::replace_na(list(stat = "Total")) %>%
mutate(
across(
stat
,~stringr::str_replace(
.
,"Standard Errors"
,"Standard Error"
)
)
,sex = "Male"
)
female_hs <- female_hs_raw %>%
filter(Total >= 1985) %>%
filter(Total %nin% c(19103, 19203, 19303)) %>%
mutate(across(everything(), as.numeric)) %>%
rename(year = Total) %>%
rename_with(
~stringr::str_remove_all(
.
,", percent of all persons age 25 and over|1"
)
) %>%
select(-contains("Total - Asian/Pacific Islander")) %>%
rename_with(
~stringr::str_remove_all(
.
,"Asian/Pacific Islander - "
)
) %>%
tidyr::pivot_longer(-year) %>%
tidyr::separate(name, c("stat", "race"), sep = "- ", fill = "left") %>%
tidyr::replace_na(list(stat = "Total")) %>%
mutate(
across(
stat
,~stringr::str_replace(
.
,"Standard Errors"
,"Standard Error"
)
)
,sex = "Female"
)
```
Here we will combine the two data frames and then pivot to our final graphing form.
```{r}
male_female_hs_wide <- male_hs %>%
bind_rows(female_hs) %>%
tidyr::pivot_wider(names_from = stat, values_from = value) %>%
janitor::clean_names() %>%
mutate(across(total:standard_error, ~.x/100)) %>%
mutate(
ymax = total - standard_error
,ymin = total + standard_error
)
```
Lets first graph the total for Male and Female graduation rates.
```{r}
g2 <- male_female_hs_wide %>%
filter(race == "Total") %>%
ggplot(aes(x = year, y = total, group = sex, color = sex)) +
geom_ribbon(aes(ymax = ymax, ymin = ymin, fill = sex), alpha = 0.3, color = NA) +
geom_line() +
scale_x_continuous(breaks = seq(1985,2016,3)) +
scale_y_continuous(labels = scales::label_percent()) +
scale_color_brewer(palette = "Dark2", aesthetics = c("color", "fill")) +
theme_bw() +
labs(
x = NULL
,y = NULL
,title = glue::glue("Percentage of High School Graduates by Sex"
,"\n"
,"1985 - 2016")
,color = "Sex"
,fill = "Sex"
) +
theme(
plot.title = element_text(hjust = 0.5)
,legend.title = element_text(hjust = 0.5)
)
g2
```
Now I am going to graph by Sex and Race.
```{r}
race_filter <- c("White", "Black", "Hispanic")
make_label <- function(label){
# browser()
result <- stringr::str_split(label, "\\.")
unlist(lapply(result, function(x) paste(x[2],x[1])))
}
g2 <- male_female_hs_wide %>%
filter(race %in% race_filter) %>%
ggplot(aes(x = year, y = total, group = interaction(sex,race), color = interaction(sex,race))) +
geom_ribbon(aes(ymax = ymax, ymin = ymin, fill = interaction(sex,race)), alpha = 0.3, color = NA) +
geom_line() +
scale_x_continuous(breaks = seq(1985,2016,3)) +
scale_y_continuous(labels = scales::label_percent()) +
scale_color_brewer(palette = "Dark2", aesthetics = c("color", "fill"), labels = make_label) +
theme_bw() +
labs(
x = NULL
,y = NULL
,title = glue::glue("Percentage of High School Graduates by Race and Sex"
,"\n"
,"1985 - 2016")
,color = "Race & Sex"
,fill = "Race & Sex"
) +
theme(
plot.title = element_text(hjust = 0.5)
,legend.title = element_text(hjust = 0.5)
)
g2
```
# Conclusion
While I am sure there is much more that could be done with this data this is where I am going to stop for today. Our graphs clearly show a divide in graduation rates by race, however Sex does not seem to have much of an effect on graduation rates.