Skip to contents

Display a complete or sparse age-year table as a heatmap, surface or contour. Buttons change the metric, display type and value scale; an optional model selector compares models using the same ranges within each metric.

Usage

plot_matrix(
  data,
  metric = NULL,
  frame = NULL,
  type = c("heatmap", "surface", "contour"),
  signed = FALSE,
  y = ~age,
  ylab = "Age",
  y_labels = NULL
)

Arguments

data

A data frame with numeric year, age and est columns. Optional unit, definition, notes and is_proj columns enrich hover text.

metric

Optional one-sided formula selecting a metric column.

frame

Optional one-sided formula selecting a model column. Factor levels determine the initial model and selector order.

type

Initial display: "heatmap", "surface" or "contour".

signed

Use symmetric orange-white-navy ranges centred on zero and disable the log control? Default FALSE preserves ordinary matrix plots.

y

One-sided formula selecting the vertical coordinate, default ~age. Character/factor coordinates use ordered positions with each model's own labels, suitable for unique M state blocks.

ylab

Vertical-axis label, default "Age". A named character vector can supply a different label for each metric.

y_labels

Optional one-sided formula selecting display labels for the vertical coordinates, useful for model-specific state blocks.

Value

A Plotly object with independent controls for each widget.

Details

Linear shows original estimates, including zero. Log displays log10 estimates; nonpositive values are gaps. Hover text always shows original values and units. Ranges are shared across models separately for each metric. All models of a metric must use the same units. Colours use the built-in tam_cols() ramp from low to high values. Colour-ramp titles place units on a second line; axis labels remain on one line. Missing cells remain missing. Surface and contour rendering interpolates only for display and does not create additional source estimates.

Examples

d <- expand.grid(year = 2000:2005, age = 1:5)
d$est <- exp(.1 * (d$year - 2000) - .3 * d$age)
plot_matrix(d)