nl_plot: Plot predictions and derivatives from nl_fit models

View source: R/nl_plot.R

nl_plotR Documentation

Plot predictions and derivatives from nl_fit models

Description

Visualises results from nl_predict or nl_derivatives. The type argument selects the plot:

  • "trajectory": predicted outcome vs x with optional confidence ribbon (v1 behaviour, now default).

  • "slope": first derivative (marginal effect) vs x.

  • "curvature": second derivative vs x.

  • "combo": trajectory + slope panels side by side.

Usage

nl_plot(
  pred_df = NULL,
  deriv_df = NULL,
  x,
  time = NULL,
  type = c("trajectory", "slope", "curvature", "combo"),
  show_ci = TRUE,
  ci_level = 0.95,
  show_turning_points = FALSE,
  turning_points = NULL,
  zero_line = TRUE,
  y_lab = NULL,
  x_lab = NULL,
  title = NULL,
  legend_title = NULL
)

Arguments

pred_df

A data frame from nl_predict (for type = "trajectory" or "combo").

deriv_df

A data frame from nl_derivatives (for type = "slope", "curvature", or "combo").

x

Character; name of the focal predictor column in pred_df / deriv_df.

time

Optional character; name of the time column. Auto-detected if NULL.

type

Plot type: "trajectory" (default), "slope", "curvature", or "combo".

show_ci

Logical; add confidence ribbons. Default TRUE.

ci_level

Numeric; confidence level when deriving CI from se.fit. Default 0.95.

show_turning_points

Logical; overlay turning-point markers on the trajectory plot. Default FALSE.

turning_points

Data frame from nl_turning_points (only used when show_turning_points = TRUE).

zero_line

Logical; for slope / curvature plots, draw a dashed horizontal line at zero. Default TRUE.

y_lab

Y-axis label.

x_lab

X-axis label. Defaults to x.

title

Optional plot title.

legend_title

Optional legend title.

Value

A ggplot object (or a combined plot list for "combo").

See Also

nl_predict, nl_derivatives, nl_turning_points


MultiSpline documentation built on April 16, 2026, 9:06 a.m.