Last active
July 24, 2026 07:11
-
-
Save TonyLadson/4f8c20c6c5c2dd6a95b5 to your computer and use it in GitHub Desktop.
Plot sampled concentrations on a hydrograph see https://tonyladson.wordpress.com/2016/01/11/plotting-water-quality-samples-on-a-hydrograph/
This file contains hidden or 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(dplyr) | |
| library(ggplot2) | |
| library(grid) | |
| library(scales) | |
| # download sample files from google drive | |
| file_id <- "1a5ksZpQbuAnbC6oNEBe8RJO4Z1L2HEic" | |
| url <- sprintf("https://docs.google.com/uc?id=%s&export=download", file_id) | |
| wq <- read.csv(url) | |
| file_id <- "1CInezMIto1zeK1qVfmjYv36Zd3WEAzBR" | |
| url <- sprintf("https://docs.google.com/uc?id=%s&export=download", file_id) | |
| flow <- read.csv(url) | |
| # parse the dates | |
| wq$Date <- as.Date(wq$Date) | |
| flow$Date <- as.Date(flow$Date) | |
| # join flows onto the water quality data | |
| wq <- left_join(wq, flow) | |
| # plot | |
| p <- ggplot(data = flow, aes(Date, Discharge)) + | |
| geom_line() + # plot the hydrograph | |
| geom_point(data = wq, aes(Date, Discharge, color = Total.N), size = 5) + # overlay the concentrations | |
| scale_color_continuous(low = 'green', high = 'red', name = 'Total N (mg/L)') + | |
| scale_y_continuous(labels = comma, name = 'Discharge (ML/d)') + | |
| theme_bw() + # beautify | |
| theme( | |
| panel.background = element_rect(fill="gray98"), | |
| axis.title.x = element_text(colour="grey20", size=20, vjust = -2), | |
| axis.text.x = element_text(colour="grey20",size=12), | |
| axis.title.y = element_text(colour="grey20",size=20, vjust = 2), | |
| axis.text.y = element_text(colour="grey20",size=12), | |
| legend.title = element_text(colour="grey20",size=12), | |
| plot.margin = unit(c(2.5, 2.5, 2.5, 2.5), "cm")) | |
| print(p) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've changed the script to read in sample files from google drive. Which now works.