The tab_stub_indent()
function
Use pizzaplace
to create a gt table with summary rows at the top of each row group. With tab_stub_indent()
we can add indentation to the row labels in the stub.
pizzaplace |>
dplyr:: group_by (type, size) |>
dplyr:: summarize (
sold = dplyr:: n (),
income = sum (price),
.groups = "drop"
) |>
gt (rowname_col = "size" , groupname_col = "type" ) |>
tab_header (title = "Pizzas Sold in 2015" ) |>
fmt_integer (columns = sold) |>
fmt_currency (columns = income) |>
summary_rows (
fns = list (label = "All Sizes" , fn = "sum" ),
side = "top" ,
fmt = list (
~ fmt_integer (., columns = sold),
~ fmt_currency (., columns = income)
)
) |>
tab_options (
summary_row.background.color = "gray95" ,
row_group.background.color = "#FFEFDB" ,
row_group.as_column = TRUE
) |>
tab_stub_indent (
rows = everything (),
indent = 2
)
Pizzas Sold in 2015
sold
income
chicken All Sizes
11,050
$195,919.50
L
4,932
$102,339.00
M
3,894
$65,224.50
S
2,224
$28,356.00
classic All Sizes
14,888
$220,053.10
L
4,057
$74,518.50
M
4,112
$60,581.75
S
6,139
$69,870.25
XL
552
$14,076.00
XXL
28
$1,006.60
supreme All Sizes
11,987
$208,197.00
L
4,564
$94,258.50
M
4,046
$66,475.00
S
3,377
$47,463.50
veggie All Sizes
11,649
$193,690.45
L
5,403
$104,202.70
M
3,583
$57,101.00
S
2,663
$32,386.75