Visualise a Triangle object as a triangle-style table. Cells are arranged by
period and dev dimensions, and each cell displays the selected metric.
For ratio metrics (ratio, incr_ratio), labels can show either the ratio alone or
the ratio together with the associated loss / risk premium amounts.
For amount metrics (loss, incr_loss, premium, incr_premium, margin, incr_margin),
labels show the selected amount only.
For proportion metrics (loss_share, incr_loss_share, premium_share, incr_premium_share),
labels are displayed as percentages.
The loss ratio is defined as: $$ratio = loss / premium$$
where premium denotes risk premium rather than written premium.
Usage
# S3 method for class 'Triangle'
plot_triangle(
x,
view = c("value", "usage"),
metric = "ratio",
label_style = c("value", "detail"),
label_size = NULL,
amount_divisor = "auto",
nrow = NULL,
ncol = NULL,
theme = c("view", "save", "shiny"),
...
)Arguments
- x
An object of class
Triangle.- view
Plot view. One of:
- "value"
(default) Per-cell metric heatmap controlled by
metric,label_style,amount_divisor,nrow,ncol.- "usage"
Cell-status heatmap (used / holdout / unused / future). Accepts
recent,regime,holdout,maturityvia.... Seevignette("diagnostics")for details.
- metric
A single metric to plot. Must be one of:
"ratio","incr_ratio","loss","incr_loss","premium","incr_premium","margin","incr_margin","loss_share","incr_loss_share","premium_share", or"incr_premium_share".- label_style
Label display style. One of:
- "value"
Show only the selected metric.
- "detail"
For
ratio/incr_ratio, show the ratio in percent and, on the next line, the associated loss / premium amounts. For amount and proportion metrics, this falls back to"value".
- label_size
Numeric size of the in-cell text label. Defaults to
3forlabel_style = "value"and2.5forlabel_style = "detail"(two-line labels need a smaller size to fit). Other label appearance fields (family, color, hjust, ...) fall back to the standard label defaults.- amount_divisor
Numeric scaling factor applied to amount variables (e.g.,
loss,incr_loss,premium,incr_premium,margin,incr_margin) before plotting. Default"auto"picks the largest divisor in{1, 1e3, 1e6, 1e7, 1e8, 1e9}such that the median displayed value is still at least1, minimising label digit count.- nrow, ncol
Number of rows and columns passed to
ggplot2::facet_wrap().- theme
A string passed to
.switch_theme()("view","save","shiny").- ...
Additional arguments passed to
.switch_theme().
Details
The x-axis uses the development variable stored in attr(x, "dev"), and
the y-axis uses the period variable stored in attr(x, "cohort").
If either axis variable is a period-like variable such as uy_m, cy_m,
uy_q, cy_q, uy_h, cy_h, uy, or cy, it is formatted using
.format_period().
Facets are created from attr(x, "groups").
Ratio and proportion values are displayed in percent. Amount values are displayed in units of 100 million KRW.
Examples
if (FALSE) { # \dontrun{
d <- as_triangle(
df,
groups = "pd_cat_nm",
cohort = "uy_m",
calendar = "cy_m",
loss = "incr_loss",
premium = "incr_premium"
)
plot_triangle(d)
plot_triangle(d, metric = "ratio")
plot_triangle(d, metric = "loss")
plot_triangle(d, metric = "premium")
plot_triangle(d, metric = "loss_share")
plot_triangle(d, metric = "premium_share")
plot_triangle(d, label_style = "value")
plot_triangle(d, label_style = "detail")
} # }
