Skip to contents

Generates an interactive plotly visualization of growth trajectories with hover information, zoom capabilities, and customization options.

Usage

plot_interactive(
  object,
  type = c("trajectories", "individual", "spaghetti"),
  interactive = TRUE,
  show_ci = TRUE,
  show_points = FALSE,
  n_individuals = 10,
  color_palette = NULL,
  title = NULL,
  ...
)

Arguments

object

Fitted SurveyMixr object

type

Character: "trajectories" (default), "individual", or "spaghetti"

interactive

Logical; if TRUE, returns plotly object; if FALSE, returns ggplot

show_ci

Logical; show confidence intervals?

show_points

Logical; show individual observed points?

n_individuals

For "individual" plots, number of individuals to show per class

color_palette

Character vector of colors or name of palette

title

Optional plot title

...

Additional arguments passed to plotting functions

Value

If interactive = TRUE, a plotly object; otherwise a ggplot object

Details

Creates interactive visualizations with the following features:

**Hover Information:** - Class label and proportion - Parameter estimates (intercept, slope) - Confidence intervals - Individual IDs (for individual plots)

**Interactivity:** - Zoom and pan - Toggle classes on/off - Download as PNG - Customizable layout

**Plot Types:** - **trajectories**: Class-specific mean trajectories with CI - **individual**: Sample of individual trajectories within each class - **spaghetti**: All individual trajectories overlaid

Examples

if (FALSE) { # \dontrun{
# Full example (requires plotly package)
data(mcs_simulated)

fit <- gmm_survey(
  data = mcs_simulated,
  id = "id", time = "age", outcome = "selfcontrol",
  n_classes = 3, starts = 100
)

# Interactive trajectory plot
plot_interactive(fit, type = "trajectories")

# Spaghetti plot showing individual trajectories
plot_interactive(fit, type = "spaghetti", n_individuals = 50)

# Save to HTML file
p <- plot_interactive(fit)
htmlwidgets::saveWidget(p, "gmm_trajectories.html")
} # }