gtcars |>
filter(
mfr == "Mercedes-Benz" | mfr == "Rolls-Royce"
) |>
select(mfr, model, hp, trq, year, bdy_style, msrp) |>
arrange(mfr, model) |>
gt(
groupname_col = "mfr",
rowname_col = "model"
) |>
tab_header(
title = md("**Modern High-Performance Cars**"),
subtitle = "Comparing Mercedes-Benz and Rolls-Royce"
) |>
cols_label(
hp = "Horsepower",
trq = "Torque",
year = "Year",
bdy_style = "Style",
msrp = "MSRP"
) |>
tab_spanner(
label = "Performance",
columns = c(hp, trq)
) |>
tab_spanner(
label = "Configuration",
columns = c(year, bdy_style)
) |>
tab_source_note(
source_note = md("Data from the *gtcars* dataset (v0.2.0.5).")
) |>
tab_footnote(
footnote = "Manufacturer's suggested retail price.",
locations = cells_column_labels(
columns = msrp
)
) |>
cols_align(
align = "center",
columns = c(hp, trq, year, bdy_style)
) |>
fmt_currency(
columns = msrp,
decimals = 0
) |>
tab_style(
style = list(
cell_text(weight = "bold"),
cell_fill(color = "lightgray")
),
locations = cells_row_groups()
)