我正在尝试生成一个图,该图的顶部绘制了降雨数据,下面绘制了两个位置的水位数据(双Y轴,因为两个位置的范围明显不同。
我已经成功地分别生成了这两个图,但是当使用subplot
时,上方图的第二个水位时间序列图和所有轴标签都丢失了。
非常感谢您的帮助 1.在子图的正确部分上绘制第二个水位时间序列。 2.正确绘制轴标签
#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)