title: Combining both grouped bar chart and stacked bar chart using R Plotly
body: <p>I am trying to combine both stacked bar and grouped bar chart using <code>plot_ly()</code>. I came across a few questions but couldn't get the perfect solution for this scenario.</p>
  <p>I came across the <a href="https://stackoverflow.com/questions/46597278/how-to-plot-a-stacked-and-grouped-bar-chart-in-ggplot">solution</a> using <code>ggplot2</code>. But I need to implement using <code>plot_ly</code></p>
  <p>This is the data frame I am trying to plot</p>
  <pre><code>structure(list(QuarterYear = c(&quot;Q4 2019&quot;, &quot;Q4 2019&quot;, &quot;Q4 2019&quot;, 
  &quot;Q4 2019&quot;, &quot;Q4 2019&quot;, &quot;Q4 2019&quot;, &quot;Q4 2019&quot;, &quot;Q4 2019&quot;, &quot;Q4 2019&quot;, 
  &quot;Q4 2019&quot;, &quot;Q4 2019&quot;, &quot;Q4 2019&quot;, &quot;Q1 2020&quot;, &quot;Q1 2020&quot;, &quot;Q1 2020&quot;, 
  &quot;Q1 2020&quot;, &quot;Q1 2020&quot;, &quot;Q1 2020&quot;, &quot;Q1 2020&quot;, &quot;Q1 2020&quot;, &quot;Q1 2020&quot;, 
  &quot;Q1 2020&quot;, &quot;Q1 2020&quot;, &quot;Q1 2020&quot;, &quot;Q2 2020&quot;, &quot;Q2 2020&quot;, &quot;Q2 2020&quot;, 
  &quot;Q2 2020&quot;, &quot;Q2 2020&quot;, &quot;Q2 2020&quot;, &quot;Q2 2020&quot;, &quot;Q2 2020&quot;, &quot;Q2 2020&quot;, 
  &quot;Q2 2020&quot;, &quot;Q2 2020&quot;, &quot;Q2 2020&quot;, &quot;Q3 2020&quot;, &quot;Q3 2020&quot;, &quot;Q3 2020&quot;, 
  &quot;Q3 2020&quot;, &quot;Q3 2020&quot;, &quot;Q3 2020&quot;, &quot;Q3 2020&quot;, &quot;Q3 2020&quot;, &quot;Q3 2020&quot;, 
  &quot;Q3 2020&quot;, &quot;Q3 2020&quot;, &quot;Q3 2020&quot;), Grade = c(&quot;Grade 8&quot;, &quot;Grade 8&quot;, 
  &quot;Grade 8&quot;, &quot;Grade 9&quot;, &quot;Grade 9&quot;, &quot;Grade 9&quot;, &quot;Grade 10&quot;, &quot;Grade 10&quot;, 
  &quot;Grade 10&quot;, &quot;Grade 11&quot;, &quot;Grade 11&quot;, &quot;Grade 11&quot;, &quot;Grade 8&quot;, &quot;Grade 8&quot;, 
  &quot;Grade 8&quot;, &quot;Grade 9&quot;, &quot;Grade 9&quot;, &quot;Grade 9&quot;, &quot;Grade 10&quot;, &quot;Grade 10&quot;, 
  &quot;Grade 10&quot;, &quot;Grade 11&quot;, &quot;Grade 11&quot;, &quot;Grade 11&quot;, &quot;Grade 8&quot;, &quot;Grade 8&quot;, 
  &quot;Grade 8&quot;, &quot;Grade 9&quot;, &quot;Grade 9&quot;, &quot;Grade 9&quot;, &quot;Grade 10&quot;, &quot;Grade 10&quot;, 
  &quot;Grade 10&quot;, &quot;Grade 11&quot;, &quot;Grade 11&quot;, &quot;Grade 11&quot;, &quot;Grade 8&quot;, &quot;Grade 8&quot;, 
  &quot;Grade 8&quot;, &quot;Grade 9&quot;, &quot;Grade 9&quot;, &quot;Grade 9&quot;, &quot;Grade 10&quot;, &quot;Grade 10&quot;, 
  &quot;Grade 10&quot;, &quot;Grade 11&quot;, &quot;Grade 11&quot;, &quot;Grade 11&quot;), Type = c(&quot;overallAverage&quot;, 
  &quot;CT&quot;, &quot;RT&quot;, &quot;overallAverage&quot;, &quot;CT&quot;, &quot;RT&quot;, &quot;overallAverage&quot;, &quot;CT&quot;, 
  &quot;RT&quot;, &quot;overallAverage&quot;, &quot;CT&quot;, &quot;RT&quot;, &quot;overallAverage&quot;, &quot;CT&quot;, &quot;RT&quot;, 
  &quot;overallAverage&quot;, &quot;CT&quot;, &quot;RT&quot;, &quot;overallAverage&quot;, &quot;CT&quot;, &quot;RT&quot;, &quot;overallAverage&quot;, 
  &quot;CT&quot;, &quot;RT&quot;, &quot;overallAverage&quot;, &quot;CT&quot;, &quot;RT&quot;, &quot;overallAverage&quot;, &quot;CT&quot;, 
  &quot;RT&quot;, &quot;overallAverage&quot;, &quot;CT&quot;, &quot;RT&quot;, &quot;overallAverage&quot;, &quot;CT&quot;, &quot;RT&quot;, 
  &quot;overallAverage&quot;, &quot;CT&quot;, &quot;RT&quot;, &quot;overallAverage&quot;, &quot;CT&quot;, &quot;RT&quot;, &quot;overallAverage&quot;, 
  &quot;CT&quot;, &quot;RT&quot;, &quot;overallAverage&quot;, &quot;CT&quot;, &quot;RT&quot;), value = c(2.48, 2.21, 
  0.27, 3.48, 3.03, 0.45, 4.6, 4, 0.6, 2.8, 2.4, 0.4, 2.54, 2.28, 
  0.26, 3.45, 3, 0.45, 4.46, 3.88, 0.58, 3.56, 2.81, 0.75, 2.47, 
  2.14, 0.33, 2.96, 2.54, 0.41, 4.1, 3.69, 0.41, 3.44, 2.61, 0.83, 
  2, 1.81, 0.19, 2.54, 2.26, 0.28, 4.11, 3.68, 0.43, 2.67, 2.11, 
  0.56)), row.names = c(NA, -48L), class = &quot;data.frame&quot;)
  </code></pre>
  <p>I am aware that we need to define the <code>barmode</code> as <code>stack</code> for stacked bar and <code>group</code> for grouped bar chart. I'm not aware of now to combine these <code>barmode</code> in one single plot using <code>plot_ly</code></p>
  <p>Can anyone provide a suitable solution in R?</p>
  <p>Thanks in advance!!</p>