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
setwd("~/Documents/code/francesca") | |
library(TSAgg) | |
quality<-read.csv("Burke_worked.csv",header=T) | |
head(quality) | |
q2<-timeSeries(quality$date,"%d/%m/%Y %H:%M") |
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
##################################################################################################### | |
### Aim: To test the significance of randomly allocating flow to 'midnight' water quality samples. | |
### Date Created: Thursday 2nd September 2010 | |
### Author: Jason Lessels | |
### Packages required: TSAgg_0.2-1,geoR | |
### Notes: The script can easily be modified for the other water quality parameters, and the amount of simulations. Things to check: | |
###Both WQ and discharge must have the same initial time stamp (hours) before aggregation. | |
###WQ variable modify lines 52,60,146,186 | |
###line 99 changes the amount of simulations to run. | |
###line 156 determines when the bushfire occurred. |
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
piper <- | |
function (data, group = NULL, colours = NULL, pch = NULL, numbersymbols = FALSE, | |
X = 300, ...) | |
{ | |
p <- (X/11) | |
q <- (X/22) | |
over100 <- data[data$Ca + data$Mg > 100 | data$Cl + data$SO4 > | |
100, ] | |
if (length(over100[, 1]) != 0) { | |
print("ERROR") |
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
### A piper diagram based on the ternary plot example here: http://srmulcahy.github.io/2012/12/04/ternary-plots-r.html | |
### This was written quickly, and most likely contains bugs - I advise you to check it first. | |
### Jason Lessels [email protected] | |
### This now consists of two functions. transform_piper_data transforms the data to match | |
### the coordinates of the piper diagram. ggplot_piper does all of the background. | |
transform_piper_data <- function(Mg, Ca, Cl,SO4, name=NULL){ | |
if(is.null(name)){ |
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
### simulate some dates | |
dates <- seq.Date(as.Date("2014-01-01"), as.Date("2014-12-31"), by = "1 day") | |
### simulate some rainfall | |
rain <- sample(c(0,0,0,2,3), length(dates), replace=T) | |
data <- data.frame(date = dates, | |
daily_precip = rain) | |
# Use a rolling apply function to check the rainfall of the last 3 days including the day in question. | |
library(zoo) |
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(ggplot2) | |
library(lubridate) | |
libarry(ggthemes) | |
# Create a series of dates (hourly) | |
hourly_date <- seq.POSIXt(dmy("01012012"), dmy("31122012"), by = "1 hour") | |
# Create some fictional fdom data. | |
fdom <- data.frame(date = hourly_date, fdom = sin(1:length(hourly_date)/300)+10) | |
# Create a series of dates (daily) | |
daily_date <- seq.POSIXt(dmy("01012012"), dmy("31122012"), by = "1 day") |
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(ggplot2) | |
library(gtable) | |
library(grid) | |
library(ggthemes) | |
# extract gtable | |
ggplot_second_axis <- function(p1, p2){ | |
p2 <- p2 + theme() %+replace% |
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
# load the libraries | |
library(ggplot2) | |
library(gtable) | |
library(gridExtra) | |
# Create the plots | |
p1 <- ggplot() + geom_point(aes(1,1)) | |
p2 <- ggplot() + geom_point(aes(2,2)) | |
p3 <- ggplot() + geom_point(aes(3,3)) | |
p4 <- ggplot() + geom_point(aes(4,4)) | |
# Firstly create two columns (the first and second column) |
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(lubridate) | |
## A synthetic data set. | |
doc <- data.frame(date=ymd_hm("2014-01-01 14:00") + (1:360)* 24*3600) | |
# Find all the dates before a certain time period. | |
index <- doc$date < ymd("2014-06-01") | |
## use the hour function to extract the hour of each day e.g | |
hour(doc$date) | |
## Now using the index from above you can subtract an hour from each of the times | |
# using the index vector and reassiging the modified hour back to the time stamp. | |
hour(doc$date[index]) <- hour(doc$date[index]) - 1 |
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
set.seed(1082) | |
# Create two weeks of 15 minute data | |
library(lubridate) | |
dates <- seq.POSIXt(dmy_hm("01-01-2013 00:00"), dmy_hm("31-12-2013 11:45"), by = "15 mins") | |
# Add a column with a random variable with mean = 10 | |
temp <- data.frame(date = dates, temp = rnorm(length(dates))+10) | |
plot(temp, type='l') | |
# aggreagate the data to daily by converting the POSIX date to date format (i.e drop the timestamp) | |
daily_temp <- aggregate(temp$temp, list(date=as.Date(temp$date)), mean) | |
# fix the names up |
OlderNewer