% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/add_griddap_contours.R
\name{add_griddap_contours}
\alias{add_griddap_contours}
\title{Add contour lines to a plotdap object}
\usage{
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{
\item{p}{a plotdap object (result of \code{plotdap()} piped through
\code{add_griddap()}).  \strong{Not} the result of
\code{add_ggplot()}.}

\item{data}{data frame  typically \code{dat$data} from a
\code{griddap()} call.}

\item{var}{character; name of the variable column to contour.}

\item{n_breaks}{integer; number of evenly-spaced interior contour levels
(ignored when \code{breaks} is supplied). Default 10.}

\item{breaks}{numeric vector of explicit contour levels, or \code{NULL}.}

\item{lon_col}{name of longitude column (default \code{"longitude"}).}

\item{lat_col}{name of latitude column  (default \code{"latitude"}).}

\item{color}{contour line color (default \code{"black"}).}

\item{linewidth}{contour line width (default \code{0.3}).}

\item{alpha}{opacity 01 (default \code{1}).}

\item{crs}{integer EPSG code for the data (default \code{4326}).}
}
\value{
the plotdap object with contour lines added to its internal ggplot.
  Pipe the result to \code{add_ggplot()} or \code{print()} as usual.
}
\description{
Computes isolines from a griddap data frame and appends them as a
\code{geom_sf()} layer to the \strong{plotdap object's internal ggplot}.
Call this \emph{before} \code{add_ggplot()} or \code{print()}.
}
\examples{
\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()
}
}
