Shades every other row group, so each group reads as a block. gt::opt_row_striping()
bands every other row, which fights the grouping on a table that is already
divided into sections.
Arguments
- gt_object
A
gttable object to modify. It must have row groups.- color
Character. A hex color for the banded groups. Defaults to
"#F5F5F5".- start
Integer. Which group to begin banding on, in the order the groups are rendered.
2leaves the first group unshaded,1shades it. Defaults to2.- include_stub
Logical. Should the stub column be banded along with the body? Defaults to
TRUE.
Details
Groups are banded in the order they render, so this follows
gt::row_group_order() rather than the order the groups happen to appear in
the data.
The fill is applied to body cells rather than through CSS, because a group
heading occupies a row of its own and shifts every nth-child count below it.
Group heading rows are left alone; gt::tab_options(row_group.background.color)
sets those, and it sets all of them at once.
Examples
library(gt)
afc <- subset(
sdv_example_standings, conference == "AFC",
c(team_name, division, wins, losses, points_for)
)
gt(afc, groupname_col = "division") |>
gt_theme_broadsheet() |>
gt_group_stripes()
AFC East
AFC North
AFC South
AFC West
# shade from the first group instead, in a warmer tone
gt(afc, groupname_col = "division") |>
gt_group_stripes(color = "#FBF3E4", start = 1)
team_name
wins
losses
points_for
AFC East
AFC North
AFC South
AFC West
