class: center, middle, inverse, title-slide # Introduction to R ### Alex Hollingsworth, Grant McDermott, and Kelli Marquardt ### Indiana University | University of Oregon | Chicago FED ### 2021-07-19 --- <style type="text/css"> .remark-slide-content { font-size: 25px; padding: 1em 4em 1em 4em; } </style> # This document was made using R-Markdown. --- # This document was also made using R-Markdown. .center[ <img src="figures/personal-website.png" width="75%" /> ] --- # This document was also made using R-Markdown. .center[ <img src="figures/package-website-and-package.png" width="75%" /> ] --- # Summary statistics table Now we can use the `datasummary_skim` function. ```r datasummary_skim(diamonds) ``` <table class="table" style="width: auto !important; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:left;"> </th> <th style="text-align:right;"> Unique (#) </th> <th style="text-align:right;"> Missing (%) </th> <th style="text-align:right;"> Mean </th> <th style="text-align:right;"> SD </th> <th style="text-align:right;"> Min </th> <th style="text-align:right;"> Median </th> <th style="text-align:right;"> Max </th> <th style="text-align:right;"> </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> carat </td> <td style="text-align:right;"> 273 </td> <td style="text-align:right;"> 0 </td> <td style="text-align:right;"> 0.8 </td> <td style="text-align:right;"> 0.5 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:right;"> 0.7 </td> <td style="text-align:right;"> 5.0 </td> <td style="text-align:right;"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="svglite" width="48.00pt" height="12.00pt" viewBox="0 0 48.00 12.00"><defs><style type="text/css"> .svglite line, .svglite polyline, .svglite polygon, .svglite path, .svglite rect, .svglite circle { fill: none; stroke: #000000; stroke-linecap: round; stroke-linejoin: round; stroke-miterlimit: 10.00; } </style></defs><rect width="100%" height="100%" style="stroke: none; fill: none;"></rect><defs><clipPath id="cpMC4wMHw0OC4wMHwwLjAwfDEyLjAw"><rect x="0.00" y="0.00" width="48.00" height="12.00"></rect></clipPath></defs><g clip-path="url(#cpMC4wMHw0OC4wMHwwLjAwfDEyLjAw)"> </g><defs><clipPath id="cpMC4wMHw0OC4wMHwyLjg4fDEyLjAw"><rect x="0.00" y="2.88" width="48.00" height="9.12"></rect></clipPath></defs><g clip-path="url(#cpMC4wMHw0OC4wMHwyLjg4fDEyLjAw)"><rect x="-0.070" y="3.22" width="4.62" height="8.44" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="4.55" y="3.85" width="4.62" height="7.81" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="9.17" y="6.28" width="4.62" height="5.38" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="13.79" y="10.08" width="4.62" height="1.58" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="18.41" y="10.88" width="4.62" height="0.79" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="23.03" y="11.62" width="4.62" height="0.042" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="27.65" y="11.65" width="4.62" height="0.010" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="32.27" y="11.66" width="4.62" height="0.0018" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="36.89" y="11.66" width="4.62" height="0.0018" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="41.51" y="11.66" width="4.62" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="46.13" y="11.66" width="4.62" height="0.00045" style="stroke-width: 0.38; fill: #000000;"></rect></g></svg> </td> </tr> <tr> <td style="text-align:left;"> depth </td> <td style="text-align:right;"> 184 </td> <td style="text-align:right;"> 0 </td> <td style="text-align:right;"> 61.7 </td> <td style="text-align:right;"> 1.4 </td> <td style="text-align:right;"> 43.0 </td> <td style="text-align:right;"> 61.8 </td> <td style="text-align:right;"> 79.0 </td> <td style="text-align:right;"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="svglite" width="48.00pt" height="12.00pt" viewBox="0 0 48.00 12.00"><defs><style type="text/css"> .svglite line, .svglite polyline, .svglite polygon, .svglite path, .svglite rect, .svglite circle { fill: none; stroke: #000000; stroke-linecap: round; stroke-linejoin: round; stroke-miterlimit: 10.00; } </style></defs><rect width="100%" height="100%" style="stroke: none; fill: none;"></rect><defs><clipPath id="cpMC4wMHw0OC4wMHwwLjAwfDEyLjAw"><rect x="0.00" y="0.00" width="48.00" height="12.00"></rect></clipPath></defs><g clip-path="url(#cpMC4wMHw0OC4wMHwwLjAwfDEyLjAw)"> </g><defs><clipPath id="cpMC4wMHw0OC4wMHwyLjg4fDEyLjAw"><rect x="0.00" y="2.88" width="48.00" height="9.12"></rect></clipPath></defs><g clip-path="url(#cpMC4wMHw0OC4wMHwyLjg4fDEyLjAw)"><rect x="0.54" y="11.66" width="2.47" height="0.00098" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="3.01" y="11.66" width="2.47" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="5.48" y="11.66" width="2.47" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="7.95" y="11.66" width="2.47" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="10.42" y="11.66" width="2.47" height="0.00065" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="12.89" y="11.66" width="2.47" height="0.0036" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="15.36" y="11.64" width="2.47" height="0.017" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="17.83" y="11.47" width="2.47" height="0.20" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="20.30" y="10.05" width="2.47" height="1.62" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="22.77" y="3.22" width="2.47" height="8.44" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="25.23" y="4.95" width="2.47" height="6.71" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="27.70" y="11.17" width="2.47" height="0.49" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="30.17" y="11.57" width="2.47" height="0.091" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="32.64" y="11.64" width="2.47" height="0.021" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="35.11" y="11.66" width="2.47" height="0.0055" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="37.58" y="11.66" width="2.47" height="0.00098" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="40.05" y="11.66" width="2.47" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="42.52" y="11.66" width="2.47" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="44.99" y="11.66" width="2.47" height="0.00098" style="stroke-width: 0.38; fill: #000000;"></rect></g></svg> </td> </tr> <tr> <td style="text-align:left;"> table </td> <td style="text-align:right;"> 127 </td> <td style="text-align:right;"> 0 </td> <td style="text-align:right;"> 57.5 </td> <td style="text-align:right;"> 2.2 </td> <td style="text-align:right;"> 43.0 </td> <td style="text-align:right;"> 57.0 </td> <td style="text-align:right;"> 95.0 </td> <td style="text-align:right;"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="svglite" width="48.00pt" height="12.00pt" viewBox="0 0 48.00 12.00"><defs><style type="text/css"> .svglite line, .svglite polyline, .svglite polygon, .svglite path, .svglite rect, .svglite circle { fill: none; stroke: #000000; stroke-linecap: round; stroke-linejoin: round; stroke-miterlimit: 10.00; } </style></defs><rect width="100%" height="100%" style="stroke: none; fill: none;"></rect><defs><clipPath id="cpMC4wMHw0OC4wMHwwLjAwfDEyLjAw"><rect x="0.00" y="0.00" width="48.00" height="12.00"></rect></clipPath></defs><g clip-path="url(#cpMC4wMHw0OC4wMHwwLjAwfDEyLjAw)"> </g><defs><clipPath id="cpMC4wMHw0OC4wMHwyLjg4fDEyLjAw"><rect x="0.00" y="2.88" width="48.00" height="9.12"></rect></clipPath></defs><g clip-path="url(#cpMC4wMHw0OC4wMHwyLjg4fDEyLjAw)"><rect x="-0.79" y="11.66" width="4.27" height="0.00043" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="3.49" y="11.66" width="4.27" height="0.00086" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="7.76" y="9.55" width="4.27" height="2.12" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="12.03" y="3.22" width="4.27" height="8.44" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="16.31" y="10.66" width="4.27" height="1.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="20.58" y="11.63" width="4.27" height="0.037" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="24.85" y="11.66" width="4.27" height="0.0011" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="29.13" y="11.66" width="4.27" height="0.00043" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="33.40" y="11.66" width="4.27" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="37.68" y="11.66" width="4.27" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="41.95" y="11.66" width="4.27" height="0.00022" style="stroke-width: 0.38; fill: #000000;"></rect></g></svg> </td> </tr> <tr> <td style="text-align:left;"> price </td> <td style="text-align:right;"> 11602 </td> <td style="text-align:right;"> 0 </td> <td style="text-align:right;"> 3932.8 </td> <td style="text-align:right;"> 3989.4 </td> <td style="text-align:right;"> 326.0 </td> <td style="text-align:right;"> 2401.0 </td> <td style="text-align:right;"> 18823.0 </td> <td style="text-align:right;"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="svglite" width="48.00pt" height="12.00pt" viewBox="0 0 48.00 12.00"><defs><style type="text/css"> .svglite line, .svglite polyline, .svglite polygon, .svglite path, .svglite rect, .svglite circle { fill: none; stroke: #000000; stroke-linecap: round; stroke-linejoin: round; stroke-miterlimit: 10.00; } </style></defs><rect width="100%" height="100%" style="stroke: none; fill: none;"></rect><defs><clipPath id="cpMC4wMHw0OC4wMHwwLjAwfDEyLjAw"><rect x="0.00" y="0.00" width="48.00" height="12.00"></rect></clipPath></defs><g clip-path="url(#cpMC4wMHw0OC4wMHwwLjAwfDEyLjAw)"> </g><defs><clipPath id="cpMC4wMHw0OC4wMHwyLjg4fDEyLjAw"><rect x="0.00" y="2.88" width="48.00" height="9.12"></rect></clipPath></defs><g clip-path="url(#cpMC4wMHw0OC4wMHwyLjg4fDEyLjAw)"><rect x="0.99" y="3.22" width="2.40" height="8.44" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="3.40" y="6.03" width="2.40" height="5.63" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="5.80" y="8.10" width="2.40" height="3.56" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="8.20" y="9.21" width="2.40" height="2.46" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="10.61" y="8.95" width="2.40" height="2.71" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="13.01" y="9.82" width="2.40" height="1.84" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="15.41" y="10.34" width="2.40" height="1.32" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="17.81" y="10.69" width="2.40" height="0.97" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="20.22" y="10.90" width="2.40" height="0.76" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="22.62" y="11.04" width="2.40" height="0.63" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="25.02" y="11.12" width="2.40" height="0.54" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="27.43" y="11.18" width="2.40" height="0.48" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="29.83" y="11.25" width="2.40" height="0.41" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="32.23" y="11.31" width="2.40" height="0.35" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="34.63" y="11.37" width="2.40" height="0.29" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="37.04" y="11.36" width="2.40" height="0.30" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="39.44" y="11.42" width="2.40" height="0.25" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="41.84" y="11.43" width="2.40" height="0.24" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="44.24" y="11.48" width="2.40" height="0.18" style="stroke-width: 0.38; fill: #000000;"></rect></g></svg> </td> </tr> <tr> <td style="text-align:left;"> x </td> <td style="text-align:right;"> 554 </td> <td style="text-align:right;"> 0 </td> <td style="text-align:right;"> 5.7 </td> <td style="text-align:right;"> 1.1 </td> <td style="text-align:right;"> 0.0 </td> <td style="text-align:right;"> 5.7 </td> <td style="text-align:right;"> 10.7 </td> <td style="text-align:right;"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="svglite" width="48.00pt" height="12.00pt" viewBox="0 0 48.00 12.00"><defs><style type="text/css"> .svglite line, .svglite polyline, .svglite polygon, .svglite path, .svglite rect, .svglite circle { fill: none; stroke: #000000; stroke-linecap: round; stroke-linejoin: round; stroke-miterlimit: 10.00; } </style></defs><rect width="100%" height="100%" style="stroke: none; fill: none;"></rect><defs><clipPath id="cpMC4wMHw0OC4wMHwwLjAwfDEyLjAw"><rect x="0.00" y="0.00" width="48.00" height="12.00"></rect></clipPath></defs><g clip-path="url(#cpMC4wMHw0OC4wMHwwLjAwfDEyLjAw)"> </g><defs><clipPath id="cpMC4wMHw0OC4wMHwyLjg4fDEyLjAw"><rect x="0.00" y="2.88" width="48.00" height="9.12"></rect></clipPath></defs><g clip-path="url(#cpMC4wMHw0OC4wMHwyLjg4fDEyLjAw)"><rect x="1.78" y="11.66" width="2.07" height="0.0070" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="3.85" y="11.66" width="2.07" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="5.92" y="11.66" width="2.07" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="7.99" y="11.66" width="2.07" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="10.05" y="11.66" width="2.07" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="12.12" y="11.66" width="2.07" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="14.19" y="11.66" width="2.07" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="16.26" y="11.23" width="2.07" height="0.43" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="18.33" y="3.22" width="2.07" height="8.44" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="20.40" y="5.07" width="2.07" height="6.59" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="22.47" y="5.38" width="2.07" height="6.28" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="24.54" y="5.60" width="2.07" height="6.06" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="26.61" y="4.64" width="2.07" height="7.02" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="28.68" y="5.49" width="2.07" height="6.17" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="30.75" y="8.42" width="2.07" height="3.25" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="32.81" y="10.21" width="2.07" height="1.45" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="34.88" y="10.26" width="2.07" height="1.40" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="36.95" y="11.45" width="2.07" height="0.21" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="39.02" y="11.64" width="2.07" height="0.026" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="41.09" y="11.66" width="2.07" height="0.0061" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="43.16" y="11.66" width="2.07" height="0.0035" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="45.23" y="11.66" width="2.07" height="0.00088" style="stroke-width: 0.38; fill: #000000;"></rect></g></svg> </td> </tr> <tr> <td style="text-align:left;"> y </td> <td style="text-align:right;"> 552 </td> <td style="text-align:right;"> 0 </td> <td style="text-align:right;"> 5.7 </td> <td style="text-align:right;"> 1.1 </td> <td style="text-align:right;"> 0.0 </td> <td style="text-align:right;"> 5.7 </td> <td style="text-align:right;"> 58.9 </td> <td style="text-align:right;"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="svglite" width="48.00pt" height="12.00pt" viewBox="0 0 48.00 12.00"><defs><style type="text/css"> .svglite line, .svglite polyline, .svglite polygon, .svglite path, .svglite rect, .svglite circle { fill: none; stroke: #000000; stroke-linecap: round; stroke-linejoin: round; stroke-miterlimit: 10.00; } </style></defs><rect width="100%" height="100%" style="stroke: none; fill: none;"></rect><defs><clipPath id="cpMC4wMHw0OC4wMHwwLjAwfDEyLjAw"><rect x="0.00" y="0.00" width="48.00" height="12.00"></rect></clipPath></defs><g clip-path="url(#cpMC4wMHw0OC4wMHwwLjAwfDEyLjAw)"> </g><defs><clipPath id="cpMC4wMHw0OC4wMHwyLjg4fDEyLjAw"><rect x="0.00" y="2.88" width="48.00" height="9.12"></rect></clipPath></defs><g clip-path="url(#cpMC4wMHw0OC4wMHwyLjg4fDEyLjAw)"><rect x="1.78" y="7.56" width="3.77" height="4.10" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="5.55" y="3.22" width="3.77" height="8.44" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="9.32" y="11.66" width="3.77" height="0.00070" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="13.10" y="11.66" width="3.77" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="16.87" y="11.66" width="3.77" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="20.64" y="11.66" width="3.77" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="24.42" y="11.66" width="3.77" height="0.00023" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="28.19" y="11.66" width="3.77" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="31.96" y="11.66" width="3.77" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="35.73" y="11.66" width="3.77" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="39.51" y="11.66" width="3.77" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="43.28" y="11.66" width="3.77" height="0.00023" style="stroke-width: 0.38; fill: #000000;"></rect></g></svg> </td> </tr> <tr> <td style="text-align:left;"> z </td> <td style="text-align:right;"> 375 </td> <td style="text-align:right;"> 0 </td> <td style="text-align:right;"> 3.5 </td> <td style="text-align:right;"> 0.7 </td> <td style="text-align:right;"> 0.0 </td> <td style="text-align:right;"> 3.5 </td> <td style="text-align:right;"> 31.8 </td> <td style="text-align:right;"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="svglite" width="48.00pt" height="12.00pt" viewBox="0 0 48.00 12.00"><defs><style type="text/css"> .svglite line, .svglite polyline, .svglite polygon, .svglite path, .svglite rect, .svglite circle { fill: none; stroke: #000000; stroke-linecap: round; stroke-linejoin: round; stroke-miterlimit: 10.00; } </style></defs><rect width="100%" height="100%" style="stroke: none; fill: none;"></rect><defs><clipPath id="cpMC4wMHw0OC4wMHwwLjAwfDEyLjAw"><rect x="0.00" y="0.00" width="48.00" height="12.00"></rect></clipPath></defs><g clip-path="url(#cpMC4wMHw0OC4wMHwwLjAwfDEyLjAw)"> </g><defs><clipPath id="cpMC4wMHw0OC4wMHwyLjg4fDEyLjAw"><rect x="0.00" y="2.88" width="48.00" height="9.12"></rect></clipPath></defs><g clip-path="url(#cpMC4wMHw0OC4wMHwyLjg4fDEyLjAw)"><rect x="1.78" y="11.66" width="2.80" height="0.0050" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="4.57" y="3.22" width="2.80" height="8.44" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="7.37" y="8.40" width="2.80" height="3.26" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="10.16" y="11.66" width="2.80" height="0.0026" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="12.96" y="11.66" width="2.80" height="0.00022" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="15.75" y="11.66" width="2.80" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="18.55" y="11.66" width="2.80" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="21.34" y="11.66" width="2.80" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="24.14" y="11.66" width="2.80" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="26.94" y="11.66" width="2.80" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="29.73" y="11.66" width="2.80" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="32.53" y="11.66" width="2.80" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="35.32" y="11.66" width="2.80" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="38.12" y="11.66" width="2.80" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="40.91" y="11.66" width="2.80" height="0.00" style="stroke-width: 0.38; fill: #000000;"></rect><rect x="43.71" y="11.66" width="2.80" height="0.00022" style="stroke-width: 0.38; fill: #000000;"></rect></g></svg> </td> </tr> </tbody> </table> --- # Graphing with `ggplot` **g**rammar of **g**raphics **plot** .pull-right[ <img src="figures/ggplot-layers.png" width="75%" /> ] --- # Graphing with `ggplot` **g**rammar of **g**raphics **plot** .center[ <img src="figures/ggplot-layers-2.png" width="75%" /> ] --- # Graphing with `ggplot` .pull-left[ ```r *ggplot(data = diamonds) ``` First add data ] .pull-right[ <!-- --> ] --- # Graphing with `ggplot` .pull-left[ ```r ggplot(data = diamonds, * aes(y = price, x = carat)) ``` Second add aesthetics ] .pull-right[ <!-- --> ] --- # Graphing with `ggplot` .pull-left[ ```r ggplot(data = diamonds, aes(y = price, x = carat)) + * geom_point() ``` Third add geometry ] .pull-right[ <!-- --> ] --- # Graphing with `ggplot` .pull-left[ ```r ggplot(data = diamonds, aes(y = price, x = carat)) + geom_point() + * theme_classic() ``` Fourth add theme ] .pull-right[ <!-- --> ] --- # Graphing with `ggplot` .pull-left[ ```r base_plot = ggplot(data = diamonds, aes(y = price, x = carat)) + geom_point() *base_plot + * theme_classic() ``` Alternative way of making changes to a "base" plot ] .pull-right[ <!-- --> ] --- # Graphing with `ggplot` .pull-left[ ```r ggplot(data = diamonds, aes(y = price, x = carat)) + * geom_point(alpha = .1) + theme_classic() ``` Exploring geometry options ] .pull-right[ <!-- --> ] --- # Graphing with `ggplot` .pull-left[ ```r ggplot(data = diamonds, aes(y = price, x = carat)) + geom_point(alpha = .1) + theme_classic() + * theme(text = element_text(size = 18)) + labs(title = "Larger diamonds cost more", subtitle = "Price, $", y = "", x = "Carat") ``` Change text size ] .pull-right[ <!-- --> ] --- # Graphing with `ggplot` .pull-left[ ```r ggplot(data = diamonds, aes(y = price, x = carat)) + geom_point(alpha = .1) + theme_classic() + theme(text = element_text(size = 18)) + * labs(title = "Larger diamonds cost more", * subtitle = "Price, $", * y = "", * x = "Carat") ``` Change text options ] .pull-right[ <!-- --> ] --- # Graphing with `ggplot` .pull-left[ ```r ggplot(data = diamonds, aes(y = price, x = carat)) + geom_point(alpha = .1) + * facet_wrap(~color) + theme_classic() + theme(text = element_text(size = 18)) + labs(title = "Larger diamonds cost more", subtitle = "Price, $", y = "", x = "Carat") ``` Add facets ] .pull-right[ <!-- --> ] --- # Graphing with `ggplot` .pull-left[ ```r ggplot(data = diamonds, * aes(y = price, x = carat, color = clarity)) + geom_point(alpha = .1) + facet_wrap(~color) + theme_classic() + theme(text = element_text(size = 14)) + labs(title = "Larger diamonds cost more by diamond color", subtitle = "Price, $", y = "", x = "Carat") ``` Add color to points based on clarity of diamond ] .pull-right[ <!-- --> ] --- # Graphing with `ggplot` .pull-left[ ```r ggplot(data = diamonds, aes(y = price, x = carat, color = clarity)) + geom_point(alpha = .1) + facet_wrap(~color) + * geom_smooth(method = "lm") + theme_classic() + theme(text = element_text(size = 14)) + labs(title = "Larger diamonds cost more by diamond color", subtitle = "Price, $", y = "", x = "Carat") ``` Add regression line ] .pull-right[ <!-- --> ] --- # Graphing with `ggplot` .pull-left[ ```r ggplot(data = diamonds, aes(y = price, x = carat, color = clarity)) + * geom_point(alpha = .1) + facet_wrap(~color) + geom_smooth(method = "lm") + theme_classic() + theme(text = element_text(size = 14)) + labs(title = "Larger diamonds cost more by diamond color", subtitle = "Price, $", y = "", x = "Carat") ``` De-clutter by removing points ] .pull-right[ <!-- --> ] --- # Graphing with `ggplot` .pull-left[ ```r ggplot(data = diamonds, aes(y = price, x = carat, color = clarity)) + facet_wrap(~color) + geom_smooth(method = "lm") + theme_classic() + theme(text = element_text(size = 14)) + labs(title = "Larger diamonds cost more by diamond color", subtitle = "Price, $", y = "", x = "Carat") ``` De-clutter by removing points ] .pull-right[ <!-- --> ] --- # Let's switch over to an R-Markdown document ### Also look. Some latex $$ f(x) = \frac{1}{\sigma\sqrt{2\pi}} \exp\left( -\frac{1}{2}\left(\frac{x-\mu}{\sigma}\right)^{2}\,\right) $$ --- # And oh yea, this was made in R too. .pull-left[  ] .pull-right[ - Check out [`rayshader`](https://www.rayshader.com) if you want to make your own awesome map, 2D, and 3D visualization. - Source of image: https://wcmbishop.github.io/rayshader-demo/ ] --- exclude: true