% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plotly_Utils.R
\name{sub_plot}
\alias{sub_plot}
\title{Display multiple plotly plots}
\usage{
sub_plot(
  ...,
  nrows = 1,
  widths = NULL,
  heights = NULL,
  margin = 0.02,
  titles = NULL,
  shareX = FALSE,
  shareY = FALSE,
  titleX = shareX,
  titleY = shareY,
  which_layout = "merge",
  print = TRUE
)
}
\arguments{
\item{\dots}{One of the following
\itemize{
\item any number of plotly objects
\item a list of plotly objects.
Note that unlike \code{\link[plotly:subplot]{plotly::subplot()}}, ggplots and tibbles cannot be passed to
this function.
}}

\item{nrows}{number of rows for laying out plots in a grid-like
structure. Default is 1.}

\item{widths, heights}{Vector of relative column widths or heights
on a 0-1 scale. By default all columns have an equal relative width/height,
i.e. \code{c(0.5, 0.5)} for two columns, \code{rep(0.25, 4)} for 4 columns.}

\item{margin}{either a single value or a vector of four values (all between 0 and 1),
e.g. \code{c(0.05, 0.05, 0.05, 0.1)}
If four values are provided, the first is used as the left margin,
the second is used as the right margin, the third is used as the top margin,
and the fourth is used as the bottom margin. If a single value is provided,
it will be used as all four margins.}

\item{titles}{Include titles on individual subplots? Default is \code{NULL}. If
specified as vector of length 2, will be rendered as x and y values relative
to each plot. For example, \code{title = c(0,1)} plots the titles in the upper
left corner of each subplot and \code{title = c(1,0)} renders the titles in the
lower right corner. Title text and formatting will be grabbed from each
individual plot. To modify these characteristics, modify the code that
generated the individual plot.}

\item{shareX, shareY}{Should the x- or y- axis be shared amongst the subplots?}

\item{titleX, titleY}{Should x- or y- axis titles be retained?}

\item{which_layout}{Adopt the layout of which plot? If the default value of
"merge" is used, layout options found later in the sequence of plots
will override options found earlier in the sequence. This argument also
accepts a numeric vector specifying which plots to consider when merging.}

\item{print}{If \code{TRUE}, will print the plotly object and return it. If \code{FALSE}, will only return the plotly object.}
}
\value{
A plot and plotly object combining all the plots in \code{...},
which can be further modified.
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}}

Wrapper around \code{\link[plotly:subplot]{plotly::subplot()}}.
}
\details{
This function addresses the deficiency with the native plotly method of combining
multiple plots that prevents individualized titling of subplots. The function
has identical arguments to \code{\link[plotly:subplot]{plotly::subplot()}} with the addition of a \code{titles}
argument. In addition to \code{subplot}, the behavior of this function is two-fold:
\itemize{
\item Fetch the titles (text and formatting) from each included plot
\item Include the titles with placement per the \code{titles} argument
}
}
\examples{
\dontrun{
plot1 <- NPex$op$plot(title = "Posterior")
plot2 <- NPex$op$plot(pred.type = "pop", title = "Population")
sub_plot(plot1, plot2, titles = c(0, 0.95), nrows = 2)
}
}
\seealso{
\code{\link[plotly:subplot]{plotly::subplot()}}
}
\author{
Michael Neely
}
