library(dplyr)
library(ggplot2)
library(reshape2)
library(lubridate)
library(tidyr)
## Warning: package 'tidyr' was built under R version 3.2.2
library(ggmap)
library(RODBC)
## Warning: package 'RODBC' was built under R version 3.2.2
setwd("\\\\psf/Home/Dropbox/")
#setwd("c:/Users/Katrina/Dropbox/")

# User: fill in location, date(s), file names; report will get relevant data
location = 'MAR003'
sample_date = 'July 17, 2015'
DeployID = "20150717"
VerticalSurveyID = "20150721"

#load Deployment table exported from Access
oxy1 <- read.csv(
  "MysticDB/Conversion/sonde/testing_20150717/Deployments_export_test.csv", 
  strip.white=TRUE, header = TRUE, as.is=TRUE)
# parse date and specify time zone
oxy2 <- oxy1 %>%
               mutate(Datetime = mdy_hm(Datetime, tz="UTC")) %>%
               mutate(Datetime = with_tz(Datetime, tzone="US/Eastern"))
#filter for desired parameters
oxy2 <- oxy2 %>%
  filter(DeploymentID ==  DeployID) %>%
  filter(CharacteristicID == "DO" | CharacteristicID == "DO_SAT" | 
           CharacteristicID == "CHLA" | CharacteristicID == "SPCOND" | 
           CharacteristicID == "TEMP_WATER" | CharacteristicID == "DEPTH")

#load Surveys table of vertical profiles exported from Access
oxyvertacc <- read.csv(
  "MysticDB/Conversion/sonde/testing_20150717/Survey_export_test.csv", 
  strip.white=TRUE, header = TRUE, as.is=TRUE)
# parse date and filter for id
oxyvertacc2 <- oxyvertacc %>%
  filter(SurveyID == VerticalSurveyID) %>%
  mutate(Datetime = mdy_hms(Datetime, tz="UTC")) %>% #need time to the sec to uniquely id
  mutate(Datetime = with_tz(Datetime, tzone="US/Eastern"))

oxyvertacc2 <- unique( oxyvertacc2[ , 1:8 ])  #handheld creates duplicate records; remove

On July 17, 2015, the Mystic River Watershed Association deployed a YSI EXO2 water quality sonde to monitor several water quality parameters.

1 Results: July 17 - July 21

g <- ggplot(oxy2, aes(Datetime, ResultValue)) 
g + geom_line() + facet_wrap( ~ CharacteristicID, ncol= 2, scale = "free_y") +theme_bw() + theme(axis.text.x = element_text(angle = 45, hjust = 1))

2 Depth profiles

Vertical profile data from post-event sampling, ~9AM, July 21.

# Shape Access data and plot
# spread data for scatterplots
oxyvertplot <- oxyvertacc2 %>% 
  #spread(CharacteristicID, ResultValue)
  dcast(Datetime ~ CharacteristicID, value.var = "ResultValue")

oxyvertplot <- left_join(oxyvertacc2, oxyvertplot) %>%
  filter(CharacteristicID == "CHLA" | CharacteristicID == "DO" |
           CharacteristicID == "DO_SAT" |
           CharacteristicID == "SPCOND" |CharacteristicID == "DEPTH" 
         |CharacteristicID == "TEMP_WATER")

g <- ggplot(arrange(oxyvertplot, DEPTH), aes(ResultValue, DEPTH))
g + facet_wrap( ~ CharacteristicID, ncol= 3, scale = "free_x") + theme_bw() + 
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) + 
  scale_y_reverse() + ylab("Depth (m)") + 
  geom_path(aes(color = DEPTH), size = 1)  + 
  scale_color_gradient(low = "gray94", high = "gray37") + 
  guides(color = guide_colorbar(reverse=T)) + geom_point() 

3 Map MAR003

map <- get_map(location=c(lon=mean(range(c(-71.083691, -71.063778))), lat=mean(range(42.407704, 42.392112))), zoom=15, maptype="roadmap")

site <- data.frame('MAR003', 42.399338, -71.0754)
col_headings <- c('loc','Latitude','Longitude')
names(site) <- col_headings

ggmap(map, darken=c(0.25, "white"), extent="device") +
  geom_point(aes(x = Longitude, y = Latitude), data = site,
 alpha = .5, color="red", size = 7) +
  annotate('text', label = 'MAR003')