Skip to contents

Bolds the body cells of chosen rows, with an option to recolor their text and fill their background. Rows are chosen by index or by a filter expression; with neither, every row is bolded.

Usage

gt_bold_rows(
  gt_object,
  rows = NULL,
  text_color = "black",
  highlight_color = NULL
)

Arguments

gt_object

A gt table object to modify.

rows

The rows to bold. Either an expression evaluated against the table's data, such as wins > 10, or a numeric vector of row indices. If NULL, every row is bolded. Defaults to NULL.

text_color

Character. The text color for the bolded rows. Defaults to "black".

highlight_color

Character. The background fill for the bolded rows. Set to NULL for no fill. Defaults to NULL.

Value

Returns a modified gt table with the chosen rows bolded.

Details

rows is evaluated against the table's underlying data, so rows = wins > 10 bolds the rows where that is TRUE; a numeric vector picks rows by index. The styling is applied with a single gt::tab_style() over gt::cells_body(), so it covers every column of the chosen rows.

Examples

library(gt)

nfc_west <- subset(
  sdv_example_standings, division == "NFC West",
  c(team_name, wins:points_against)
)

# bold every row
gt(nfc_west) |> gt_bold_rows()
team_name wins losses ties win_pct points_for points_against
Seattle Seahawks 14 3 0 0.824 483 292
Los Angeles Rams 12 5 0 0.706 518 346
San Francisco 49ers 12 5 0 0.706 437 371
Arizona Cardinals 3 14 0 0.176 355 488
# bold and fill the teams with a winning record gt(nfc_west) |> gt_bold_rows(rows = win_pct > 0.5, highlight_color = "#FFF3B0")
team_name wins losses ties win_pct points_for points_against
Seattle Seahawks 14 3 0 0.824 483 292
Los Angeles Rams 12 5 0 0.706 518 346
San Francisco 49ers 12 5 0 0.706 437 371
Arizona Cardinals 3 14 0 0.176 355 488