A ggplot2::ggsave()-compatible wrapper (defaulting to
ggplot2::ggsave() itself, but swappable via save_fun – e.g. for
reportifyr::ggsave_with_metadata() or any other function sharing
ggsave()'s plot/filename/path/width/height signature).
Before saving: resolved labels are applied via apply_default_labs()
and a configured watermark (if any) via add_watermark() – see
apply_labs/apply_watermark, both of which default to the
xpose.xtras.auto_apply option (TRUE unless changed), the same
switch print.xpose_plot() uses, so a plot looks the
same whether it's viewed interactively or saved with ggsave_xp().
filename/path have any @keyword placeholders expanded via
xpose::parse_title(), the same way xpose::xpose_save() does
(independent of which save_fun is used, since most save functions
don't do this themselves); and path/width/height/save_fun fall
back to the xpose.xtras.save_dir, xpose.xtras.save_width,
xpose.xtras.save_height, and xpose.xtras.save_fun R options when not
supplied explicitly, so a project can set output defaults once (see
set_xtras_options()).
Usage
ggsave_xp(
plot = ggplot2::last_plot(),
filename,
path = getOption("xpose.xtras.save_dir"),
width = getOption("xpose.xtras.save_width", 7),
height = getOption("xpose.xtras.save_height", 6),
xpdb = NULL,
apply_labs = getOption("xpose.xtras.auto_apply", TRUE),
apply_watermark = getOption("xpose.xtras.auto_apply", TRUE),
save_fun = getOption("xpose.xtras.save_fun", ggplot2::ggsave),
...
)Arguments
- plot
<
ggplot> or <xpose_plot> object- filename
<
character> File name, optionally with@keywordplaceholders (e.g."@run_@plotfun.pdf", seexpose::parse_title()).@plotfun(the name of the function that builtplot, e.g."dv_vs_ipred") only resolves whenplotis anxpose_plot, since it isn't something a barexpdbknows about- path
<
character> Directory to save in; falls back to thexpose.xtras.save_dirR option- width, height
<
numeric> Plot size (in inches by default, seesave_fun's ownunitsargument if it has one); fall back to thexpose.xtras.save_width/xpose.xtras.save_heightR options- xpdb
<
xpose_data> or <xp_xtras> objectplotwas built from, forwarded toapply_default_labs()/add_watermark()(see theirxpdbargument) and used to resolve@keywordplaceholders- apply_labs
<
logical> Applyapply_default_labs()toplotbefore saving; defaults to thexpose.xtras.auto_applyoption (TRUEunless changed)- apply_watermark
<
logical> Applyadd_watermark()toplotbefore saving, if adefault_watermarkis configured at some tier (seeadd_watermark()) – otherwise a no-op regardless; defaults to thexpose.xtras.auto_applyoption (TRUEunless changed)- save_fun
<
function> The actual save function to call, e.g.ggplot2::ggsave()(the default) or a drop-in alternative such asreportifyr::ggsave_with_metadata(); falls back to thexpose.xtras.save_funR option, thenggplot2::ggsave()- ...
Passed on to
save_fun(e.g.device,dpi,units,bg)
Value
the result of save_fun (for the default ggplot2::ggsave(),
the saved file path, invisibly)
See also
set_xtras_options() for the full list of xpose.xtras.*
session options.
Examples
if (FALSE) { # \dontrun{
options(xpose.xtras.save_dir = "figures", xpose.xtras.save_width = 8)
p <- xpose::dv_vs_ipred(xpose::xpdb_ex_pk)
ggsave_xp(p, filename = "dv_vs_ipred.png")
} # }
