简体   繁体   English

当用作独立层时,ggoce 中的 geom_isopycnal 返回错误

[英]geom_isopycnal in ggoce returning error when used as standalone layer

I would like to draw temperature salinity diagrams with isopycnals.我想用 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, ie using it with a data frame containing CTD data in the ggplot instead of using a ctd object created by the package oce .我一直在尝试将ggoce::geom_isopycnal层用于ggplot2 ,但在将其用作独立层时遇到错误,即将其与包含 ggplot 中的 CTD 数据的数据框一起使用,而不是使用由 package 创建的ctd object 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.当我没有在调用中指定任何纬度或经度时,我无法找到为什么 geom_isopycnal 的assert_has_lonlat()内部geom_isopycnal返回此错误。

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)reprex package (v2.0.1) 创建于 2022-03-20

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.根据文档,如果eos设置为"gsw" ,则需要添加ref_longituderef_latitude ,因为它是默认设置。 You could set these to 0 without affecting the plot.您可以将它们设置为 0 而不会影响 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)")

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM