Last active
December 4, 2018 01:17
-
-
Save TonyLadson/a6e450a94f7696617313db1b89fd9c38 to your computer and use it in GitHub Desktop.
Comparing flow peaks at neighbouring stream gauges. See Blog https://tonyladson.wordpress.com/2018/12/04/comparing-peaks-at-stream-gauges/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(scales) | |
library(lubridate) | |
library(ggrepel) | |
# Fifteen Mile Creek and Boggy Ck | |
# | |
# The gauges are: | |
# Fifteen Mile Creek at Greta South (403213) | |
# Boggy Creek at Angleside (403226) | |
# Data obtained from WMIS - Water Measurement Information System | |
# http://data.water.vic.gov.au/monitoring.htm | |
# Data is at | |
# https://drive.google.com/open?id=1afzZH4Vi97_-_5hSdkEEhOvzNgEW2lzL | |
# This provides the min, mean and max flows at the two gauges for a number of years | |
# Fifteen Mile Ck at Greta south 1958 - 2016 | |
# Boggy Creek at Angleside 1968 - 2017 | |
# Read data from google drive --------------------------------------------- | |
id <- "1afzZH4Vi97_-_5hSdkEEhOvzNgEW2lzL" # google file ID | |
flow <- read_csv(sprintf("https://docs.google.com/uc?id=%s&export=download", id), | |
skip = 20, | |
col_names = FALSE) | |
# Process the file | |
flow <- flow %>% | |
select(c(1,6,12)) %>% # Select date, annual max for each gauge | |
rename(xdatetime = X1, # year of maximum | |
Fifteen_mile = X6, # Annual maximum | |
Boggy = X12) %>% # Annual maximum | |
mutate(xdatetime = lubridate::dmy_hm(xdatetime)) %>% # convert the date to R format | |
mutate(xyear = lubridate::year(xdatetime)) # extract the year from the date | |
# Time series barplot | |
p <- flow %>% | |
select(xyear, Fifteen_mile, Boggy) %>% | |
filter(xyear %in% c(1980:1990)) %>% | |
gather(-xyear, key = 'Creek', value = 'annual_peak') %>% | |
ggplot(aes(x = factor(xyear), y = annual_peak, fill = Creek)) + | |
geom_bar(stat = 'identity', position = 'dodge') + | |
scale_fill_hue(name = NULL, l = 40, labels = c('Boggy Ck', 'Fifteen Mile Ck')) + | |
scale_x_discrete(name = 'Year') + | |
scale_y_continuous(name = 'Annual peak flow (ML/d)', labels = scales::comma) + | |
theme(legend.position = c(0.9, 0.9)) + | |
theme(legend.position = 'bottom', text = element_text(size = 8)) | |
p | |
#ggsave("../figures/peak_barplot.png", p, width=4, height=3) | |
# Points representing paires of values | |
p2 <- flow %>% | |
filter(xyear %in% c(1980:1990)) %>% # extract a sub-set of the data | |
ggplot(aes(x = Fifteen_mile, y = Boggy)) + | |
#geom_line() + | |
geom_point(size = 1) + | |
geom_abline(slope = 1, intercept = 0, linetype = 'dashed', alpha = 0.3) + | |
scale_x_continuous(name = 'Fifteen Mile Ck (ML/d)', labels = comma, limits = c(0,11000)) + | |
scale_y_continuous(name = 'Boggy Ck (ML/d)', labels = comma, limits = c(0,11000)) + | |
geom_text_repel(aes(label = xyear), size = 2, min.segment.length = 0.2, segment.size = 0.2) + | |
theme(text = element_text(size = 8)) | |
p2 | |
#ggsave("../figures/peak_pair_comparison.png", p2, width=4, height=3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment