-
Notifications
You must be signed in to change notification settings - Fork 0
/
working code.txt
53 lines (44 loc) · 2.75 KB
/
working code.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#Packages
library(tidyverse)
library(ggplot2)
library(lubridate)
library(gridExtra)
library(dplyr)
library(ggpubr)
library(Hmisc)
library(readxl)
library(rgdal)
library(gstat)
library(sp)
library(raster)
library(mapview)
library(sf)
#Data importing and cleaning
water <- read_excel("~/Desktop/bio/project/water.xlsx", na = " ") %>%
mutate_at(vars(Nitrite:VOC), as.numeric)
#Study area mapping using google open street map
charlestown_bnd <- st_read("~/Desktop/bio/project/Municipalities_1997/Municipalities_1997.shp") %>%
filter(NAME == "CHARLESTOWN") %>%
st_transform(crs = "+proj=utm +zone=19 +ellps=WGS84 +datum=WGS84 +no_defs") %>%
as("Spatial")
water_sp <- SpatialPoints(water[,c("Long","Lat")], proj4string = CRS("+proj=longlat +datum=WGS84"))
water_sp <- SpatialPointsDataFrame(water_sp, water)
water_sp <- spTransform(water_sp, CRS(proj4string(charlestown_bnd)))
mapview(water_sp) + charlestown_bnd
#Data availability assessment
ggplot(water) + stat_count(aes(x = Year, fill =Rt1_ref ), position = "dodge")+ylab('Number of samples')+xlab('Year')+theme(axis.text.x = element_text(angle = 90))+scale_x_continuous(breaks=seq(2008, 2017, 1))
#TDS value below and above Route-1 hightwy
ggplot(water, aes(x=Rt1_ref, y=TDS))+ geom_boxplot(alpha = 1,color='blue')+xlab('From Route - 1')+ylab('Total dissolved solids (mg/L)')+ stat_summary(fun.y=mean, color="red", geom="point", shape=15, size=1,show_guide = T, show.legend = T) + theme_bw()
#Monthly average value of TDS
water$Month<-as.character(as.numeric(water$Month))
ggplot(water, aes(x=Month, y=TDS))+ geom_boxplot(alpha = 1,color='blue')+xlab('Months')+ylab('Total dissolved solids (mg/L)')+ stat_summary(fun.y=mean, color="red", geom="point", shape=15, size=1,show_guide = T, show.legend = T) + theme_bw()
#Yearly distribution of TDS
water$Year<-as.character(as.numeric(water$Year))
water_2010<-water[ which(water$Year>2010),]
ggplot(water_2010, aes(x=Year, y=TDS))+ geom_boxplot(alpha = 1,color='black')+xlab('Year')+ylab('Total dissolved solids (mg/L)')+ stat_summary(fun.y=mean, color="red", geom="point", shape=15, size=1,show_guide = T, show.legend = T) + theme_bw()+geom_smooth(method="lm", se=FALSE, color="blue", aes(group=1))
#Relationship between TDS and chloride content
ggscatter(water, x = "TDS", y = "Chloride", color = "black", shape = 21, size = 2, add = "reg.line", conf.int = TRUE, cor.coef = TRUE, cor.method = "pearson", ylab = "Chloride (mg/L)", xlab = "TDS (mg/L)")
c4 <- cor.test(water$EC,water$Chloride)
#Relationship between TDS and coliform detection
ggplot(water, aes(x=Coliform, y=TDS))+
geom_boxplot(alpha = 1,color='blue')+xlab('Coliform presense/absence')+ylab('Total Dissolved Solids (mg/L)')+ stat_summary(fun.y=mean, color="red", geom="point", shape=15, size=1,show_guide = T, show.legend = T) + theme_bw()