Reputation: 81
I would like to draw temperature salinity diagrams with isopycnals. I've been trying to use the ggoce::geom_isopycnal
layer for ggplot2
but encounter an error when using it as a standalone layer, i.e using it with a data frame containing CTD data in the ggplot instead of using a ctd
object created by the package oce
. I was not able to find why the assert_has_lonlat()
internal function of geom_isopycnal
is returning this error when I did not specify any latitude or longitude in the call.
library(tidyverse)
library(oce)
#> Loading required package: gsw
library(ggoce)
data <- tibble(PS = c(34.3753,34.3748,34.3745,34.3744,34.3742,34.3742,34.3737,34.3734,34.3733,34.3728,34.3722),
TMP = c(10.6853,10.6722,10.6701,10.6673,10.6629,10.6660,10.6571,10.6493,10.6462,10.6502,10.6413),
P = c(10,11,12,13,14,15,16,17,18,19,20),
CT = c(10.68576,10.67254,10.67033,10.66741,10.66290,10.66588,10.65687,10.64895,10.64573,10.64962,10.64061),
LAT = c(-43.97961,-43.97961,-43.97961,-43.97961,-43.97961,-43.97961,-43.97961,-43.97961,-43.97961,-43.97961,-43.97961),
LONG = c(14.06983,14.06983,14.06983,14.06983,14.06983,14.06983,14.06983,14.06983,14.06983,14.06983,14.06983)
)
# Plot T-S diagram using ggoce::geom_isopycnal as a standalone layer
ggplot(data,
aes(x = PS, y = CT)) +
geom_isopycnal(salinity_type = "practical",
temperature_type = "conservative") + # Specify the type of temperature and salinity on the axes
geom_point() +
labs(x = "Practical salinity",
y = "Potential temperature (°C)")
#> Error in assert_has_lonlat(ref_longitude, ref_latitude): !is.null(ref_longitude) is not TRUE
# Create a CTD object from data (package oce)
ctd.data <- as.ctd(salinity = data$PS,
temperature = data$TMP,
pressure = data$P,
longitude = data$LONG,
latitude = data$LAT)
# Plot T-S diagram using ggoce::geom_isopycnal with oce
ggplot(ctd.data,
aes(x = salinity,
y = gsw::gsw_CT_from_t(gsw::gsw_SA_from_SP(salinity, pressure, longitude, latitude),
temperature,
pressure))) +
geom_isopycnal() +
geom_point() +
labs(x = "Practical salinity",
y = "Potential Temperature (°C)")
Created on 2022-03-20 by the reprex package (v2.0.1)
Upvotes: 1
Views: 105
Reputation: 174293
According to the docs you need to add a ref_longitude
and ref_latitude
if eos
is set to "gsw"
, as it is by default. You could set these to 0 without affecting the plot.
ggplot(data,
aes(x = PS, y = CT)) +
geom_isopycnal(salinity_type = "practical",
temperature_type = "conservative",
ref_longitude = 0,
ref_latitude = 0) +
geom_point() +
labs(x = "Practical salinity",
y = "Potential temperature (°C)")
Upvotes: 3