Skip to content

Instantly share code, notes, and snippets.

@TonyLadson
Created February 22, 2016 10:43
Show Gist options
  • Save TonyLadson/87101c97dd5054e63210 to your computer and use it in GitHub Desktop.
Save TonyLadson/87101c97dd5054e63210 to your computer and use it in GitHub Desktop.
Plot annual maximum data from http://data.water.vic.gov.au/monitoring.htm.
# This script takes the standard download of annual max, min, mean data from
# http://data.water.vic.gov.au/monitoring.htm
# Plots a bar plot with ggplot
library(stringr)
library(dplyr)
library(lubridate)
library(ggplot2)
library(devtools)
library(scales)
library(repmis)
# Source my preferred ggplot Theme see
# see https://gist.github.com/TonyLadson/cc60bbb3cbadf0e72619
devtools::source_gist('cc60bbb3cbadf0e72619')
# Download sample data
flow <- tbl_df(source_data('https://dl.dropboxusercontent.com/u/10963448/CreswickCk%40Clunes-407214.csv', skip = 16, stringsAsFactors = FALSE))
names(flow) <- c('date.time', 'flow.mean', 'flow.mean.qc', 'flow.min', 'flow.min.qc', 'flow.max', 'flow.max.qc')
# parse dates
flow <- flow %>%
mutate(date.time = parse_date_time(date.time, orders = 'dmy H:M:S'))
# First and last dates
flow %>%
summarise(max(date.time), min(date.time))
# plot
flow %>%
ggplot(aes(x = date.time, y = flow.max)) + geom_bar(stat = 'identity') + BwTheme +
scale_x_datetime(name = 'Date', limits = c(ymd('1943-01-01'), ymd('2016-01-01')), date_breaks = '2 year', date_labels = "%Y") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5)) +
scale_y_continuous(name = 'Discharge (cumec)', labels = comma) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment