Dual Y-Axis and subplot using Plotly
I am trying to generate a plot that has rainfall data plotted at the top and water level data at two locations plotted below (with a dual Y-Axis as the ranges of the two locations are significantly different.
I have successfully generated these two plots individually, but when using
subplot, the second water level time series plots on the upper graph, and all axes labels are missing.
I'd appreciate help with 1. Plotting the second water level time series on the correct part of the subplot. 2. Plotting the axis labels correctly
#Set up left X axis ay <- list( title = "Stream Level (cm)", zeroline = TRUE, showgrid = FALSE, range=c(0,30) ) #Set up right Y axis by <- list( tickfont = list(color = "red"), overlaying = "y", side = "right", title = "Bund Level (cm)", tick = 0, zeroline = TRUE, showgrid = FALSE, range=c(0,80) ) #Plot water levels p_30 <- ms_merged_30 %>% plot_ly() %>% add_lines(x = ~date, y = ~MS1_cm, name = "Stream_1 Level") %>% add_lines(x = ~date, y = ~MS2_cm, name = "Stream_2 Level", yaxis = "y2") %>% layout( title = "", yaxis = ay, yaxis2 = by, xaxis = list(title="x") ) #Plot rainfall rain_plot <- rain_data %>% plot_ly(type = "bar") %>% add_bars(x = ~DateTime, y = ~Rainfall, name = "Rainfall") #Make subplot to combine hydrograph and hyteograph combined_plot <- subplot(rain_plot, p_30, nrows = 2, heights = c(0.3,0.7), shareX = TRUE)