This function creates posterior density plots for the hierarchical Bayesian model parameters aggregated by species complex. It uses the stanfit object and associated data generated by `run_stan()`. The plot can optionally be saved to a specified directory.

plot_density(
  stan_results,
  unlabel = FALSE,
  plot_dir = NULL,
  complex_names = NULL
)

Arguments

stan_results

Named list output from `run_stan()` containing the fitted model and related data.

unlabel

Logical. If TRUE, removes labels from the plot. Default is FALSE.

plot_dir

Optional character. Directory path to save the plot image. If NULL, the plot is not saved.

complex_names

Optional character vector. Names of species complexes to include in the plot. If NULL, all are included.

genus

Logical. Adjusts vertical size of the plot. Default is TRUE.