This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(devtools)
## Warning: package 'devtools' was built under R version 4.0.5
## Loading required package: usethis
## Warning: package 'usethis' was built under R version 4.0.5
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.0.5
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr)
## Warning: package 'tidyr' was built under R version 4.0.5
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.0.5
library(leaflet)
## Warning: package 'leaflet' was built under R version 4.0.5
library(devtools)
library(gsw)
## Warning: package 'gsw' was built under R version 4.0.5
#install_github("MikkoVihtakari/PlotSvalbard")
library(PlotSvalbard)
#shell("cd c:/Users/Saman/Onedrive/Desktop/Mast467/Data/", translate=TRUE)
#shell("dir")
shell("c:/Users/Saman/OneDrive/Desktop/Mast467/Data/nasa.cmd",translate=TRUE)
Omg<- read.csv("c:/Users/Saman/Onedrive/Desktop/Mast467/Data/output.dat",sep=" ")
## Plot sal vs. depth for range
library(ggplot2)
#Individual profiles
ggplot(Omg, mapping=aes (x=dep, y=sal, group=cast)) +
geom_path() +
ylim(c(30,35)) +
xlim(c(720,0)) +
ylab("Salinity, psu") +
xlab("Depth, m") +
coord_flip(expand=FALSE) +
facet_wrap(~cast)
## Warning: Removed 1999 row(s) containing missing values (geom_path).
#Profiles on one plot
ggplot(Omg, mapping=aes (x=dep, y=sal, group=cast)) +
geom_path() +
xlim(c(720,0)) +
ylab("Salinity, psu") +
xlab("Depth, m") +
coord_flip(expand=FALSE)
## Plot temp vs. depth for individual casts
library(ggplot2)
ggplot(Omg, mapping=aes (x=dep, y=temp, group=cast)) +
geom_path() +
#ylim(c(-3.0,6.5)) +
xlim(c(720,0)) +
ylab("Temperature, C") +
xlab("Depth, m") +
coord_flip(expand=FALSE) +
facet_wrap(~cast)
#Plot temp vs. depth for all casts
ggplot(Omg, mapping=aes (x=dep, y=temp, group=cast)) +
geom_path() +
#ylim(c(-3.0,6.5)) +
xlim(c(720,0)) +
ylab("Temperature, C") +
xlab("Depth, m") +
coord_flip(expand=FALSE)
#Salinity and Temperature (all casts)
ggplot(Omg,mapping=aes(x=sal,y=temp,group=cast,color=dep)) +
geom_point() +
xlim(c(30,35)) +
ylim(c(-2,4)) +
xlab("Salinity, psu") +
ylab("Temperature, C") +
scale_color_viridis_c(guide=guide_colorbar(barheight=15,reverse=TRUE)) #+
## Warning: Removed 2012 rows containing missing values (geom_point).
#facet_wrap(~cast)
#Put OMG data into data frame
OMG.df = data.frame(Omg$lon, Omg$lat, Omg$dep, Omg$temp, Omg$sal, Omg$cast)
#rename colums
colnames(OMG.df) = c("Lon", "Lat", "D", "T", "S", "Cast")
#I decided to use a dataframe after looking through Michael's code, he is working with data from each year, so I did not alter the cast dumber for my data
#Isolate a single cast (156)
C156 = OMG.df[OMG.df$Cast==156,]
#Create temperature profile for this single cast
ggplot(C156, mapping=aes (x=D, y=T)) +
geom_path() +
xlim(c(200,0)) +
ylab("Temperature, C") +
xlab("Depth, m") +
coord_flip(expand=FALSE) +
ggtitle("Temperature Profile Cast 156")
#Create Salinity profile for single cast
ggplot(C156, mapping=aes (x=D, y=S)) +
geom_path() +
xlim(c(200,0)) +
ylab("Salinity, psu") +
xlab("Depth, m") +
coord_flip(expand=FALSE) +
ggtitle("Salinity Profile Cast 156")
#New salinity profile for depths between 150 and 180 m
ggplot(C156, mapping=aes (x=D, y=S)) +
geom_path() +
xlim(c(180,150)) +
ylim(c(34.2,34.6)) +
ylab("Salinity, psu") +
xlab("Depth, m") +
coord_flip(expand=FALSE) +
ggtitle("Salinity Profile Cast 156")
## Warning: Removed 1342 row(s) containing missing values (geom_path).
#Graph another T profile for this same depth range
ggplot(C156, mapping=aes (x=D, y=T)) +
geom_path() +
xlim(c(180,150)) +
ylim(c(-.55,-.12)) +
ylab("Temperature, C") +
xlab("Depth, m") +
coord_flip(expand=FALSE) +
ggtitle("Temperature Profile Cast 156")
## Warning: Removed 1351 row(s) containing missing values (geom_path).
#Calculate Values using gsw package
library(gsw)
# Pressure from depth
p = gsw_p_from_z(-C156$D,C156$Lat)
#absolute salinity from practical salinity
SA = gsw_SA_from_SP(C156$S,p,C156$Lon,C156$Lat)
#potential temperature from in situ t
pt = gsw_pt_from_t(SA,C156$T,p,0)
#conservative temp from pt
CT = gsw_CT_from_t(SA,C156$T,p)
#potential density at p=0
r0 = gsw_sigma0(SA,CT)
#potential density with p=1000
r1 = gsw_sigma1(SA,CT)
# Freezing Point
#This code gets an error
#tf = gsw_CT_freezing_poly(SA,p,1)
#Put new data into a data frame ("dat")
dat = data.frame(p,SA,pt,CT,r0,r1,C156$T)
ggplot(dat, aes(x=p)) +
geom_line(aes(y=C156.T),color = "blue")+
geom_line(aes(y=pt),color="red") +
coord_flip(expand=FALSE)+
xlim(c(200,0))+
xlab("Pressure, db")+
ylab("Temperature, C")+
ggtitle("in situ and Potential Temperature")
#Salinity and density
#I have not figured out how to create separate axes yet
ggplot(dat, aes(x=p)) +
geom_line(aes(y=SA),color = "blue")+
geom_line(aes(y=r1),color="red") +
coord_flip(expand=FALSE)+
xlim(c(200,0))+
xlab("Pressure, db")
#Download package that can make T-S Diagrams
library(devtools)
library(PlotSvalbard)
ts_plot(dt=C156,temp_col= "T",sal_col="S")
#I found this package that makes T-S diagrams using ggplot
#I'm not entirely sure what's going on with this function. The graph lists potential temperature on the y axis, but I am not sure if it is just taking my in situ T values or if the conversion is built within the function
#Trying a different packege for T-S Diagram
#install_github("MikkoVihtakari/ggOceanMaps")
#install_github("MikkoVihtakari/ggOceanPlots")
#library(ggOceanPlots)
#library(ggOceanMaps)