
Save a ggplot chart with an econanalyzr-style filename
Source:R/save_econanalyzr_chart.R
save_econanalyzr_chart.RdBuilds 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
ggplotobject.- folder
Output directory path. Created if it doesn't exist.
- data
Optional data frame for filename construction. If
NULL, usesplt$data. Must satisfycheck_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 toggplot2::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 toggsave()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 fromdata.- ...
Additional arguments forwarded to
ggplot2::ggsave()whenengine = "ggsave".
Details
Filename construction reuses package helpers:
make_file_name_date()for the date stem (singleYYYY-MM-DDormax_minrange),make_metadata_vec()for tokens derived from all*_textcolumns in order,sanitize_filename()to make a safe, lowercase slug.
Saving backends:
engine = "ggsave"(default): callsggplot2::ggsave(), honoringdevice,width,height,units,dpi,scale,bg, and any extra...thatggsave()supports.engine = "grDevices": opens base devices (png/jpeg/tiff/bmp/pdf/svg) viaecon_viz_save_grdevices().engine = "ragg": high-quality raster (png/jpeg/tiff) viaecon_viz_save_ragg()(Suggests: ragg).engine = "svglite": vector SVG viaecon_viz_save_svglite()(Suggests: svglite).