
Compute pixel and inch dimensions for visualization devices
Source:R/utils-econ_viz_dims.R
, R/utils-econ_viz_save_grdevices.R
, R/utils-econ_viz_save_ragg.R
, and 4 more
econanalyzr-viz-helpers.Rd
Converts user-supplied width
, height
, units
, and dpi
into:
integer pixel sizes (for raster devices, e.g., PNG/JPEG/TIFF), and
floating-point inch sizes (for vector devices, e.g., PDF/SVG).
Opens a base graphics device (png/jpeg/tiff/bmp/pdf/svg), prints the ggplot,
and closes the device. Raster devices use pixels + res
; vector devices use inches.
Uses ragg::agg_png()
, ragg::agg_jpeg()
, or ragg::agg_tiff()
for
high-quality raster output. Requires ragg in Suggests.
This helper checks availability with rlang::is_installed()
and never attaches ragg.
Uses svglite::svglite()
for clean SVG output. Requires svglite in Suggests.
Checks availability with rlang::is_installed()
and never attaches svglite.
If there is exactly one unique non-NA date, return it as YYYY-MM-DD
.
If there are multiple, return maxDate_minDate
(both formatted YYYY-MM-DD
).
Errors if there are no non-NA dates or if date_vec
is not Date/POSIXt.
Produces a conservative, filesystem-friendly slug:
Lowercases the string.
Replaces any whitespace (one or more) with underscores.
Replaces any character not in
[a-z0-9._-]
with underscores.Collapses multiple underscores to a single underscore.
Trims leading/trailing underscores and dots.
Usage
econ_viz_dims(width, height, units, dpi)
econ_viz_save_grdevices(plt, outpath, ext, dims, bg, dpi)
econ_viz_save_ragg(plt, outpath, ext, dims, bg, dpi)
econ_viz_save_svglite(plt, outpath, ext, dims)
make_file_name_date(date_vec)
make_metadata_vec(df_text, na_token = "na", warn_all_na = TRUE)
sanitize_filename(x)
Arguments
- width, height
Numeric scalars: requested size.
- units
Character scalar: one of
"px"
,"in"
,"cm"
,"mm"
.- dpi
Resolution (passed as
res
).- plt
A ggplot object to print.
- outpath
File path (including extension) to write to.
- ext
Lowercased extension; must be "svg".
- dims
List from
econ_viz_dims()
:width_in
,height_in
(inches).- bg
Background color (e.g., "white", "transparent").
- date_vec
A Date vector (POSIXt allowed; coerced to Date).
- df_text
Data frame of *_text columns.
- na_token
Token to use when a column is all NA.
- warn_all_na
If TRUE, warn when a column is all NA.
- x
A character vector (will be coerced via
as.character()
).