Skip to content

Instantly share code, notes, and snippets.

@TonyLadson
Last active July 24, 2026 07:11
Show Gist options
  • Select an option

  • Save TonyLadson/4f8c20c6c5c2dd6a95b5 to your computer and use it in GitHub Desktop.

Select an option

Save TonyLadson/4f8c20c6c5c2dd6a95b5 to your computer and use it in GitHub Desktop.
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)
@LCroninATU

Copy link
Copy Markdown

Is it possible to include a sample of the datasets head first 3 rows would be great as links aren't working for the sample files? Thanks

@TonyLadson

Copy link
Copy Markdown
Author

I've changed the script to read in sample files from google drive. Which now works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment