title: R Plotly overlay bar chart
body: <p>Question in short: using <code>R</code> and the <code>Plotly</code> package, can I create an overlay bar chart where 2 series are shown using the same position on the x-axis? After quite a bit of Googling, I could not find the answer.</p>
  
  <p>For example this visualisation:</p>
  
  <p><a href="https://i.stack.imgur.com/g1XHS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g1XHS.png" alt="enter image description here"></a></p>
  
  <p>Code to create a grouped (not-overlayed) stacked bar, using Plotly and R:</p>
  
  <pre><code>months = 1:12
  n1 = runif(12, min = 0, max = 1)
  n2 = runif(12, min = 0, max = 1)
  dfPlot = data.frame(months, n1, n2)
  
  plot_ly(x = dfPlot [,1],
          y = dfPlot [,2],
          type = 'bar') %&gt;%
  add_trace(x = dfPlot[,1],
            y = dfPlot[,3],
            type = 'bar')
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/KMvGC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KMvGC.png" alt="enter image description here"></a></p>
  
  <p>How can I tweak the chart so that the series overlay? Suggestions on how to visualize the same information in a similar way, but with a different logic are also very much appreciated!</p>