% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/methods.R
\name{plot.lgspline}
\alias{plot.lgspline}
\title{Plot Method for lgspline Objects}
\usage{
\method{plot}{lgspline}(
  x,
  show_formulas = FALSE,
  include_all_terms_in_formulas = FALSE,
  digits = 4,
  legend_pos = "topright",
  custom_response_lab = "y",
  custom_predictor_lab = NULL,
  custom_predictor_lab1 = NULL,
  custom_predictor_lab2 = NULL,
  custom_formula_lab = NULL,
  custom_title = "Fitted Function",
  text_size_formula = NULL,
  legend_args = list(),
  new_predictors = NULL,
  xlim = NULL,
  ylim = NULL,
  color_function = NULL,
  add = FALSE,
  vars = c(),
  legend_order = NULL,
  se.fit = FALSE,
  cv = 1,
  band_col = "grey80",
  band_border = NA,
  fixed_values = NULL,
  n_grid = 200,
  ...
)
}
\arguments{
\item{x}{A fitted lgspline model object.}

\item{show_formulas}{Logical; display partition-level polynomial formulas.
Default FALSE.}

\item{include_all_terms_in_formulas}{Logical; when \code{show_formulas = TRUE}
and plotting only a subset of predictors via \code{vars}, include all
fitted terms in the displayed formulas rather than only the terms
involving the plotted predictor(s). Default FALSE retains the current
marginal-only formula display.}

\item{digits}{Integer; decimal places for formula coefficients. Default 4.}

\item{legend_pos}{Character; legend position for 1D plots. Default
\code{"topright"}.}

\item{custom_response_lab}{Character; response axis label. Default
\code{"y"}.}

\item{custom_predictor_lab}{Character; predictor axis label (1D). Default
NULL uses the column name.}

\item{custom_predictor_lab1}{Character; first predictor axis label (2D).
Default NULL.}

\item{custom_predictor_lab2}{Character; second predictor axis label (2D).
Default NULL.}

\item{custom_formula_lab}{Character; fitted response label on the link
scale. Default NULL.}

\item{custom_title}{Character; plot title. Default \code{"Fitted Function"}.}

\item{text_size_formula}{Numeric; formula text size. Passed to \code{cex}
(1D) or hover font size (2D). Default NULL (0.8 for 1D, 8 for 2D).}

\item{legend_args}{List; additional arguments passed to \code{legend()}
(1D only).}

\item{new_predictors}{Matrix; optional predictor values for prediction.
Default NULL. When \code{vars} is specified and
\code{new_predictors} is NULL, a grid is automatically generated
with non-plotted variables set to zero (or values from
\code{fixed_values}).}

\item{xlim}{Numeric vector; x-axis limits (1D only). Default NULL.}

\item{ylim}{Numeric vector; y-axis limits (1D only). Default NULL.}

\item{color_function}{Function; returns K+1 colors, one per partition.
Default NULL uses \code{grDevices::rainbow(K+1)} for 1D and a
Spectral palette for 2D.}

\item{add}{Logical; add to an existing plot (1D only). Default FALSE.}

\item{vars}{Numeric or character vector; predictor indices or names to
plot. Default \code{c()} plots all.}

\item{legend_order}{Numeric; re-ordered partition indices for the legend.}

\item{se.fit}{Logical; if TRUE, plot pointwise confidence bands. Default
FALSE.}

\item{cv}{Numeric; critical value for confidence bands. Default 1.}

\item{band_col}{Character; color for confidence band fill. Default
\code{"grey80"}.}

\item{band_border}{Character or NA; border color for confidence band
polygon. Default NA (no border).}

\item{fixed_values}{Named list; fixed values for non-plotted predictors
when \code{vars} is specified. Names should match predictor names.
Default NULL sets non-plotted predictors to zero.}

\item{n_grid}{Integer; number of grid points for automatic grid
generation when \code{vars} is specified and
\code{new_predictors} is NULL. Default 200.}

\item{...}{Additional arguments passed to \code{\link[graphics]{plot}}
(1D) or \code{\link[plotly]{plot_ly}} (2D).}
}
\value{
For 1D models: invisibly returns NULL (base R plot drawn to
  device). For 2D models: returns a plotly object.
}
\description{
Wrapper for the internal lgspline plot function. Produces a 1D line plot
(base R) or interactive 3D surface plot (plotly) depending on the number
of predictors, with optional formula overlays per partition. When plotting
a subset of variables via \code{vars}, non-plotted predictors are
automatically set to zero (or a user-specified value via
\code{fixed_values}).
}
\details{
Partition boundaries are indicated by color changes. For 1D models,
observation points can be overlaid. For 2D models, plotly is used.

When using \code{vars} to plot a subset of predictors, the non-plotted
predictors are automatically set to zero. This can be overridden by
passing a named list to \code{fixed_values} (e.g.,
\code{fixed_values = list(Height = 75)}). The automatic zeroing replaces
the previous behavior where the user had to manually construct
\code{new_predictors} with non-plotted variables set to fixed values.

When \code{se.fit = TRUE}, pointwise confidence bands are drawn around
the fitted function. These are Wald-type intervals constructed on the
link scale and back-transformed to the response scale, using
\code{cv} as the critical value to multiply se.fit by (default 1 for actual se).

The function extracts predictor positions from linear expansion terms.
If linear terms are excluded (e.g., via \code{exclude_these_expansions}),
plotting will fail. As a workaround, constrain those terms to zero via
\code{constraint_vectors} / \code{constraint_values} so they remain in
the expansion but are zeroed out.
}
\examples{

set.seed(1234)
t_data <- runif(1000, -10, 10)
y_data <- 2*sin(t_data) + -0.06*t_data^2 + rnorm(length(t_data))
model_fit <- lgspline(t_data, y_data, K = 9)

## Basic plot
plot(model_fit)

## Plot with confidence bands
plot(model_fit,
     se.fit = TRUE,
     cv = 1.96,
     custom_title = 'Fitted Function with 95\% CI')

## Multi-predictor: automatically zeros non-plotted variables
# plot(model_fit_2d, vars = 'x1', se.fit = TRUE)

}
\seealso{
\code{\link{lgspline}},
\code{\link[graphics]{plot}},
\code{\link[plotly]{plot_ly}}
}
