plot.fitverse: Diagnostic Plot for a 'fitverse' Object

View source: R/plot_fitverse.R

plot.fitverseR Documentation

Diagnostic Plot for a fitverse Object

Description

Produces a two-panel diagnostic figure for a fitted fitverse object:

  1. A histogram of the data overlaid with the fitted density curves for the top-ranked distributions. The PDF formula is annotated directly on the figure.

  2. A Q-Q plot of the empirical quantiles against theoretical quantiles from the best-fit distribution.

Either or both panels can be requested. The plot can optionally be returned as an interactive plotly HTML widget.

Usage

## S3 method for class 'fitverse'
plot(x,
     which       = "both",
     top_n       = 3L,
     xlab        = NULL,
     interactive = FALSE,
     draw        = TRUE,
     ...)

Arguments

x

An object of class "fitverse" as returned by fitverse().

which

Character scalar controlling which panels to draw. One of:

"both"

(default) Both density and Q-Q panels side by side.

"density"

Density histogram with overlaid PDF curves only.

"qq"

Q-Q plot only.

top_n

Integer: number of top-ranked models to overlay on the density panel. The best-fit model is drawn as a solid line; others as dashed lines with distinct colours. Default 3.

xlab

Character: x-axis label. If NULL (default), falls back to the xlab stored in x (set when fitverse() was called), then to "x" if that is also absent.

interactive

Logical: if TRUE and plotly is installed, converts the ggplot2 figure to a plotly interactive widget. Default FALSE.

draw

Logical: if TRUE (default), print the plot to the current graphics device. Set to FALSE to return the plot object silently without displaying it.

...

Currently unused; reserved for future extensions.

Details

The density panel uses ggplot2::geom_histogram(aes(y = after_stat(density))) with Freedman-Diaconis binning, overlaid with geom_line() curves evaluated on a fine grid of 512 points spanning the observed data range.

The Q-Q panel compares theoretical quantiles from the best-fit distribution (evaluated via qfitverse()) against the empirical quantiles of the data, with a 45-degree reference line.

When which = "both", the two ggplot2 objects are arranged side-by-side using gridExtra::grid.arrange(). When interactive = TRUE and which != "both", a single panel is converted with plotly::ggplotly().

Value

Invisibly returns the plot object(s):

  • A single ggplot2 object when which is "density" or "qq".

  • A grob (arranged grid object) when which = "both".

  • A plotly widget when interactive = TRUE.

Author(s)

Karuna G. Reddy karuna.reddy@auckland.ac.nz
M. G. M. Khan mgm.khan@usp.ac.fj

See Also

save_plot to write the figure to a PNG or PDF file.
fitverse which calls this function automatically when plot = TRUE.

Examples

set.seed(42)
x <- rgamma(300, shape = 2, rate = 0.5)
fit <- fitverse(x, plot = FALSE, verbose = FALSE)

# Both panels (default)
plot(fit)

# Density panel only with custom x-axis label
plot(fit, which = "density", xlab = "Value", top_n = 5)

# Q-Q plot only
plot(fit, which = "qq")

FitVerse documentation built on Dec. 1, 2026, 1:07 a.m.