Skip to content
Snippets Groups Projects
gt-grammar.html 216 KiB
Newer Older
  • Learn to ignore specific revisions
  • bpkleer's avatar
    bpkleer committed
    <!DOCTYPE html>
    
    <html>
    
    <head>
    
    <meta charset="utf-8" />
    <meta name="generator" content="pandoc" />
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
    
    
    
    
    <title>gt-tables.knit</title>
    
    <script src="gt-tables_files/header-attrs-2.11/header-attrs.js"></script>
    <script src="gt-tables_files/jquery-3.6.0/jquery-3.6.0.min.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link href="gt-tables_files/bootstrap-3.3.5/css/readable.min.css" rel="stylesheet" />
    <script src="gt-tables_files/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="gt-tables_files/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
    <script src="gt-tables_files/bootstrap-3.3.5/shim/respond.min.js"></script>
    <style>h1 {font-size: 34px;}
           h1.title {font-size: 38px;}
           h2 {font-size: 30px;}
           h3 {font-size: 24px;}
           h4 {font-size: 18px;}
           h5 {font-size: 16px;}
           h6 {font-size: 12px;}
           code {color: inherit; background-color: rgba(0, 0, 0, 0.04);}
           pre:not([class]) { background-color: white }</style>
    <script src="gt-tables_files/jqueryui-1.11.4/jquery-ui.min.js"></script>
    <link href="gt-tables_files/tocify-1.9.1/jquery.tocify.css" rel="stylesheet" />
    <script src="gt-tables_files/tocify-1.9.1/jquery.tocify.js"></script>
    <script src="gt-tables_files/navigation-1.1/tabsets.js"></script>
    <link href="gt-tables_files/pagedtable-1.1/css/pagedtable.css" rel="stylesheet" />
    <script src="gt-tables_files/pagedtable-1.1/js/pagedtable.js"></script>
    <script src="gt-tables_files/clipboard-2.0.6/clipboard.min.js"></script>
    <link href="gt-tables_files/xaringanExtra-clipboard-0.2.6/xaringanExtra-clipboard.css" rel="stylesheet" />
    <script src="gt-tables_files/xaringanExtra-clipboard-0.2.6/xaringanExtra-clipboard.js"></script>
    <script>window.xaringanExtraClipboard(null, {"button":"<i class=\"fa fa-clipboard\"><\/i>","success":"<i class=\"fa fa-check\" style=\"color: #90BE6D\"><\/i>","error":"<i class=\"fa fa-times-circle\" style=\"color: #F94144\"><\/i>"})</script>
    <link href="gt-tables_files/font-awesome-5.1.0/css/all.css" rel="stylesheet" />
    <link href="gt-tables_files/font-awesome-5.1.0/css/v4-shims.css" rel="stylesheet" />
    
    <style type="text/css">
      code{white-space: pre-wrap;}
      span.smallcaps{font-variant: small-caps;}
      span.underline{text-decoration: underline;}
      div.column{display: inline-block; vertical-align: top; width: 50%;}
      div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
      ul.task-list{list-style: none;}
        </style>
    
    
    <style type="text/css">
      code {
        white-space: pre;
      }
      .sourceCode {
        overflow: visible;
      }
    </style>
    <style type="text/css" data-origin="pandoc">
    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;
        color: #aaaaaa;
      }
    pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
    div.sourceCode
      {   }
    @media screen {
    pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
    }
    code span.al { color: #ff0000; font-weight: bold; } /* Alert */
    code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
    code span.at { color: #7d9029; } /* Attribute */
    code span.bn { color: #40a070; } /* BaseN */
    code span.bu { } /* BuiltIn */
    code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
    code span.ch { color: #4070a0; } /* Char */
    code span.cn { color: #880000; } /* Constant */
    code span.co { color: #60a0b0; font-style: italic; } /* Comment */
    code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
    code span.do { color: #ba2121; font-style: italic; } /* Documentation */
    code span.dt { color: #902000; } /* DataType */
    code span.dv { color: #40a070; } /* DecVal */
    code span.er { color: #ff0000; font-weight: bold; } /* Error */
    code span.ex { } /* Extension */
    code span.fl { color: #40a070; } /* Float */
    code span.fu { color: #06287e; } /* Function */
    code span.im { } /* Import */
    code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
    code span.kw { color: #007020; font-weight: bold; } /* Keyword */
    code span.op { color: #666666; } /* Operator */
    code span.ot { color: #007020; } /* Other */
    code span.pp { color: #bc7a00; } /* Preprocessor */
    code span.sc { color: #4070a0; } /* SpecialChar */
    code span.ss { color: #bb6688; } /* SpecialString */
    code span.st { color: #4070a0; } /* String */
    code span.va { color: #19177c; } /* Variable */
    code span.vs { color: #4070a0; } /* VerbatimString */
    code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
    
    </style>
    <script>
    // apply pandoc div.sourceCode style to pre.sourceCode instead
    (function() {
      var sheets = document.styleSheets;
      for (var i = 0; i < sheets.length; i++) {
        if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
        try { var rules = sheets[i].cssRules; } catch (e) { continue; }
        for (var j = 0; j < rules.length; j++) {
          var rule = rules[j];
          // check if there is a div.sourceCode rule
          if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") continue;
          var style = rule.style.cssText;
          // check if color or background-color is set
          if (rule.style.color === '' && rule.style.backgroundColor === '') continue;
          // replace div.sourceCode by a pre.sourceCode rule
          sheets[i].deleteRule(j);
          sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
        }
      }
    })();
    </script>
    
    
    
    
    <link rel="stylesheet" href="styles/style.css" type="text/css" />
    
    
    
    <style type = "text/css">
    .main-container {
      max-width: 940px;
      margin-left: auto;
      margin-right: auto;
    }
    img {
      max-width:100%;
    }
    .tabbed-pane {
      padding-top: 12px;
    }
    .html-widget {
      margin-bottom: 20px;
    }
    button.code-folding-btn:focus {
      outline: none;
    }
    summary {
      display: list-item;
    }
    pre code {
      padding: 0;
    }
    </style>
    
    
    
    <!-- tabsets -->
    
    <style type="text/css">
    .tabset-dropdown > .nav-tabs {
      display: inline-table;
      max-height: 500px;
      min-height: 44px;
      overflow-y: auto;
      border: 1px solid #ddd;
      border-radius: 4px;
    }
    
    .tabset-dropdown > .nav-tabs > li.active:before {
      content: "";
      font-family: 'Glyphicons Halflings';
      display: inline-block;
      padding: 10px;
      border-right: 1px solid #ddd;
    }
    
    .tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before {
      content: "&#xe258;";
      border: none;
    }
    
    .tabset-dropdown > .nav-tabs.nav-tabs-open:before {
      content: "";
      font-family: 'Glyphicons Halflings';
      display: inline-block;
      padding: 10px;
      border-right: 1px solid #ddd;
    }
    
    .tabset-dropdown > .nav-tabs > li.active {
      display: block;
    }
    
    .tabset-dropdown > .nav-tabs > li > a,
    .tabset-dropdown > .nav-tabs > li > a:focus,
    .tabset-dropdown > .nav-tabs > li > a:hover {
      border: none;
      display: inline-block;
      border-radius: 4px;
      background-color: transparent;
    }
    
    .tabset-dropdown > .nav-tabs.nav-tabs-open > li {
      display: block;
      float: none;
    }
    
    .tabset-dropdown > .nav-tabs > li {
      display: none;
    }
    </style>
    
    <!-- code folding -->
    
    
    
    <style type="text/css">
    
    #TOC {
      margin: 25px 0px 20px 0px;
    }
    @media (max-width: 768px) {
    #TOC {
      position: relative;
      width: 100%;
    }
    }
    
    @media print {
    .toc-content {
      /* see https://github.com/w3c/csswg-drafts/issues/4434 */
      float: right;
    }
    }
    
    .toc-content {
      padding-left: 30px;
      padding-right: 40px;
    }
    
    div.main-container {
      max-width: 1200px;
    }
    
    div.tocify {
      width: 20%;
      max-width: 260px;
      max-height: 85%;
    }
    
    @media (min-width: 768px) and (max-width: 991px) {
      div.tocify {
        width: 25%;
      }
    }
    
    @media (max-width: 767px) {
      div.tocify {
        width: 100%;
        max-width: none;
      }
    }
    
    .tocify ul, .tocify li {
      line-height: 20px;
    }
    
    .tocify-subheader .tocify-item {
      font-size: 0.90em;
    }
    
    .tocify .list-group-item {
      border-radius: 0px;
    }
    
    
    </style>
    
    
    
    </head>
    
    <body>
    
    
    <div class="container-fluid main-container">
    
    
    <!-- setup 3col/9col grid for toc_float and main content  -->
    <div class="row">
    <div class="col-xs-12 col-sm-4 col-md-3">
    <div id="TOC" class="tocify">
    </div>
    </div>
    
    <div class="toc-content col-xs-12 col-sm-8 col-md-9">
    
    
    
    <br><br>
    
    <center>
    <p style="font-size: 26px; font-weight:bold; align:center;color:rgb(69, 130, 236)"> Datensätze bändigen & visualisieren mit R</p>
    <br>
    <p style="font-size: 24px; align:center"> Benedikt Philipp Kleer <br> 11. Oktober 2021</p>
    <hr />
    <br>
    </center>
    
    <div id="header">
    
    
    
    
    </div>
    
    
    <div id="tabellen-publizierbar-erstellen-mit-gt" class="section level2">
    <h2>Tabellen publizierbar erstellen mit <code>gt</code></h2>
    
    bpkleer's avatar
    bpkleer committed
    <p>Das <em>package</em> <code>gt</code> (<em>grammar of tables</em>) inkludiert hilfreiche Funktionen, um Tabellen aus R in ein Format zu exportieren, das in wissenschaftlichen Arbeiten oder bei Präsentationen genutzt werden kann.</p>
    
    bpkleer's avatar
    bpkleer committed
    <p>Das Paket ist umfassend und hier werden nur einführende Schritte dargestellt, die aber für erste Projekte im BA-Studium hilfreich sind. Die genaue Dokumentation findet sich in der <a href="https://gt.rstudio.com/">Benutzerdokumentation</a>.</p>
    <p>Die generelle Funktionslogik erfolgt bei <code>gt</code> wie folgt:</p>
    <center>
    <img src="pics/gt.svg" title="fig:" alt="Aufbau-Logik eines tables in gt" />
    </center>
    <p>All diese verschiedenen Felder können einzeln angesprochen werden und verändert werden.</p>
    <p>Bevor wir nun mit den Beispielen starten, müssen wir das <em>package</em> selbst laden als auch <code>tidyverse</code>.</p>
    <div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="co"># falls noch nicht installiert</span></span>
    <span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="co"># install.packages(&quot;gt&quot;, </span></span>
    
    bpkleer's avatar
    bpkleer committed
    <span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="co">#                  dependencies = TRUE</span></span>
    <span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="co">#                  )</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><span class="co"># install.packages(&quot;tidyverse&quot;,</span></span>
    <span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a><span class="co">#                  dependencies = TRUE</span></span>
    <span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a><span class="co">#                  )</span></span>
    <span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a></span>
    <span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(<span class="st">&quot;gt&quot;</span>)</span>
    <span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(<span class="st">&quot;tidyverse&quot;</span>)</span></code></pre></div>
    
    bpkleer's avatar
    bpkleer committed
    </div>
    <div id="eine-einfache-tabelle" class="section level2">
    <h2>Eine einfache Tabelle</h2>
    <p>Bevor wir nun Kreuztabellen darstellen, machen wir eine einfache Tabelle. Wir wollen zum Beispiel die Häufigkeiten für die <em>Studienmotivation</em> ausgeben lassen (<code>mot</code>).</p>
    <div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="fu">table</span>(uni<span class="sc">$</span>mot)</span></code></pre></div>
    <pre><code>
      0   1   2   3   4   5   6   7   8   9 
    105  93  81 110 116  93  88 108  91 115 </code></pre>
    <p>Zuerst müssen wir mit <code>tidyverse</code> ein <em>tibble</em> schaffen, dass wir an <code>gt</code> übergeben können. Dazu wählen wir aus dem Datensatz die Variable <code>mot</code> aus, gruppieren die Daten nach <code>mot</code> und bilden dann mit summarize die jeweilige Summe unter den Ausprägungen der Variable <code>mot</code> (Funktion <code>n()</code>). Mit <code>gt()</code> erstellen wir dann die Tabelle:</p>
    <div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>uni <span class="sc">%&gt;%</span> </span>
    <span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(mot) <span class="sc">%&gt;%</span>  </span>
    <span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(mot) <span class="sc">%&gt;%</span> </span>
    <span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(<span class="at">n =</span> <span class="fu">n</span>()) <span class="sc">%&gt;%</span> </span>
    <span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">gt</span>()</span></code></pre></div>
    
    bpkleer's avatar
    bpkleer committed
    <div id="ersisutghe" style="overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
    
    bpkleer's avatar
    bpkleer committed
    <style>html {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_table {
    
    bpkleer's avatar
    bpkleer committed
      display: table;
      border-collapse: collapse;
      margin-left: auto;
      margin-right: auto;
      color: #333333;
      font-size: 16px;
      font-weight: normal;
      font-style: normal;
      background-color: #FFFFFF;
      width: auto;
      border-top-style: solid;
      border-top-width: 2px;
      border-top-color: #A8A8A8;
      border-right-style: none;
      border-right-width: 2px;
      border-right-color: #D3D3D3;
      border-bottom-style: solid;
      border-bottom-width: 2px;
      border-bottom-color: #A8A8A8;
      border-left-style: none;
      border-left-width: 2px;
      border-left-color: #D3D3D3;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_heading {
    
    bpkleer's avatar
    bpkleer committed
      background-color: #FFFFFF;
      text-align: center;
      border-bottom-color: #FFFFFF;
      border-left-style: none;
      border-left-width: 1px;
      border-left-color: #D3D3D3;
      border-right-style: none;
      border-right-width: 1px;
      border-right-color: #D3D3D3;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_title {
    
    bpkleer's avatar
    bpkleer committed
      color: #333333;
      font-size: 125%;
      font-weight: initial;
      padding-top: 4px;
      padding-bottom: 4px;
      border-bottom-color: #FFFFFF;
      border-bottom-width: 0;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_subtitle {
    
    bpkleer's avatar
    bpkleer committed
      color: #333333;
      font-size: 85%;
      font-weight: initial;
      padding-top: 0;
      padding-bottom: 6px;
      border-top-color: #FFFFFF;
      border-top-width: 0;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_bottom_border {
    
    bpkleer's avatar
    bpkleer committed
      border-bottom-style: solid;
      border-bottom-width: 2px;
      border-bottom-color: #D3D3D3;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_col_headings {
    
    bpkleer's avatar
    bpkleer committed
      border-top-style: solid;
      border-top-width: 2px;
      border-top-color: #D3D3D3;
      border-bottom-style: solid;
      border-bottom-width: 2px;
      border-bottom-color: #D3D3D3;
      border-left-style: none;
      border-left-width: 1px;
      border-left-color: #D3D3D3;
      border-right-style: none;
      border-right-width: 1px;
      border-right-color: #D3D3D3;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_col_heading {
    
    bpkleer's avatar
    bpkleer committed
      color: #333333;
      background-color: #FFFFFF;
      font-size: 100%;
      font-weight: normal;
      text-transform: inherit;
      border-left-style: none;
      border-left-width: 1px;
      border-left-color: #D3D3D3;
      border-right-style: none;
      border-right-width: 1px;
      border-right-color: #D3D3D3;
      vertical-align: bottom;
      padding-top: 5px;
      padding-bottom: 6px;
      padding-left: 5px;
      padding-right: 5px;
      overflow-x: hidden;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_column_spanner_outer {
    
    bpkleer's avatar
    bpkleer committed
      color: #333333;
      background-color: #FFFFFF;
      font-size: 100%;
      font-weight: normal;
      text-transform: inherit;
      padding-top: 0;
      padding-bottom: 0;
      padding-left: 4px;
      padding-right: 4px;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_column_spanner_outer:first-child {
    
    bpkleer's avatar
    bpkleer committed
      padding-left: 0;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_column_spanner_outer:last-child {
    
    bpkleer's avatar
    bpkleer committed
      padding-right: 0;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_column_spanner {
    
    bpkleer's avatar
    bpkleer committed
      border-bottom-style: solid;
      border-bottom-width: 2px;
      border-bottom-color: #D3D3D3;
      vertical-align: bottom;
      padding-top: 5px;
      padding-bottom: 5px;
      overflow-x: hidden;
      display: inline-block;
      width: 100%;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_group_heading {
    
    bpkleer's avatar
    bpkleer committed
      padding: 8px;
      color: #333333;
      background-color: #FFFFFF;
      font-size: 100%;
      font-weight: initial;
      text-transform: inherit;
      border-top-style: solid;
      border-top-width: 2px;
      border-top-color: #D3D3D3;
      border-bottom-style: solid;
      border-bottom-width: 2px;
      border-bottom-color: #D3D3D3;
      border-left-style: none;
      border-left-width: 1px;
      border-left-color: #D3D3D3;
      border-right-style: none;
      border-right-width: 1px;
      border-right-color: #D3D3D3;
      vertical-align: middle;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_empty_group_heading {
    
    bpkleer's avatar
    bpkleer committed
      padding: 0.5px;
      color: #333333;
      background-color: #FFFFFF;
      font-size: 100%;
      font-weight: initial;
      border-top-style: solid;
      border-top-width: 2px;
      border-top-color: #D3D3D3;
      border-bottom-style: solid;
      border-bottom-width: 2px;
      border-bottom-color: #D3D3D3;
      vertical-align: middle;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_from_md > :first-child {
    
    bpkleer's avatar
    bpkleer committed
      margin-top: 0;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_from_md > :last-child {
    
    bpkleer's avatar
    bpkleer committed
      margin-bottom: 0;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_row {
    
    bpkleer's avatar
    bpkleer committed
      padding-top: 8px;
      padding-bottom: 8px;
      padding-left: 5px;
      padding-right: 5px;
      margin: 10px;
      border-top-style: solid;
      border-top-width: 1px;
      border-top-color: #D3D3D3;
      border-left-style: none;
      border-left-width: 1px;
      border-left-color: #D3D3D3;
      border-right-style: none;
      border-right-width: 1px;
      border-right-color: #D3D3D3;
      vertical-align: middle;
      overflow-x: hidden;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_stub {
    
    bpkleer's avatar
    bpkleer committed
      color: #333333;
      background-color: #FFFFFF;
      font-size: 100%;
      font-weight: initial;
      text-transform: inherit;
      border-right-style: solid;
      border-right-width: 2px;
      border-right-color: #D3D3D3;
      padding-left: 12px;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_summary_row {
    
    bpkleer's avatar
    bpkleer committed
      color: #333333;
      background-color: #FFFFFF;
      text-transform: inherit;
      padding-top: 8px;
      padding-bottom: 8px;
      padding-left: 5px;
      padding-right: 5px;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_first_summary_row {
    
    bpkleer's avatar
    bpkleer committed
      padding-top: 8px;
      padding-bottom: 8px;
      padding-left: 5px;
      padding-right: 5px;
      border-top-style: solid;
      border-top-width: 2px;
      border-top-color: #D3D3D3;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_grand_summary_row {
    
    bpkleer's avatar
    bpkleer committed
      color: #333333;
      background-color: #FFFFFF;
      text-transform: inherit;
      padding-top: 8px;
      padding-bottom: 8px;
      padding-left: 5px;
      padding-right: 5px;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_first_grand_summary_row {
    
    bpkleer's avatar
    bpkleer committed
      padding-top: 8px;
      padding-bottom: 8px;
      padding-left: 5px;
      padding-right: 5px;
      border-top-style: double;
      border-top-width: 6px;
      border-top-color: #D3D3D3;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_striped {
    
    bpkleer's avatar
    bpkleer committed
      background-color: rgba(128, 128, 128, 0.05);
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_table_body {
    
    bpkleer's avatar
    bpkleer committed
      border-top-style: solid;
      border-top-width: 2px;
      border-top-color: #D3D3D3;
      border-bottom-style: solid;
      border-bottom-width: 2px;
      border-bottom-color: #D3D3D3;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_footnotes {
    
    bpkleer's avatar
    bpkleer committed
      color: #333333;
      background-color: #FFFFFF;
      border-bottom-style: none;
      border-bottom-width: 2px;
      border-bottom-color: #D3D3D3;
      border-left-style: none;
      border-left-width: 2px;
      border-left-color: #D3D3D3;
      border-right-style: none;
      border-right-width: 2px;
      border-right-color: #D3D3D3;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_footnote {
    
    bpkleer's avatar
    bpkleer committed
      margin: 0px;
      font-size: 90%;
      padding: 4px;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_sourcenotes {
    
    bpkleer's avatar
    bpkleer committed
      color: #333333;
      background-color: #FFFFFF;
      border-bottom-style: none;
      border-bottom-width: 2px;
      border-bottom-color: #D3D3D3;
      border-left-style: none;
      border-left-width: 2px;
      border-left-color: #D3D3D3;
      border-right-style: none;
      border-right-width: 2px;
      border-right-color: #D3D3D3;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_sourcenote {
    
    bpkleer's avatar
    bpkleer committed
      font-size: 90%;
      padding: 4px;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_left {
    
    bpkleer's avatar
    bpkleer committed
      text-align: left;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_center {
    
    bpkleer's avatar
    bpkleer committed
      text-align: center;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_right {
    
    bpkleer's avatar
    bpkleer committed
      text-align: right;
      font-variant-numeric: tabular-nums;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_font_normal {
    
    bpkleer's avatar
    bpkleer committed
      font-weight: normal;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_font_bold {
    
    bpkleer's avatar
    bpkleer committed
      font-weight: bold;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_font_italic {
    
    bpkleer's avatar
    bpkleer committed
      font-style: italic;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_super {
    
    bpkleer's avatar
    bpkleer committed
      font-size: 65%;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #ersisutghe .gt_footnote_marks {
    
    bpkleer's avatar
    bpkleer committed
      font-style: italic;
      font-weight: normal;
      font-size: 65%;
    }
    </style>
    <table class="gt_table">
      
      <thead class="gt_col_headings">
        <tr>
          <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">mot</th>
          <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">n</th>
        </tr>
      </thead>
      <tbody class="gt_table_body">
        <tr><td class="gt_row gt_right">0</td>
    <td class="gt_row gt_right">105</td></tr>
        <tr><td class="gt_row gt_right">1</td>
    <td class="gt_row gt_right">93</td></tr>
        <tr><td class="gt_row gt_right">2</td>
    <td class="gt_row gt_right">81</td></tr>
        <tr><td class="gt_row gt_right">3</td>
    <td class="gt_row gt_right">110</td></tr>
        <tr><td class="gt_row gt_right">4</td>
    <td class="gt_row gt_right">116</td></tr>
        <tr><td class="gt_row gt_right">5</td>
    <td class="gt_row gt_right">93</td></tr>
        <tr><td class="gt_row gt_right">6</td>
    <td class="gt_row gt_right">88</td></tr>
        <tr><td class="gt_row gt_right">7</td>
    <td class="gt_row gt_right">108</td></tr>
        <tr><td class="gt_row gt_right">8</td>
    <td class="gt_row gt_right">91</td></tr>
        <tr><td class="gt_row gt_right">9</td>
    <td class="gt_row gt_right">115</td></tr>
      </tbody>
      
      
    </table>
    </div>
    <p>Jetzt ist das Format noch etwas unhandlich für Berichte oder Abschlussarbeiten und daher nutzen wir eine weitere Funktion aus <code>tidyverse</code>, nämlich <code>pivot_wider()</code>. Mit <code>pivot_wider()</code> können wir die Tabelle neu ordnen. Hierbei geben wir dann an, dass die Spaltennamen die Ausprägungen von <code>mot</code> sind und die Werte (also der Inhalt der ersten und einzigen Zeile) aus der vorherigen Spalte <code>n</code> entnommen werden.</p>
    <div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>uni <span class="sc">%&gt;%</span> </span>
    <span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(mot) <span class="sc">%&gt;%</span>  </span>
    <span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(mot) <span class="sc">%&gt;%</span> </span>
    <span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(<span class="at">n =</span> <span class="fu">n</span>()) <span class="sc">%&gt;%</span> </span>
    <span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">pivot_wider</span>(<span class="at">names_from =</span> mot,</span>
    
    bpkleer's avatar
    bpkleer committed
    <span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a>              <span class="at">values_from =</span> n</span>
    <span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a>              ) <span class="sc">%&gt;%</span> </span>
    <span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">gt</span>()</span></code></pre></div>
    
    bpkleer's avatar
    bpkleer committed
    <div id="jigzjgrlrz" style="overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
    
    bpkleer's avatar
    bpkleer committed
    <style>html {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_table {
    
    bpkleer's avatar
    bpkleer committed
      display: table;
      border-collapse: collapse;
      margin-left: auto;
      margin-right: auto;
      color: #333333;
      font-size: 16px;
      font-weight: normal;
      font-style: normal;
      background-color: #FFFFFF;
      width: auto;
      border-top-style: solid;
      border-top-width: 2px;
      border-top-color: #A8A8A8;
      border-right-style: none;
      border-right-width: 2px;
      border-right-color: #D3D3D3;
      border-bottom-style: solid;
      border-bottom-width: 2px;
      border-bottom-color: #A8A8A8;
      border-left-style: none;
      border-left-width: 2px;
      border-left-color: #D3D3D3;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_heading {
    
    bpkleer's avatar
    bpkleer committed
      background-color: #FFFFFF;
      text-align: center;
      border-bottom-color: #FFFFFF;
      border-left-style: none;
      border-left-width: 1px;
      border-left-color: #D3D3D3;
      border-right-style: none;
      border-right-width: 1px;
      border-right-color: #D3D3D3;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_title {
    
    bpkleer's avatar
    bpkleer committed
      color: #333333;
      font-size: 125%;
      font-weight: initial;
      padding-top: 4px;
      padding-bottom: 4px;
      border-bottom-color: #FFFFFF;
      border-bottom-width: 0;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_subtitle {
    
    bpkleer's avatar
    bpkleer committed
      color: #333333;
      font-size: 85%;
      font-weight: initial;
      padding-top: 0;
      padding-bottom: 6px;
      border-top-color: #FFFFFF;
      border-top-width: 0;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_bottom_border {
    
    bpkleer's avatar
    bpkleer committed
      border-bottom-style: solid;
      border-bottom-width: 2px;
      border-bottom-color: #D3D3D3;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_col_headings {
    
    bpkleer's avatar
    bpkleer committed
      border-top-style: solid;
      border-top-width: 2px;
      border-top-color: #D3D3D3;
      border-bottom-style: solid;
      border-bottom-width: 2px;
      border-bottom-color: #D3D3D3;
      border-left-style: none;
      border-left-width: 1px;
      border-left-color: #D3D3D3;
      border-right-style: none;
      border-right-width: 1px;
      border-right-color: #D3D3D3;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_col_heading {
    
    bpkleer's avatar
    bpkleer committed
      color: #333333;
      background-color: #FFFFFF;
      font-size: 100%;
      font-weight: normal;
      text-transform: inherit;
      border-left-style: none;
      border-left-width: 1px;
      border-left-color: #D3D3D3;
      border-right-style: none;
      border-right-width: 1px;
      border-right-color: #D3D3D3;
      vertical-align: bottom;
      padding-top: 5px;
      padding-bottom: 6px;
      padding-left: 5px;
      padding-right: 5px;
      overflow-x: hidden;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_column_spanner_outer {
    
    bpkleer's avatar
    bpkleer committed
      color: #333333;
      background-color: #FFFFFF;
      font-size: 100%;
      font-weight: normal;
      text-transform: inherit;
      padding-top: 0;
      padding-bottom: 0;
      padding-left: 4px;
      padding-right: 4px;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_column_spanner_outer:first-child {
    
    bpkleer's avatar
    bpkleer committed
      padding-left: 0;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_column_spanner_outer:last-child {
    
    bpkleer's avatar
    bpkleer committed
      padding-right: 0;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_column_spanner {
    
    bpkleer's avatar
    bpkleer committed
      border-bottom-style: solid;
      border-bottom-width: 2px;
      border-bottom-color: #D3D3D3;
      vertical-align: bottom;
      padding-top: 5px;
      padding-bottom: 5px;
      overflow-x: hidden;
      display: inline-block;
      width: 100%;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_group_heading {
    
    bpkleer's avatar
    bpkleer committed
      padding: 8px;
      color: #333333;
      background-color: #FFFFFF;
      font-size: 100%;
      font-weight: initial;
      text-transform: inherit;
      border-top-style: solid;
      border-top-width: 2px;
      border-top-color: #D3D3D3;
      border-bottom-style: solid;
      border-bottom-width: 2px;
      border-bottom-color: #D3D3D3;
      border-left-style: none;
      border-left-width: 1px;
      border-left-color: #D3D3D3;
      border-right-style: none;
      border-right-width: 1px;
      border-right-color: #D3D3D3;
      vertical-align: middle;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_empty_group_heading {
    
    bpkleer's avatar
    bpkleer committed
      padding: 0.5px;
      color: #333333;
      background-color: #FFFFFF;
      font-size: 100%;
      font-weight: initial;
      border-top-style: solid;
      border-top-width: 2px;
      border-top-color: #D3D3D3;
      border-bottom-style: solid;
      border-bottom-width: 2px;
      border-bottom-color: #D3D3D3;
      vertical-align: middle;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_from_md > :first-child {
    
    bpkleer's avatar
    bpkleer committed
      margin-top: 0;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_from_md > :last-child {
    
    bpkleer's avatar
    bpkleer committed
      margin-bottom: 0;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_row {
    
    bpkleer's avatar
    bpkleer committed
      padding-top: 8px;
      padding-bottom: 8px;
      padding-left: 5px;
      padding-right: 5px;
      margin: 10px;
      border-top-style: solid;
      border-top-width: 1px;
      border-top-color: #D3D3D3;
      border-left-style: none;
      border-left-width: 1px;
      border-left-color: #D3D3D3;
      border-right-style: none;
      border-right-width: 1px;
      border-right-color: #D3D3D3;
      vertical-align: middle;
      overflow-x: hidden;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_stub {
    
    bpkleer's avatar
    bpkleer committed
      color: #333333;
      background-color: #FFFFFF;
      font-size: 100%;
      font-weight: initial;
      text-transform: inherit;
      border-right-style: solid;
      border-right-width: 2px;
      border-right-color: #D3D3D3;
      padding-left: 12px;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_summary_row {
    
    bpkleer's avatar
    bpkleer committed
      color: #333333;
      background-color: #FFFFFF;
      text-transform: inherit;
      padding-top: 8px;
      padding-bottom: 8px;
      padding-left: 5px;
      padding-right: 5px;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_first_summary_row {
    
    bpkleer's avatar
    bpkleer committed
      padding-top: 8px;
      padding-bottom: 8px;
      padding-left: 5px;
      padding-right: 5px;
      border-top-style: solid;
      border-top-width: 2px;
      border-top-color: #D3D3D3;
    }
    
    
    bpkleer's avatar
    bpkleer committed
    #jigzjgrlrz .gt_grand_summary_row {
    
    bpkleer's avatar
    bpkleer committed
      color: #333333;
      background-color: #FFFFFF;
      text-transform: inherit;
      padding-top: 8px;
      padding-bottom: 8px;
      padding-left: 5px;