Learn R Programming

gt (version 0.2.2)

row_group_order: Modify the ordering of any row groups

Description

We can modify the display order of any row groups in a gt object with the row_group_order() function. The groups argument can either take a vector of row group names or a numeric vector of row group indices; whichever is provided, the row groups will adhere to this revised ordering. It isn't necessary to provide all row group names in groups, rather, what is provided will assume the specified ordering at the top of the table and the remaining row groups will follow in their original ordering.

Usage

row_group_order(data, groups)

Arguments

data

A table object that is created using the gt() function.

groups

A vector of row group names, or, a numeric vector of indices corresponding to the new ordering. Either vector must correspond to assigned group names or the index positions. Also, either type of vector is not required to have all of the row group names or available index positions within it; any omitted values will be added to the end while preserving the original ordering.

Value

An object of class gt_tbl.

Figures

Function ID

5-1

Examples

Run this code
# NOT RUN {
# Use `exibble` to create a gt table
# with a stub and with row groups;
# modify the order of the row groups
# with `row_group_order()`, specifying
# the new ordering in `groups`
tab_1 <-
  exibble %>%
  dplyr::select(char, currency, row, group) %>%
    gt(
      rowname_col = "row",
      groupname_col = "group"
    ) %>%
    row_group_order(
      groups = c("grp_b", "grp_a")
    )

# }

Run the code above in your browser using DataLab