rstudio / gt

Easily generate information-rich, publication-quality tables from R
https://gt.rstudio.com
Other
2.02k stars 205 forks source link

Enable ability to specify order of rows **within** a group #1112

Open andtheWings opened 1 year ago

andtheWings commented 1 year ago

Prework

Proposal

Currently, the user is able to specify the order of the groups in relation to each other using row_group_order(), but there is not a way to specify the order of rows within each group. This would be helpful for ordering rows within groups that have some inherent order to them that may not be obvious to {gt}.

One way would be to make it similar to the factor() function by adding an ordered = option within the tab_row_group():

gt_tbl |>
    tab_row_group(
        md("**Education**"), 
        c(
            less_than_high_school,
            high_school_diploma,
            some_college,
            college_diploma
        ),
        ordered = TRUE
    )

Another way would be to add an order_by = option which defaults to alphabetic, but can be set as user-specified.

rich-iannone commented 1 year ago

Thanks for getting this topic from Discussions over into an issue. It's a good one and I like the examples you included here! (A very great thing in a feature request.)