I am trying to do a grouped bar chart with two different Y axis
for measure two different columns. Here is the data:
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
and here is my code:
ay <- list(
tickfont = list(color = "red"),
overlaying = "y1",
side = "right"
)
p <- plot_ly(dfplot, x = dfplot$SUCURSAL, y = dfplot$EXISTENCIA, type = "bar", opacity = 0.4, name = 'EXISTENCIA', yaxis = "y1") %>%
add_trace(x = dfplot$SUCURSAL, y = dfplot$COSTO_MEDIO, type = "bar", name = 'COSTO', yaxis = "y2") %>%
layout( xaxis = list(title = ""), yaxis = list(title = "", tickfont= list(size = 10, color = "black"), showticklabels = TRUE), yaxis2= ay, barmode = 'group' ) %>%
config(displayModeBar = F)
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?
Any idea?