Data is provided at the bottom of the question.
I am trying to use subplot
with plotly
objects which one of them has multiple se
Looking at this issue on github This turned out to be a bug in plotly.
Referencing to the link above, what we need to do is explicitly defining the y axes for all the plots, all the axes. Look below for its implementation on my example:
## Creating axis layouts, explicitly for all y axes
L_Axis <- list(tickfont = list(color = "red"), overlaying = "y",
side = "right", title = "Lft")
F_Axis <- list(side = "left", title = "fmgd")
P_Axis <- list(side = "left", title = "prcp")
pp1 <- fmean1 %>% group_by(grp) %>% plot_ly() %>%
add_lines(x = ~hour, y = ~fmgd, name = "FMGD", colour = "blue") %>%
add_lines(x = ~hour, y = ~lft, name = "Lft", yaxis = "y2", colour = "red") %>%
layout( yaxis = F_Axis, #left axis
yaxis2 = L_Axis, #right axis
title = "Fbay", xaxis = list(title="Date"))
pp2 <- prcpf1 %>% plot_ly() %>%
add_bars(x=~Datetime, y=~precip, name = "prcp", yaxis = "y", colour = "green") %>%
layout(yaxis = P_Axis) #only y axis, on the left
pp <- subplot(pp1, pp2 , nrows = 2 , titleY = T, shareX = T)