title: How to create facet plot from hierarchically grouped data frame
body: <p>I have the following tibbles <code>s12.tbl</code> and <code>ref.tbl</code>.</p>
  
  <p>
  <br/></p>
  
  <pre class="lang-r prettyprint-override"><code>s12.tbl &lt;- structure(list(Sample_name = c("s1", "s2", "s1", "s2", "s1", 
  "s2", "s1", "s2", "s1", "s2", "s1", "s2", "s1", "s2", "s1", "s2", 
  "s1", "s2", "s1", "s2"), some_score = c("0.04741", "0.09293", 
  "0.06210", "0.09838", "0.09606", "0.09866", "0.08851", "0.10866", 
  "0.05063", "0.09726", "0.39775", "0.10731", "0.05509", "0.09866", 
  "0.10784", "0.09398", "0.04680", "0.10007", "0.04782", "0.10408"
  ), category = c("real", "real", "real", "real", "real", "real", 
  "real", "real", "real", "real", "real", "real", "real", "real", 
  "real", "real", "real", "real", "real", "real")), .Names = c("Sample_name", 
  "some_score", "category"), class = c("tbl_df", "tbl", "data.frame"
  ), row.names = c(NA, -20L))
  s12.tbl
  #&gt;    Sample_name some_score category
  #&gt; 1           s1    0.04741     real
  #&gt; 2           s2    0.09293     real
  #&gt; 3           s1    0.06210     real
  #&gt; 4           s2    0.09838     real
  #&gt; 5           s1    0.09606     real
  #&gt; 6           s2    0.09866     real
  #&gt; 7           s1    0.08851     real
  #&gt; 8           s2    0.10866     real
  #&gt; 9           s1    0.05063     real
  #&gt; 10          s2    0.09726     real
  #&gt; 11          s1    0.39775     real
  #&gt; 12          s2    0.10731     real
  #&gt; 13          s1    0.05509     real
  #&gt; 14          s2    0.09866     real
  #&gt; 15          s1    0.10784     real
  #&gt; 16          s2    0.09398     real
  #&gt; 17          s1    0.04680     real
  #&gt; 18          s2    0.10007     real
  #&gt; 19          s1    0.04782     real
  #&gt; 20          s2    0.10408     real
  
  ref.tbl &lt;- structure(list(Sample_name = c("K1", "K2", "K3", "K1", "K2", 
  "K3", "K1", "K2", "K3", "K1", "K2", "K3", "K1", "K2", "K3", "K1", 
  "K2", "K3", "K1", "K2", "K3", "K1", "K2", "K3", "K1", "K2", "K3", 
  "K1", "K2", "K3"), some_score = c(0.09651, 0.09787, 0.09526, 
  0.09543, 0.09479, 0.09435, 0.09122, 0.09123, 0.09024, 0.09458, 
  0.09478, 0.09299, 0.09382, 0.0945, 0.09285, 0.10158, 0.10127, 
  0.09889, 0.10339, 0.10476, 0.1037, 0.13594, 0.13257, 0.14651, 
  0.09458, 0.09473, 0.09325, 0.09296, 0.0935, 0.09196), category = c("fake", 
  "fake", "fake", "fake", "fake", "fake", "fake", "fake", "fake", 
  "fake", "fake", "fake", "fake", "fake", "fake", "fake", "fake", 
  "fake", "fake", "fake", "fake", "fake", "fake", "fake", "fake", 
  "fake", "fake", "fake", "fake", "fake")), .Names = c("Sample_name", 
  "some_score", "category"), class = c("tbl_df", "tbl", "data.frame"
  ), row.names = c(NA, -30L))
  ref.tbl
  #&gt;    Sample_name some_score category
  #&gt; 1           K1    0.09651     fake
  #&gt; 2           K2    0.09787     fake
  #&gt; 3           K3    0.09526     fake
  #&gt; 4           K1    0.09543     fake
  #&gt; 5           K2    0.09479     fake
  #&gt; 6           K3    0.09435     fake
  #&gt; 7           K1    0.09122     fake
  #&gt; 8           K2    0.09123     fake
  #&gt; 9           K3    0.09024     fake
  #&gt; 10          K1    0.09458     fake
  #&gt; 11          K2    0.09478     fake
  #&gt; 12          K3    0.09299     fake
  #&gt; 13          K1    0.09382     fake
  #&gt; 14          K2    0.09450     fake
  #&gt; 15          K3    0.09285     fake
  #&gt; 16          K1    0.10158     fake
  #&gt; 17          K2    0.10127     fake
  #&gt; 18          K3    0.09889     fake
  #&gt; 19          K1    0.10339     fake
  #&gt; 20          K2    0.10476     fake
  #&gt; 21          K3    0.10370     fake
  #&gt; 22          K1    0.13594     fake
  #&gt; 23          K2    0.13257     fake
  #&gt; 24          K3    0.14651     fake
  #&gt; 25          K1    0.09458     fake
  #&gt; 26          K2    0.09473     fake
  #&gt; 27          K3    0.09325     fake
  #&gt; 28          K1    0.09296     fake
  #&gt; 29          K2    0.09350     fake
  #&gt; 30          K3    0.09196     fake
  </code></pre>
  
  <p>I have no problem creating one ECDF plot for <code>s1</code> in s12.tbl using this code:</p>
  
  <pre class="lang-r prettyprint-override"><code>library(dplyr)
  library(ggplot)
  
  # Here we only pick S1, 
  s1.tbl &lt;- s12.tbl %&gt;% filter(Sample_name=="s1")
  s1.tbl &lt;- s1.tbl %&gt;% 
         mutate(some_score=some_score %&gt;% as.numeric)
  
  ref.tbl &lt;- ref.tbl %&gt;% 
         mutate(some_score=some_score %&gt;% as.numeric) %&gt;% 
         setNames(c("Sample_name", "some_score","category"))
  
  dat &lt;- rbind(s1.tbl, ref.tbl)
  
  
  ggplot(dat, aes(x = some_score)) +
      stat_ecdf(aes(group = Sample_name, colour = category, alpha=category)) +
      scale_alpha_discrete(range = c(0.5, 1)) +
      scale_color_manual(values = c("black","red")) +
      theme_minimal(base_size=15) +
      theme(legend.title=element_blank()) +
      theme(axis.text.x=element_text(angle=45, hjust=1,size=15)) +
      theme(axis.text.y=element_text( hjust=1,size=10)) +
      ylab("ECDF")  +
      xlab("Score")
  </code></pre>
  
  <p>Which produces this:<a href="https://i.stack.imgur.com/dB3gS.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dB3gS.jpg" alt="enter image description here"></a></p>
  
  <p>My question is how can I make the facet wrap version of that to include <code>s1</code> and <code>s2</code> from <code>s12.tbl</code>?</p>