% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plot.R
\name{plot.verify_stockflow}
\alias{plot.verify_stockflow}
\title{Plot verify results}
\usage{
\method{plot}{verify_stockflow}(
  x,
  test = NULL,
  vars = NULL,
  order = vars,
  show_constants = FALSE,
  label = NULL,
  ignore_case = TRUE,
  status = c("pass", "fail", "error", "skip"),
  condition = seq(1, min(c(x[["n_conditions"]], 9))),
  nrows = ceiling(sqrt(max(condition))),
  shareX = TRUE,
  shareY = TRUE,
  palette = "Dark 2",
  colors = NULL,
  line_width = 2,
  line_type = list(stock = "solid", flow = "solid", aux = "solid", constant = "dash",
    lookup = "dash"),
  font_family = getOption("sdbuildR.font_family", default = "stix-two-text"),
  font_size = 16,
  wrap_width = 25,
  show_legend = TRUE,
  label_subplots = TRUE,
  alpha = 1,
  margin = 0.05,
  format_label = TRUE,
  condition_display = c("subplots", "slider", "dropdown"),
  control_options = list(),
  animation = c("none", "time"),
  webgl = getOption("sdbuildR.webgl", default = TRUE),
  ...
)
}
\arguments{
\item{x}{Output of \code{\link[=verify]{verify()}}.}

\item{test}{Integer vector of test numbers to plot.
Combines with \code{label} and \code{status} as AND intersection.}

\item{vars}{Variable names to retain in the data frame. Only applies when
\code{which = "sims"}. Defaults to \code{NULL} to include all variables.}

\item{order}{Character vector of model variable names giving the trace and
legend order. Listed variables appear first; any plotted variables not
listed keep their default relative order. Defaults to \code{vars}, so the order
in which variables are listed in \code{vars} is followed unless \code{order} is set
explicitly.}

\item{show_constants}{If \code{TRUE}, include constants in plot. Defaults to \code{FALSE}.}

\item{label}{Character vector of regex patterns for partial, case-insensitive
label matching. A test is included if its label matches any pattern.}

\item{ignore_case}{Logical; whether \code{label} matching is case-insensitive.
Default \code{TRUE}.}

\item{status}{Optional character vector of statuses to include (e.g.,
\code{c("fail", "error")}). Defaults to all statuses.
\itemize{
\item \code{which = "tests"}: filters rows by test status.
\item \code{which = "sims"}: filters to conditions that have at least one test
with a matching status.
}}

\item{condition}{Integer vector of condition numbers to plot. Defaults to \code{1:9}. If only one condition is specified, the plot will not be a grid of subplots.}

\item{nrows}{Number of subplot rows. Defaults to \code{ceiling(sqrt(max(condition)))}.}

\item{shareX}{Share the x-axis across subplots. Defaults to \code{TRUE}.}

\item{shareY}{Share the y-axis across subplots. Defaults to \code{TRUE}.}

\item{palette}{Colour palette (see \code{hcl.pals()}). Defaults to \code{"Dark 2"}.}

\item{colors}{Colours for the plotted variables. A named vector (names are
variable names) recolours only those variables, the palette fills the rest;
an unnamed vector assigns colours in plot order. Defaults to \code{NULL}.}

\item{line_width}{Line width of the trajectories. Either a single value, a
named per-variable vector (names are variable names), or an unnamed vector
with one value per variable in plot order. Defaults to \code{2}.}

\item{line_type}{Dash style of the plotted lines. Each value is one of
\code{"solid"}, \code{"dot"}, \code{"dash"}, \code{"longdash"}, \code{"dashdot"}, \code{"longdashdot"}, or
a pixel pattern such as \code{"5px,10px"}. Supply a single style for every
variable (\code{line_type = "dash"}), a named vector to style variables
individually (\code{line_type = c(S = "solid", I = "dot")}), an unnamed vector in
plot order, or a list keyed by variable type to style each type at once
(\code{line_type = list(stock = "solid", flow = "dash")}; the types are \code{stock},
\code{flow}, \code{aux}, \code{constant}, and \code{lookup}). By default stocks, flows, and
auxiliaries are solid and constants and lookups are dashed.}

\item{font_family}{Font family. Kebab-case names (e.g. \code{"eb-garamond"})
are Fontsource ids (browse them at \url{https://fontsource.org/}), loaded as
webfonts: no installation is needed, but internet access is required to
display them. Other fonts must be installed on the system viewing the
plot. Defaults to the \code{sdbuildR.font_family} option, or
the \code{"stix-two-text"} webfont when the option is unset; use
\code{options(sdbuildR.font_family = )} to change the default for all plots,
e.g. in your .Rprofile.}

\item{font_size}{Font size. Defaults to \code{16}.}

\item{wrap_width}{Label wrap width. Defaults to \code{25}.}

\item{show_legend}{Whether to show the legend. Defaults to \code{TRUE}.}

\item{label_subplots}{Whether to title each subplot with its condition's
parameter overrides (or \code{"Baseline"}) and test number(s), e.g.
\code{"rate = 0 (test 2)"}. Defaults to \code{TRUE}.}

\item{alpha}{Trajectory opacity, between 0 and 1. A single value or a named
per-variable vector. Defaults to \code{1}.}

\item{margin}{Margin between subplots. Either a single numeric or a vector of length four(left, right, top, bottom). See \code{?plotly::subplot()} for more details. Defaults to 0.05.}

\item{format_label}{If \code{TRUE}, apply default formatting (replacing periods and
underscores with spaces) to variable labels that are the same as the
variable name. Applies to the legend and any condition controls. Defaults to
\code{TRUE}.}

\item{condition_display}{How to display multiple conditions. Use \code{"subplots"}
to show conditions as panels, \code{"slider"} to select one condition with a
slider, or \code{"dropdown"} to select one condition with a dropdown. Defaults
to \code{"subplots"}. If only a single condition is available (e.g. no
conditions were varied), \code{"slider"} and \code{"dropdown"} fall back to
\code{"subplots"} with a message. To guarantee the control geometry, plots with
a slider/dropdown have a fixed height (sized to the number of controls)
instead of a responsive one.}

\item{control_options}{Named list fine-tuning the \code{"slider"}/\code{"dropdown"}
condition control and the \code{animation = "time"} animation; see
\code{\link[=plot.ensemble_stockflow]{plot.ensemble_stockflow()}} for the supported options (\code{max_labels},
\code{spacing}, \code{frame_ms}, \code{duration}, \code{transition_ms}, \code{max_frames}).
Defaults to \code{list()}, i.e. all defaults.}

\item{animation}{Animation mode. Use \code{"none"} for a static plot or \code{"time"}
to cumulatively reveal trajectories over time. Defaults to \code{"none"}.}

\item{webgl}{If \code{TRUE}, render trajectories with WebGL (plotly \code{scattergl}) for
performance with many lines; if \code{FALSE}, use SVG (\code{scatter}). Defaults to
\code{getOption("sdbuildR.webgl", default = TRUE)}. Set
\code{options(sdbuildR.webgl = FALSE)} (e.g. in vignettes or dashboards, or when
a plot renders blank) to disable WebGL globally. WebGL is not supported for
filled flow traces (\code{fill_flows = TRUE}) or time animations; these always
render with SVG \code{scatter} regardless of \code{webgl}.}

\item{...}{Additional arguments passed to \code{\link[=plot.simulate_stockflow]{plot.simulate_stockflow()}}.}
}
\value{
A plotly object.
}
\description{
Visualize the simulation(s) used during \code{\link[=verify]{verify()}}. Each \emph{condition} is one
simulation run -- the model with one set of parameter overrides (from
\code{unit_test(conditions = )}, possibly none) -- shared by every unit test
declaring those overrides. Each condition is displayed as a subplot (or a
slider/dropdown step, see \code{condition_display}), labelled by its overrides
and the test(s) evaluated on it: e.g. \code{"rate = 0 (test 2)"}, with the
unmodified run labelled \code{"Baseline (tests 1, 3)"} (or just \code{"Tests 1, 3"}
when no test varies anything). Simulations are always available since
\code{\link[=verify]{verify()}} unconditionally retains them.
}
\section{Styling variables}{

Names in \code{colors}, \code{line_width}, and \code{alpha} refer to the model variable
names, not the labels shown in the legend. This keeps the styling stable if
labels are formatted or wrapped for display.

Use one value to style every trajectory:
\code{plot(res, line_width = 3, alpha = 0.6)}.

Use named vectors to style selected variables:
\code{plot(res, colors = c(susceptible = "#377EB8"), alpha = c(infected = 0.4))}.

Unnamed vectors are applied in plot order. Named vectors are usually clearer,
especially when \code{vars}, \code{test}, \code{label}, or \code{status} filters change what is
drawn.
}

\examples{
sfm <- stockflow("sir") |>
  unit_test(expr = all(susceptible >= 0)) |>
  unit_test(expr = all(infected >= 0), conditions = list(infected = 100))
res <- verify(sfm)
plot(res)

# Select one condition at a time with a slider or dropdown
plot(res, condition_display = "slider")
plot(res, condition_display = "dropdown")

# Animate the simulation over time (one condition at a time)
plot(res, animation = "time", condition = 1)
}
\seealso{
\code{\link[=verify]{verify()}}, \code{\link[=plot.simulate_stockflow]{plot.simulate_stockflow()}}, \code{\link[=plot.ensemble_stockflow]{plot.ensemble_stockflow()}}
}
\concept{unitTest}
