R programming Plotly bar chart grouped bars with multiple y axis
<p>I am trying to do a grouped bar chart with two different <code>Y axis</code> for measure two different columns. Here is the data:</p>

<pre><code>SUCURSAL         EXISTENCIA         COSTO_MEDIO
0 MELENARA        0.128                643.2
1 LAS TORRES      1.872                659.2
2 GALDAR          0.304                659.2
3 SEBADAL         0.851                623.8
4 ARINAGA         0.176                620.4
5 LANZAROTE       0.232                686.4
6 FUERTEVENTURA   0.480                680.2
</code></pre>

<p>and here is my code:</p>

<pre><code>ay &lt;- list(
          tickfont = list(color = "red"),
          overlaying = "y1", 
          side = "right"
        )

p &lt;- plot_ly(dfplot, x = dfplot$SUCURSAL, y = dfplot$EXISTENCIA, type = "bar", opacity = 0.4, name = 'EXISTENCIA', yaxis = "y1") %&gt;%
          add_trace(x = dfplot$SUCURSAL, y = dfplot$COSTO_MEDIO, type = "bar", name = 'COSTO', yaxis = "y2") %&gt;%
          layout( xaxis = list(title = ""), yaxis = list(title = "", tickfont= list(size = 10, color = "black"), showticklabels = TRUE), yaxis2= ay, barmode = 'group' )  %&gt;%
          config(displayModeBar = F)


p
</code></pre>

<p>The problem I have is that the two groups of bars are overlayed. It is impossible for me to see it grouped, aside each other. How can I represent it with the two groups of bars?</p>

<p>Any idea?</p>