This is a general-purpose hydrograph plotting function, which is useful for a wide variety of tasks. Currently the function only uses base R plotting, but the addition of ggplot2 graphs is planned for the future. The function can plot any of: observed flows, simulated flows, inflows to a sub-basin, and precipitation on the same graph. The plots can indicate the winter period (which is fixed), and options exist to change the scales and y-axis label.
Note that the value returned by the function, if successful, is TRUE
<- CAN05AA008[, c(3, 4)]
daily_flows <- ch_hydrograph_plot(flows = daily_flows, winter_shading = FALSE) result1
<- ch_hydrograph_plot(flows = daily_flows, winter_shading = TRUE) result2
The period of the plot can be restricted by setting the option prd, nwhich is a string like “2011-10- 01/2012-09-30” indicating the beginning and end dates of the plot.
<- "2000-01-01/2000-12-31"
myprd <- ch_hydrograph_plot(
result3 flows = daily_flows, winter_shading = TRUE,
prd = myprd
)
You can also plot precipitation data. In this example fake precipitation data are used.
<- data.frame("Date" = daily_flows$Date, "precip" = abs(rnorm(nrow(daily_flows))) * 10)
precip <- ch_hydrograph_plot(
result4 flows = daily_flows, precip = precip, winter_shading = TRUE,
prd = myprd
)
The axes of the precipitation and flow can be modified as needed to prevent overlap of the two series, if desired. The default is to multiply the precipitation range by 1.5 of the maximum value, however the range can be multiplied by any positive value to prevent this.
<- ch_hydrograph_plot(
result5 flows = daily_flows, precip = precip, winter_shading = TRUE,
prd = myprd, range_mult_precip = 2, range_mult_flow = 1.8
)
Only the default y-axis label can be over-ridden. Note that you can use a Unicode character or an expression to get a superscripted 3.
<- expression(paste("Discharge [m"^"3", "/s]"))
ylab <- ch_hydrograph_plot(
result6 flows = daily_flows, precip = precip,
prd = myprd, ylabel = ylab
)
The precipitation label can also be adjusted.
<- "Rainfall [mm]"
ylab_precip <- ch_hydrograph_plot(
result7 flows = daily_flows, precip = precip,
prd = myprd, precip_label = ylab_precip
)
Many other formatting options exist, such as:
For example:
<- ch_hydrograph_plot(
result8 flows = daily_flows, precip = precip,
prd = myprd, leg_pos = "right"
# change legend to the right side )
<- ch_hydrograph_plot(
result9 flows = daily_flows, precip = precip,
prd = myprd, leg_box = TRUE
# add legend fill and outline )
<- ch_hydrograph_plot(
result10 flows = daily_flows, precip = precip,
prd = myprd, zero_axis = F
# default plot outside of function with buffer around axis )