View source: R/visualizer-lib-utils.R
plot_fit_constructor | R Documentation |
Experiment
fit.A helper function for developing new Visualizer
plotting
functions that plot results from particular replicate(s) in the
Experiment
fit. This function will construct one plot for each
row in the Experiment
's fit_results
from the specified
replicates.
plot_fit_constructor(
fit_results,
vary_params = NULL,
reps = 1,
plot_fun,
interactive = FALSE,
...
)
fit_results |
A tibble, as returned by |
vary_params |
A vector of |
reps |
Vector of replicates from which to plot results. |
plot_fun |
The plotting function, which takes in the arguments
|
interactive |
Logical. If |
... |
Additional arguments to pass to |
If interactive = TRUE
, returns a plotly
object or
list of plotly
objects if there are multiple replicates, DGPs, or
Methods to plot. If interactive = FALSE
, returns a ggplot
object or list of ggplot
objects if there are multiple replicates,
DGPs, or Methods to plot.
# 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))
)
# function to plot scatter plot of y vs predictions
plot_fun <- function(fit_results, vary_params = NULL) {
plt <- fit_results %>%
tidyr::unnest(c("y", "predictions")) %>%
ggplot2::ggplot() +
ggplot2::aes(x = y, y = predictions) +
ggplot2::geom_point() +
ggplot2::labs(title = sprintf("DGP: %s | Method: %s | Rep: %s",
fit_results$.dgp_name,
fit_results$.method_name,
fit_results$.rep))
return(plt)
}
# returns the scatter plot for each (DGP, Method) combination from rep 1
plt <- plot_fit_constructor(fit_results, reps = 1, plot_fun = plot_fun)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.