title: (Stacked) Barplot with grouping within facet_grid
body: <p>I would like to create a stacked barplot with groupings within a facet grid.
  My Data looks like this:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Sample</th>
  <th>subject</th>
  <th>staging</th>
  <th>Species</th>
  <th>Abundance%</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>sample1</td>
  <td>1</td>
  <td>Patch</td>
  <td>A</td>
  <td>100</td>
  </tr>
  <tr>
  <td>sample2</td>
  <td>1</td>
  <td>Plaque</td>
  <td>B</td>
  <td>50</td>
  </tr>
  <tr>
  <td>sample2</td>
  <td>1</td>
  <td>Plaque</td>
  <td>A</td>
  <td>50</td>
  </tr>
  <tr>
  <td>sample3</td>
  <td>1</td>
  <td>nonlesional</td>
  <td>C</td>
  <td>100</td>
  </tr>
  <tr>
  <td>sample4</td>
  <td>1</td>
  <td>nonlesional</td>
  <td>A</td>
  <td>100</td>
  </tr>
  <tr>
  <td>sample5</td>
  <td>2</td>
  <td>Patch</td>
  <td>A</td>
  <td>100</td>
  </tr>
  <tr>
  <td>sample6</td>
  <td>2</td>
  <td>Patch</td>
  <td>B</td>
  <td>100</td>
  </tr>
  <tr>
  <td>sample7</td>
  <td>2</td>
  <td>nonlesional</td>
  <td>C</td>
  <td>100</td>
  </tr>
  <tr>
  <td>sample8</td>
  <td>2</td>
  <td>nonlesoinal</td>
  <td>A</td>
  <td>100</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I already created <a href="https://i.stack.imgur.com/x4EvZ.jpg" rel="nofollow noreferrer">his stacked barplot with facet_grid</a> using the following code:</p>
  <pre><code>mdf = read.tsv(&quot;XXX.tsv&quot;)
  p = ggplot(mdf, aes_string(x = &quot;Sample&quot;, y = &quot;Abundance&quot;, fill = &quot;Species&quot;)
  p = p + geom_bar(stat = &quot;identity&quot;, position = &quot;stack&quot;, color = &quot;black&quot;)
  p = p + theme(axis.text.x = element_text(angle = -90, hjust = 0))
  p = p + facet_grid(~staging, scales = &quot;free&quot;)
  p
  </code></pre>
  <p>Now I want to reorganize the bars from each sample to the respective subject within the facet_grid to achieve a better overview. E. g., using above example, sample3 and sample4 belong to subject 1 an should be grouped together in the facet &quot;nonlesional&quot; as sample7 and sample8 should be grouped to subject 2 in the same facet.</p>
  <p>I tried several times but did not figuere out how to achieve this.</p>