Skip to contents

Builds a descriptive filename from the plot's data (or a supplied data frame): <date_or_range>-<meta1>-<meta2>-...-<metaK>.<ext>.

Usage

save_econanalyzr_chart(
  plt,
  folder,
  data = NULL,
  engine = c("ggsave", "grDevices", "ragg", "svglite"),
  device = "png",
  format = "png",
  width = 3600,
  height = 2010,
  units = "px",
  dpi = 320,
  scale = 1,
  bg = "white",
  overwrite = FALSE,
  quiet = FALSE,
  name_stem = NULL,
  ...
)

Arguments

plt

A ggplot object.

folder

Output directory path. Created if it doesn't exist.

data

Optional data frame for filename construction. If NULL, uses plt$data. Must satisfy check_econanalyzr_df() or a classed error is raised.

engine

Saving backend: one of "ggsave" (default), "grDevices", "ragg", "svglite".

device

For engine = "ggsave", a device passed to ggplot2::ggsave() (e.g., "png", "pdf", "svg", "jpeg", "tiff", or a device function). Ignored otherwise.

format

Output format/extension for non-ggsave engines. One of "png", "pdf", "svg", "jpeg", "jpg", "tiff", "bmp". Default "png".

width, height

Plot size (defaults target a crisp social card): width = 3600, height = 2010.

units

Units for width/height: "px" (default), "in", "cm", "mm".

dpi

Resolution in dots per inch (used for raster devices or when converting from inches).

scale

Scaling factor (multiplies width/height) passed to ggsave() only.

bg

Background: "white" (default), "transparent", etc. Passed to raster devices / ggsave().

overwrite

If FALSE (default) and the target file exists, abort with a classed error.

quiet

If FALSE (default) emit an informational message on success.

name_stem

Optional override for the filename stem (no extension). Will be sanitized. If NULL, the stem is built from data.

...

Additional arguments forwarded to ggplot2::ggsave() when engine = "ggsave".

Value

(Invisibly) the full file path written.

Details

Filename construction reuses package helpers:

Saving backends:

  • engine = "ggsave" (default): calls ggplot2::ggsave(), honoring device, width, height, units, dpi, scale, bg, and any extra ... that ggsave() supports.

  • engine = "grDevices": opens base devices (png/jpeg/tiff/bmp/pdf/svg) via econ_viz_save_grdevices().

  • engine = "ragg": high-quality raster (png/jpeg/tiff) via econ_viz_save_ragg() (Suggests: ragg).

  • engine = "svglite": vector SVG via econ_viz_save_svglite() (Suggests: svglite).