title: ggplot2 stacked bars, 2 bars per X variable
body: <p>Let's say I have 2 subjects. Each did experimental trials and control trials where the outcome for both sets of trials is either 1 or 0. </p>
  
  <p>I want a stacked bar plot that shows the proportion of 1 responses and 0 responses for both types of trials for each subject. </p>
  
  <p>So each subject would have two bars that both reach up to a proportion of 1.00 on the y axis. </p>
  
  <p>Mock data </p>
  
  <pre><code>df1 &lt;- data.frame(Sbj_ID = c(1),
                Trial_Type = c("Testing", "Testing", "Control", "Control"),
                Outcome = c(1, 0, 1, 0),
                Proportion = c(0.41, 0.59, 0.02, 0.98))
  
  df2 &lt;- data.frame(Sbj_ID = c(2),
                Trial_Type = c("Testing", "Testing", "Control", "Control"),
                Outcome = c(1, 0, 1, 0),
                Proportion = c(0.30, 0.70, 0.10, 0.90))
  
  df &lt;- merge(df1, df2, all=TRUE)
  </code></pre>
  
  <p>I want it to look like this type of figure, but with stacked bars</p>
  
  <pre><code>data(iris)
  library(ggplot2)
  library(tidyr)
  
  iris %&gt;%
    gather("Type", "Value",-Species) %&gt;%
    ggplot(aes(Species, Value, fill = Type)) +
    geom_bar(position = "dodge", stat = "identity") 
  </code></pre>
  
  <p>Here are my failed attempts... </p>
  
  <pre><code>library(ggplot2)
  library(tidyr)
  
  # fail 1 
   df $&gt;$
     gather("Outcome", "Proportion", -Sbj_ID) %&gt;%
     ggplot(aes(Sbj_ID, Proporiton, fill = Outcome)) +
     geom_bar(stat = "identity", position = "dodge")
  
  # fail 2 
   ggplot(df, aes( x = factor(Sbj_ID), y = Proportion, fill = Outcome)) +
     geom_bar(stat = "identity", position = "stack") 
  </code></pre>
  
  <p>Any ideas? Thank you in advance!</p>