Divides the selected columns and records the scaling in the same call, so the numbers and the disclosure cannot drift apart.
Usage
gt_scale_note(
gt_object,
columns,
divisor = 1000,
note = NULL,
where = c("source_note", "label", "both"),
label_suffix = NULL,
decimals = 0,
...
)Arguments
- gt_object
A
gttable object to modify.- columns
The column or columns to scale.
- divisor
Numeric. The amount to divide by. Defaults to
1000.- note
Optional. The disclosure text. If
NULL, it is derived fromdivisor, giving "Figures in thousands." for1e3, "Figures in millions." for1e6, and so on. Divisors without a common name fall back to "Figures divided by 2,500." Defaults toNULL.- where
Character. Where the disclosure goes. One of
"source_note","label"to append a suffix to the column labels instead, or"both". Defaults to"source_note".- label_suffix
Optional. The suffix appended to column labels when
whereincludes"label". IfNULL, it is derived fromdivisor(for example,"(000s)"). Defaults toNULL.- decimals
Integer. The number of decimal places for the scaled values. Defaults to
0.- ...
Additional arguments passed to
gt::fmt_number.
Details
Scaling is applied through gt::fmt_number() and its scale_by argument, so
the underlying data is left untouched.
Examples
library(gt)
# an NBA season's points, scored and allowed
atlantic <- subset(
sdv_example_standings, division == "Atlantic",
c(team_name, points_for, points_against)
)
# Boston's 9,418 points render as 9.4, with "Figures in thousands." beneath
gt(atlantic) |>
gt_scale_note(c(points_for, points_against), divisor = 1e3, decimals = 1)
team_name
points_for
points_against
Figures in thousands.
# disclose in the column labels instead
gt(atlantic) |>
gt_scale_note(c(points_for, points_against),
divisor = 1e3, decimals = 2, where = "label"
)
team_name
points_for (000s)
points_against (000s)
