Computes isolines from a griddap data frame and appends them as a geom_sf() layer to the plotdap object's internal ggplot. Call this before add_ggplot() or print().

add_griddap_contours(
  p,
  data,
  var,
  n_breaks = 10L,
  breaks = NULL,
  lon_col = "longitude",
  lat_col = "latitude",
  color = "black",
  linewidth = 0.3,
  alpha = 1,
  crs = 4326L
)

Arguments

p

a plotdap object (result of plotdap() piped through add_griddap()). Not the result of add_ggplot().

data

data frame typically dat$data from a griddap() call.

var

character; name of the variable column to contour.

n_breaks

integer; number of evenly-spaced interior contour levels (ignored when breaks is supplied). Default 10.

breaks

numeric vector of explicit contour levels, or NULL.

lon_col

name of longitude column (default "longitude").

lat_col

name of latitude column (default "latitude").

color

contour line color (default "black").

linewidth

contour line width (default 0.3).

alpha

opacity 01 (default 1).

crs

integer EPSG code for the data (default 4326).

Value

the plotdap object with contour lines added to its internal ggplot. Pipe the result to add_ggplot() or print() as usual.

Examples

if (FALSE) { # \dontrun{
  library(rerddap)
  library(plotdap)

  myURL <- "https://coastwatch.pfeg.noaa.gov/erddap/"
  info <- rerddap::info("jplMURSST41", url = myURL)
  dat  <- griddap(info,
            latitude  = c(30, 50),
            longitude = c(-140, -110),
            time      = c("2020-06-15", "2020-06-15"),
            fields    = "analysed_sst")

  p <- plotdap() |>
         add_griddap(dat, ~analysed_sst)

  ## Default: 10 evenly-spaced contour levels, then render
  p |> add_griddap_contours(dat$data, "analysed_sst") |> add_ggplot()

  ## Explicit break values
  p |> add_griddap_contours(dat$data, "analysed_sst",
                             breaks = c(10, 12, 14, 16, 18, 20)) |> add_ggplot()

  ## More levels, thinner grey lines
  p |> add_griddap_contours(dat$data, "analysed_sst",
                             n_breaks = 20, color = "grey40", linewidth = 0.2) |>
       add_ggplot()
} # }