Wrapper around the ggplot2 ggsave function. Saves a ggplot (or other grid object) and captures analysis relevant metadata in a .json file
ggsave_with_metadata.Rd
Extension to the ggsave function that allows capturing object metadata as a separate .json file.
Usage
ggsave_with_metadata(
filename,
plot = ggplot2::last_plot(),
meta_type = "NA",
meta_equations = NULL,
meta_notes = NULL,
meta_abbrevs = NULL,
...
)
Arguments
- filename
File name to create on disk
- plot
Plot to save, defaults to last plot displayed
- meta_type
Parameter for specifying meta_type for write_object_metadata
- meta_equations
Parameter for specifying additional equations
- meta_notes
Parameter for specifying additional notes
- meta_abbrevs
Parameter for specifying additional abbreviations
- ...
Additional args to be used in ggsave
Examples
if (FALSE) { # \dontrun{
# Path to the analysis figures (.png) and metadata (.json files)
figures_path <- file.path(tempdir(), "figures")
# ---------------------------------------------------------------------------
# Construct a simple ggplot
# ---------------------------------------------------------------------------
g <- ggplot2::ggplot(
data = Theoph,
ggplot2::aes(x = Time, y = conc, group = Subject)
) +
ggplot2::geom_point() +
ggplot2::geom_line() +
ggplot2::theme_bw()
# Save a png using the helper function
out_name <- "01-12345-pk-timecourse1.png"
ggsave_with_metadata(
filename = file.path(figures_path, out_name),
)
} # }