save_plot: Save a FitVerse Diagnostic Plot to File

View source: R/plot_fitverse.R

save_plotR Documentation

Save a FitVerse Diagnostic Plot to File

Description

Renders the two-panel diagnostic plot for a fitverse object and saves it as a high-resolution PNG (or PDF) file, without displaying the figure on the current graphics device. Suitable for embedding in reports or automated pipelines.

Usage

save_plot(fit,
          file        = file.path(tempdir(), "fitverse_plot.png"),
          which       = "both",
          top_n       = 3L,
          xlab        = NULL,
          width       = 14,
          height      = 5.5,
          dpi         = 600,
          ...)

Arguments

fit

An object of class "fitverse".

file

Character: output file path. The file extension determines the format: .png (default), .pdf, or .svg. Default file.path(tempdir(), "fitverse_plot.png").

which

Which panels to save: "both" (default), "density", or "qq". See plot.fitverse for details.

top_n

Number of top-ranked distributions to show on the density panel. Default 3.

xlab

Character: x-axis label. Defaults to fit$xlab if present, otherwise "x".

width

Numeric: plot width in inches. Default 14.

height

Numeric: plot height in inches. Default 5.5.

dpi

Integer: resolution in dots per inch. Default 600. Ignored for PDF output.

...

Additional arguments passed to plot.fitverse().

Details

Uses grDevices::png() (or grDevices::pdf() / grDevices::svg() depending on file extension) and gridExtra::grid.arrange() to render both panels in a single device call, ensuring consistent alignment.

The function opens the graphics device, renders the figure, and closes the device via on.exit(), so the current interactive device is unaffected.

Value

Invisibly returns the normalised path to the saved file (character).

Author(s)

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

See Also

plot.fitverse for interactive display.

Examples


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

save_plot(fit, file = tempfile(fileext = ".png"))


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