Skip to contents

The tab_style_by_grp function takes an existing gt_tbl object and styling according to each group. Currently it support styling the max()/min() for each group.

Usage

tab_style_by_grp(gt_object, column, fn, ...)

Arguments

gt_object

An existing gt table object of class gt_tbl

column

The column using tidy variable name or a number indicating which column should have the styling affect it.

fn

The name of a summarizing function (ie max(), min())

...

Arguments passed to tab_style(style = ...)

Value

An object of class gt_tbl.

Examples

library(gt)
df_in <- mtcars %>%
  dplyr::select(cyl:hp, mpg) %>%
  tibble::rownames_to_column() %>%
  dplyr::group_by(cyl) %>%
  dplyr::slice(1:4) %>%
  dplyr::ungroup()

test_tab <- df_in %>%
  gt(groupname_col = "cyl") %>%
  tab_style_by_grp(mpg, fn = max,
                   cell_fill(color = "red", alpha = 0.5))

Figures

Function ID

2-12