R Markdown

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:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

library (dplyr)
## 
## 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)
library (ggplot2)
library (leaflet)
library (gsw)

install.packages(“dplyr”) install.packages(“tidyr”) install.packages(“leaflet”) install.packages(“knitr”) install.packages(“rmarkdown”) install.packages(“gsw”)

##shell("cd C:/Users/ingri/MAST467/Data/output.dat")
shell("C:/Users/ingri/MAST467/Data/NASA.cmd", translate=TRUE)
Omg<-read.csv("C:/Users/ingri/MAST467/Data/output.dat",sep=" ")

###Plotting Temp and Sal ###From Dr.Muenchow's code
ggplot(Omg,mapping=aes(x=sal,y=tem,group=cast,color=dep)) +
  geom_point() +
  xlim(c(25,35)) +
  ylim(c(-2,8)) +
  xlab("Salinity, psu") +
  ylab("Temperature, C") +
  scale_color_viridis_c(guide=guide_colorbar(barheight=15)) +
  facet_wrap(~cast)

###Depth and Temp ###From Dr.Muenchow's code
ggplot(Omg,aes(x=dep,y=tem,group=cast)) +
  geom_path() +
  ylim(c(-1.5,6.5)) +
  xlim(c(500,0)) +
  ylab("Temperature, C") +
  xlab("Depth, m") +
  coord_flip(expand=FALSE) + 
  facet_wrap(~cast)
## Warning: Removed 3735 row(s) containing missing values (geom_path).

###Depth and Sal ###From Dr.Muenchow's code
ggplot(Omg,mapping=aes(x=dep,y=sal,group=cast)) +
  geom_line() +
  ylim(c(30,35)) +
  xlim(c(500,0)) +
  ylab("Salinity, psu") +
  coord_flip(expand=FALSE) +
  facet_wrap(~cast)
## Warning: Removed 3097 row(s) containing missing values (geom_path).

###Making data fram for 1 cast
Omg.df = data.frame(Omg$lon, Omg$lat, Omg$dep, Omg$tem, Omg$sal, Omg$cast)
###rename columns
colnames(Omg.df) = c("lon", "lat", "dep", "tem", "sal", "cast")
###Specifying cast number
C106 = Omg.df[Omg.df$cast==106,]

###Using one cast (106) to convert in-situ temperature, salinity, and depth to pressure, absolute salinity, and potential temperature
#Pressure
p = gsw_p_from_z(-C106$dep, C106$lat)
#Absolute Salinity
SA = gsw_SA_from_SP(C106$sal, p, C106$lat, C106$lon)
#Potential Temperature
pt = gsw_pt_from_t(SA, C106$tem, p, 0)


####Using cast 106 to estimate potential denisty at both zero and 1000-dbar pressure as well as the freezing point
#Conservative Temperature
CT= gsw_CT_from_t(SA, C106$tem, p)
#Potential Density to Zero Pressure
r0 = gsw_sigma0(SA,CT)
#Potential Density to 1000-m Pressure
r1 = gsw_sigma1(SA,CT)
#Freezing Point
tf = gsw_CT_freezing(SA, p, saturation_fraction = 1)

dat= data.frame(p, SA, pt, CT, r0, r1, tf, C106$tem)

###Plotting profile to compare in-situ with potential temperature
ggplot(dat, aes(x=p)) + 
  geom_line(aes(y = C106$tem), color = "darkred") + 
  geom_line(aes(y = pt), color="steelblue", linetype="twodash")+
  coord_flip(expand=FALSE)+
  ylim(c(3,6.5)) +
  xlim(c(350,0)) +
  ylab("Temperature, C") +
  xlab("Pressure, p")

###Plotting profile to compare absolute salinity with potential temperature
ggplot(dat, aes(x=p)) + 
  geom_line(aes(y = SA), color = "darkred") + 
  geom_line(aes(y = r1), color="steelblue", linetype="twodash")+
  coord_flip(expand=FALSE)+
  #ylim(c(30,36)) +
  xlim(c(350,0)) +
  ylab("Absolute Salinity, SA") +
  xlab("Pressure, p")