Coder Social home page Coder Social logo

ggts's Introduction

create a TS diagram as a ggplot

David Kaiser 2018/01/16

Description

A TS diagram, Temperature-Salinity-diagram, plots the potential temperature of water over salinity. Many water masses have characteristic shapes in a TS diagram, which is used in physical oceanography to identify water masses and their mixing.

This function requires the input of vectors of potential temperature and salinity. The gws package is used to calculate potential density for plotting of isopycnals (contours of the same density). This calculation requires a reference pressure, which defaults to 0, the sea surface.

A third vector can optionally be supplied to col.par to be plotted in color, and can be named with a string supplied to col.name.

Use DOI to cite a permanent archived version of the function.

Arguments

sal -- vector of salinity values

pot.temp -- vector of potential temperature values in degree C

reference.p = 0 -- reference pressure which was also used to calculate potential temperature

col.par = NA -- optional vector of a parameter to be displayed as color of the TS-pairs

col.name = "col.par" -- optional name of the "col.par" to be used on the color bar

Plot

example <- read.csv("example_data/example_data.csv")

head(example)
##   depth potential.temperature salinity
## 1  1.50                6.1272  13.2087
## 2  1.75                6.1245  13.2115
## 3  2.00                6.1236  13.2128
## 4  2.25                6.1227  13.2126
## 5  2.50                6.1229  13.2145
## 6  2.75                6.1224  13.2122

The data will be plotted using the ggplot2 package.

ggTS(sal = example$salinity, 
        pot.temp = example$potential.temperature, 
        reference.p = 0,
        col.par = example$depth, 
        col.name = "depth [m]")

NOTE: the special "ร‚" character does not show when the function is used in R, this seems to be a markdown/knitr problem

Since the result is a ggplot, it can be altered and amended:

p1 <- ggTS(sal = example$salinity, 
        pot.temp = example$potential.temperature, 
        reference.p = 0,
        col.par = example$depth, 
        col.name = "depth [m]")
p1 + scale_color_gradient(low = "grey", high = "black", name = "something\nelse") +
      annotate(geom = "text", x = 15, y = 6, color = "red", size = 14, label = "ADD\nSTUFF")

Plot a TS diagram with isopycnals running more horizontally

example1 <- read.csv("example_data/example_data1.csv")

head(example1)
##   depth potential.temperature salinity
## 1     0              24.30924 34.36559
## 2    10              24.09002 34.30511
## 3    20              23.58654 34.32923
## 4    30              23.19063 34.38134
## 5    40              22.88482 34.44991
## 6    50              22.45423 34.50933
ggTS(sal = example1$salinity, 
        pot.temp = example1$potential.temperature, 
        reference.p = 0,
        col.par = example1$depth, 
        col.name = "depth [m]")

ggts's People

Contributors

davidatlarge avatar markolipka avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ggts's Issues

Installation help

Hi, I have been trying to install the package to R, and used the following command: install_github("Davidatlarge/ggTS")
I obtained this error message: Error: Failed to install 'ggts' from GitHub:
Does not appear to be an R package (no DESCRIPTION)

I also tried to download the zip file manually, but then faced this issue: Warning in install.packages :
cannot open compressed file 'ggTS-1.0.0/DESCRIPTION', probable reason 'No such file or directory'
Error in install.packages : cannot open the connection.

Are you familiar with this issue and if yes how is it best to install it? Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.