title: Grouped stacked bar chart in ggplot2 where each stack corresponds to its y axis value
body: <p>I am wondering if my request is possible in ggplot2. </p>
  
  <p>I am looking to enhance a bar plot where I group two bars by hour (1:24) corresponding to model1 and model2's error measured in MAPE (mean absolute percentage error), where hours are the x axis and MAPE is plotted on the y axis. </p>
  
  <p>The chart I explained is simple and informative, but the enhancement I am looking to do is fill each bar with MAPE by Date. Date is the fourth column in my data frame. I would like the fill to correspond to the MAPE value model1 or model2 produced on a given date. </p>
  
  <p>All I have been able to plot so far is each date that makes up the total MAPE calculation in a given model's bar. It is informative in the sense that it shows which dates were used in the error calculation, but it does not tell the viewer which dates were responsible for the least/greatest model error. </p>
  
  <p>I pasted my data at the bottom of the post to avoid clutter. Here are my results so far:</p>
  
  <p>My first attempt with facet_grid resulted in this:</p>
  
  <pre><code>ggplot(Hourly_compare, aes(x = Hour, y = MAPE, fill = as.factor(Date)))+
    geom_bar(position= "stack", stat = "identity") + facet_grid(~ Model)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/9yuIH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9yuIH.png" alt="enter image description here"></a></p>
  
  <p>As you can see, each date's fill is the same length in each bar. I would like the date's fill to correspond to the MAPE value for that given date.</p>
  
  <p>My second attempt produced this gnarly chart:</p>
  
  <pre><code>ggplot(Hourly_compare, aes(x = Hour, y = MAPE, fill = as.factor(Date), color = Model))+
    geom_bar(position= "stack", stat = "identity") +
    scale_color_manual(values=c("Model1"="red", "Model2"="black"))+
    scale_x_continuous(breaks = c(1:24))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/AnSm5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AnSm5.png" alt="enter image description here"></a></p>
  
  <p>This is more ideal for me as I would like to keep each model's results grouped together by hour as separate bars, but I would like the bars to be stacked with each date's model errors corresponding to their MAPE value. </p>
  
  <p>Here is my data:</p>
  
  <pre><code>Hourly_compare &lt;- dput(Hourly_compare)
  structure(list(Date = structure(c(18405, 18405, 18405, 18405, 
  18405, 18405, 18405, 18405, 18405, 18405, 18405, 18405, 18405, 
  18405, 18405, 18405, 18405, 18405, 18405, 18405, 18405, 18405, 
  18405, 18405, 18405, 18405, 18405, 18405, 18405, 18405, 18405, 
  18405, 18405, 18405, 18405, 18405, 18405, 18405, 18405, 18405, 
  18405, 18405, 18405, 18405, 18405, 18405, 18405, 18405, 18412, 
  18412, 18412, 18412, 18412, 18412, 18412, 18412, 18412, 18412, 
  18412, 18412, 18412, 18412, 18412, 18412, 18412, 18412, 18412, 
  18412, 18412, 18412, 18412, 18412, 18412, 18412, 18412, 18412, 
  18412, 18412, 18412, 18412, 18412, 18412, 18412, 18412, 18412, 
  18412, 18412, 18412, 18412, 18412, 18412, 18412, 18412, 18412, 
  18412, 18412, 18419, 18419, 18419, 18419, 18419, 18419, 18419, 
  18419, 18419, 18419, 18419, 18419, 18419, 18419, 18419, 18419, 
  18419, 18419, 18419, 18419, 18419, 18419, 18419, 18419, 18419, 
  18419, 18419, 18419, 18419, 18419, 18419, 18419, 18419, 18419, 
  18419, 18419, 18419, 18419, 18419, 18419, 18419, 18419, 18419, 
  18419, 18419, 18419, 18419, 18419), class = "Date"), Hour = c(1, 
  1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 
  11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 
  19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 1, 1, 2, 2, 3, 3, 
  4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 
  13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 
  21, 22, 22, 23, 23, 24, 24, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 
  6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 
  15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 
  23, 23, 24, 24), Model = c("Model1", "Model2", "Model1", "Model2", 
  "Model1", "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", 
  "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", "Model2", 
  "Model1", "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", 
  "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", "Model2", 
  "Model1", "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", 
  "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", "Model2", 
  "Model1", "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", 
  "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", "Model2", 
  "Model1", "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", 
  "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", "Model2", 
  "Model1", "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", 
  "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", "Model2", 
  "Model1", "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", 
  "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", "Model2", 
  "Model1", "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", 
  "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", "Model2", 
  "Model1", "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", 
  "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", "Model2", 
  "Model1", "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", 
  "Model2", "Model1", "Model2", "Model1", "Model2", "Model1", "Model2"
  ), MAPE = c(0.45, 1.33, 0.41, 1.17, 0.4, 1.23, 0.45, 1.32, 0.45, 
  1.48, 0.62, 1.82, 0.7, 1.69, 0.69, 1.16, 1.37, 1.56, 1.56, 1.48, 
  1.64, 1.42, 1.48, 1.45, 1.23, 1.42, 1.18, 1.66, 1.22, 1.8, 1.36, 
  2.21, 1.61, 2.5, 1.99, 2.87, 1.93, 2.55, 2.01, 2.61, 1.82, 2.75, 
  1.92, 2.53, 1.71, 2.31, 1.5, 2.04, 0.45, 1.33, 0.41, 1.17, 0.4, 
  1.23, 0.45, 1.32, 0.45, 1.48, 0.62, 1.82, 0.7, 1.69, 0.69, 1.16, 
  1.37, 1.56, 1.56, 1.48, 1.64, 1.42, 1.48, 1.45, 1.23, 1.42, 1.18, 
  1.66, 1.22, 1.8, 1.36, 2.21, 1.61, 2.5, 1.99, 2.87, 1.93, 2.55, 
  2.01, 2.61, 1.82, 2.75, 1.92, 2.53, 1.71, 2.31, 1.5, 2.04, 0.45, 
  1.33, 0.41, 1.17, 0.4, 1.23, 0.45, 1.32, 0.45, 1.48, 0.62, 1.82, 
  0.7, 1.69, 0.69, 1.16, 1.37, 1.56, 1.56, 1.48, 1.64, 1.42, 1.48, 
  1.45, 1.23, 1.42, 1.18, 1.66, 1.22, 1.8, 1.36, 2.21, 1.61, 2.5, 
  1.99, 2.87, 1.93, 2.55, 2.01, 2.61, 1.82, 2.75, 1.92, 2.53, 1.71, 
  2.31, 1.5, 2.04)), row.names = c(NA, -144L), groups = structure(list(
      Date = structure(c(18405, 18405, 18405, 18405, 18405, 18405, 
      18405, 18405, 18405, 18405, 18405, 18405, 18405, 18405, 18405, 
      18405, 18405, 18405, 18405, 18405, 18405, 18405, 18405, 18405, 
      18412, 18412, 18412, 18412, 18412, 18412, 18412, 18412, 18412, 
      18412, 18412, 18412, 18412, 18412, 18412, 18412, 18412, 18412, 
      18412, 18412, 18412, 18412, 18412, 18412, 18419, 18419, 18419, 
      18419, 18419, 18419, 18419, 18419, 18419, 18419, 18419, 18419, 
      18419, 18419, 18419, 18419, 18419, 18419, 18419, 18419, 18419, 
      18419, 18419, 18419), class = "Date"), Hour = c(1, 2, 3, 
      4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 
      20, 21, 22, 23, 24, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 
      13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 1, 2, 3, 
      4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 
      20, 21, 22, 23, 24), .rows = list(1:2, 3:4, 5:6, 7:8, 9:10, 
          11:12, 13:14, 15:16, 17:18, 19:20, 21:22, 23:24, 25:26, 
          27:28, 29:30, 31:32, 33:34, 35:36, 37:38, 39:40, 41:42, 
          43:44, 45:46, 47:48, 49:50, 51:52, 53:54, 55:56, 57:58, 
          59:60, 61:62, 63:64, 65:66, 67:68, 69:70, 71:72, 73:74, 
          75:76, 77:78, 79:80, 81:82, 83:84, 85:86, 87:88, 89:90, 
          91:92, 93:94, 95:96, 97:98, 99:100, 101:102, 103:104, 
          105:106, 107:108, 109:110, 111:112, 113:114, 115:116, 
          117:118, 119:120, 121:122, 123:124, 125:126, 127:128, 
          129:130, 131:132, 133:134, 135:136, 137:138, 139:140, 
          141:142, 143:144)), row.names = c(NA, -72L), class = c("tbl_df", 
  "tbl", "data.frame")), class = c("grouped_df", "tbl_df", "tbl", 
  "data.frame"))
  </code></pre>
  
  <p>Any help is much appreciated! Thank you. </p>