Iterates over plot specifications and produces rolling-difference plots for
both CAGR and log-return variants. Each plot is saved via save_plot(), and
optional XLM plots may also be generated. All generated plot objects are
stored in an environment and returned.
Usage
run_plots(
roll_diffs,
n_days,
plot_spec,
xlm_data = NULL,
add_gg_params = ggplot2::geom_blank(),
bmark_type = c("net", "gross"),
suffix = "",
...
)Arguments
- roll_diffs
A list of length 2 containing data frames, named
cagrandlog(CAGR differences and log-return differences).- n_days
Rolling-window length in days (passed to
plot_roll_diffs()for labelling).- plot_spec
A data frame or a list of data frames describing plot parameters. Expected columns include:
plot_id,title,data_filter,gg_params,width,height,funds.- xlm_data
Optional data frame used to produce XLM plots, including
date,xlm,ticker, andnamecolumns. Defaults toNULL.- add_gg_params
Optional ggplot component (or list of components) appended to each generated plot in addition to the per-plot
gg_paramsdefined inplot_spec. Defaults toggplot2::geom_blank().- bmark_type
Benchmark type used in plot titles:
"net"or"gross".- suffix
Character string appended to each
plot_idwhen constructing filenames and names in the returned environment. Defaults to"".- ...
Additional arguments passed to
plot_roll_diffs().
Value
An environment containing ggplot objects. Objects are stored under names
corresponding to the base filenames used in save_plot():
plot_id{suffix}for the CAGR variant,plot_id{suffix}_Lfor the log-return variant,and (when generated)
xlm_plot_id{suffix}for XLM plots.
Details
For each row in plot_spec, the function constructs both a CAGR-based and a
log-return-based variant using plot_roll_diffs() and writes the resulting
plots via save_plot(), using a filename suffix (_L) to distinguish the
log-return variant. The optional suffix is appended to plot_id before
filenames (and environment keys) are formed. Additional arguments in ...
are forwarded to plot_roll_diffs().
If plot_spec is provided as a list of data frames, the function binds them
into a single specification. The title column may be provided as a list
column (e.g. to keep a multilingual named vector as a single per-row value).
If xlm_data is supplied, an XLM plot is generated once per unique set of
Xetra tickers using plot_xlms(). Fund tickers are mapped to Xetra tickers
via the fundsr.xetra_map option (tickers not present in the map are used
as-is). The first plot specification encountered for a given ticker set
determines the base filename xlm_<plot_id{suffix}> used for saving and
storing the resulting XLM plot.