Skip to contents

Load R package and data

library(ggplot2)
#> Error in get(paste0(generic, ".", class), envir = get_method_env()) : 
#>   object 'type_sum.accel' not found
library(ggRunoff)
#> 
#> Attaching package: 'ggRunoff'
#> The following object is masked from 'package:base':
#> 
#>     %||%

runoff_data$flood_type = c(rep('Flood_1', 400), rep('Flood_2', 344))

head(runoff_data)
#>                  time prcp        Q flood_type
#> 1 2010-05-01 00:00:00    0 73.32857    Flood_1
#> 2 2010-05-01 01:00:00    0 72.77857    Flood_1
#> 3 2010-05-01 02:00:00    0 72.88571    Flood_1
#> 4 2010-05-01 03:00:00    0 73.31429    Flood_1
#> 5 2010-05-01 04:00:00    0 69.79286    Flood_1
#> 6 2010-05-01 05:00:00    0 66.16429    Flood_1

Visualization

set_coef = 15

runoff_data |> 
  ggplot(aes(x=time, Q)) + theme_test() +
  geom_rainfallRunoff(
    aes(runoff=Q, prcp=prcp, color=flood_type), coef=set_coef,
    rainfall.color='#80b1d3', rainfall.fill = '#80b1d3',
    color = 'darkorange', linewidth=0.5
  ) +
  scale_y_precipitation(sec.name = 'Precipitation (mm)', coef = set_coef) +
  facet_wrap(~flood_type, scales = 'free') +
  scale_x_datetime(date_labels = "%m/%d") +
  theme(
    legend.position = c(0, 1),
    legend.justification = c(0, 1),
    legend.background = element_blank(),
    legend.key = element_blank(),
    axis.ticks = element_blank(),
    axis.text.y.left = element_text(color='darkorange'),
    axis.text.y.right = element_text(color='#3e89be'),
    axis.text = element_text(color = 'black'),
    axis.text.x = element_text(angle = 60, hjust = 1),
    axis.title.y.left = element_text(color = 'darkorange'),
    axis.title.y.right =element_text(color = '#3e89be'),
    strip.background = element_blank(),
    strip.text = element_text(face = 'bold', hjust = 0)
  ) +
  labs(x = 'Date', y = expression('Streamflow (m'^'3'*'/s)'))
#> Warning: A numeric `legend.position` argument in `theme()` was deprecated in ggplot2
#> 3.5.0.
#>  Please use the `legend.position.inside` argument of `theme()` instead.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.