Learn R Programming

PortfolioTesteR (version 0.1.4)

plot.param_grid_result: Plot Parameter Grid Results (1D/2D/3D and Facets)

Description

Generic plotter for objects returned by run_param_grid(). Supported types:

  • "line": 1D metric vs one parameter.

  • "heatmap": 2D heatmap over two parameters.

  • "surface": 3D surface (persp) over two parameters.

  • "slices": 2D heatmaps faceted by a third parameter.

  • "surface_slices": 3D surfaces faceted by a third parameter.

  • "auto": chosen from the above based on the number of parameters.

Usage

# S3 method for param_grid_result
plot(
  x,
  y = NULL,
  type = c("auto", "line", "heatmap", "surface", "slices", "surface_slices"),
  metric = NULL,
  params = NULL,
  fixed = list(),
  agg = c("mean", "median", "max"),
  na.rm = TRUE,
  palette = NULL,
  zlim = NULL,
  clip = c(0.02, 0.98),
  main = NULL,
  sub = NULL,
  xlab = NULL,
  ylab = NULL,
  ...
)

Value

An invisible list describing the plot (kind/params/zlim/etc.).

Arguments

x

A param_grid_result.

y

Ignored.

type

One of "auto","line","heatmap","surface","slices","surface_slices".

metric

Column name to plot (defaults to "score" if present).

params

Character vector of parameter columns to use for axes/facets. If NULL, uses all parameter columns detected in x$all_results.

fixed

Optional named list of parameter values to condition on. Rows not matching are dropped before plotting.

agg

Aggregation when multiple rows map to a cell: "mean","median", or "max".

na.rm

Logical; drop NA metric rows before plotting.

palette

Optional color vector used for heatmaps/surfaces. Defaults to grDevices::hcl.colors(..., "YlOrRd", rev = TRUE).

zlim

Optional two-element numeric range for color scaling.

clip

Two quantiles used to winsorize z-limits for stable coloring.

main, sub, xlab, ylab

Base plotting annotations.

...

Additional options depending on type, e.g.: legend, label_cells, contour, mark_best, theta, phi, shade, expand, ticktype, shared_zlim, facet, facet_values, ncol, debug, impute_for_surface.

See Also

run_param_grid(), print.param_grid_result()

Examples

Run this code
# \donttest{
  data(sample_prices_weekly)
  b <- function(prices, params, ...) {
    weight_equally(filter_top_n(calc_momentum(prices, params$lookback), 10))
  }
  opt <- run_param_grid(
    prices  = sample_prices_weekly,
    grid    = list(lookback = c(8, 12, 26)),
    builder = b
  )
  plot(opt, type = "line", params = "lookback")
# }

Run the code above in your browser using DataLab