View source: R/visualizer-lib-utils.R
plot_eval_constructor | R Documentation |
A helper function for developing new Visualizer
plotting
functions that plot the summarized evaluation results as a boxplot,
scatter plot, line plot, or bar plot with or without 1 SD error
bars/ribbons. This function accepts either (1) the name(s) of the
Evaluator(s)
to plot (eval_names
) or (2) a tibble containing
the summarized evaluation results to plot (plot_data
).
plot_eval_constructor(
eval_results = NULL,
eval_names = NULL,
plot_data = NULL,
eval_id = NULL,
vary_params = NULL,
show = c("boxplot", "point", "line", "bar", "errorbar", "ribbon", "violin"),
x_str = "auto",
y_str = "auto",
y_boxplot_str = "auto",
err_sd_str = "auto",
color_str = "auto",
linetype_str = "auto",
facet_formula = NULL,
facet_type = c("grid", "wrap"),
plot_by = "auto",
add_ggplot_layers = NULL,
boxplot_args = NULL,
point_args = NULL,
line_args = NULL,
bar_args = NULL,
errorbar_args = NULL,
ribbon_args = NULL,
violin_args = NULL,
facet_args = NULL,
interactive = FALSE,
...
)
eval_results |
A list of result tibbles, as returned by
|
eval_names |
(Optional) A character vector or string, specifying the
name(s) of |
plot_data |
(Optional) |
eval_id |
(Optional) Character string. ID used as the suffix for naming
columns in evaluation results tibble. If |
vary_params |
A vector of |
show |
Character vector with elements being one of "boxplot", "point", "line", "bar", "errorbar", "ribbon", "violin", indicating what plot layer(s) to construct. |
x_str |
(Optional) Name of column in data frame to plot on the x-axis. Default "auto" chooses what to plot on the x-axis automatically. |
y_str |
(Optional) Name of column in data frame to plot on the
y-axis if |
y_boxplot_str |
(Optional) Name of column in data frame to plot on
the y-axis if |
err_sd_str |
(Optional) Name of column in data frame containing the
standard deviations of |
color_str |
(Optional) Name of column in data frame to use for the
color and fill aesthetics when plotting. Default "auto" chooses what to
use for the color and fill aesthetics automatically. Use |
linetype_str |
(Optional) Name of column in data frame to use for
the linetype aesthetic when plotting. Used only when |
facet_formula |
(Optional) Formula for |
facet_type |
One of "grid" or "wrap" specifying whether to use
|
plot_by |
(Optional) Name of column in |
add_ggplot_layers |
List of additional layers to add to a ggplot object
via |
boxplot_args |
(Optional) Additional arguments to pass into
|
point_args |
(Optional) Additional arguments to pass into
|
line_args |
(Optional) Additional arguments to pass into
|
bar_args |
(Optional) Additional arguments to pass into
|
errorbar_args |
(Optional) Additional arguments to pass into
|
ribbon_args |
(Optional) Additional arguments to pass into
|
violin_args |
(Optional) Additional arguments to pass into
|
facet_args |
(Optional) Additional arguments to pass into
|
interactive |
Logical. If |
... |
Not used. |
If interactive = TRUE
, returns a plotly
object if
plot_by
is NULL
and a list of plotly
objects if
plot_by
is not NULL
. If interactive = FALSE
, returns
a ggplot
object if plot_by
is NULL
and a list of
ggplot
objects if plot_by
is not NULL
.
# generate example fit results data
fit_results <- tibble::tibble(
.rep = rep(1:2, times = 2),
.dgp_name = c("DGP1", "DGP1", "DGP2", "DGP2"),
.method_name = c("Method"),
# true response
y = lapply(1:4, FUN = function(x) rnorm(100)),
# predicted response
predictions = lapply(1:4, FUN = function(x) rnorm(100))
)
# generate example evaluation results data
eval_results <- list(
`Prediction Errors` = summarize_pred_err(
fit_results = fit_results,
truth_col = "y",
estimate_col = "predictions",
eval_id = "pred_err"
)
)
# create plot using name of Evaluator
plt <- plot_eval_constructor(eval_results = eval_results,
eval_name = "Prediction Errors",
eval_id = "pred_err",
show = c("point", "errorbar"),
facet_formula = ~ .metric)
# create plot using pre-computed evaluation results
plt <- plot_eval_constructor(plot_data = eval_results[["Prediction Errors"]],
eval_id = "pred_err",
show = c("point", "errorbar"),
facet_formula = ~ .metric)
# can customize plots using additional arguments or ggplot2::`+`
plt <- plot_eval_constructor(eval_results = eval_results,
eval_name = "Prediction Errors",
eval_id = "pred_err",
show = c("point", "errorbar"),
facet_formula = ~ .metric,
facet_type = "wrap",
errorbar_args = list(width = 0.5),
facet_args = list(scales = "free")) +
ggplot2::labs(y = "Mean Prediction Error")
# can return interactive plotly plot
plt <- plot_eval_constructor(eval_results = eval_results,
eval_name = "Prediction Errors",
eval_id = "pred_err",
show = c("point", "errorbar"),
facet_formula = ~ .metric,
interactive = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.