View source: R/tab_create_modify.R
tab_stub_indent | R Documentation |
Indentation of row labels is an effective way for establishing structure in a
table stub. The tab_stub_indent()
function allows for fine control over
row label indentation in the stub. We can use an explicit definition of an
indentation level, or, employ an indentation directive using keywords.
tab_stub_indent(data, rows, indent = "increase")
data |
The gt table data object
This is the gt table object that is commonly created through use of the
|
rows |
Rows to target
The rows to consider for the indentation change. The default |
indent |
Indentation directive
An indentation directive either as a keyword describing the indentation
change or as an explicit integer value for directly setting the indentation
level. The keyword |
An object of class gt_tbl
.
from_column()
helper functionThe from_column()
helper function can be used with the indent
argument
of tab_stub_indent()
to obtain varying parameter values from a specified
column within the table. This means that each row label could be indented a
little bit differently.
Please note that for this argument (indent
), a from_column()
call needs
to reference a column that has data of the numeric
or integer
type.
Additional columns for parameter values can be generated with the
cols_add()
function (if not already present). Columns that contain
parameter data can also be hidden from final display with cols_hide()
.
Let's use a summarized version of the pizzaplace
dataset to create a
gt table with row groups and row labels. With the summary_rows()
function, we'll generate summary rows at the top of each row group. With
tab_stub_indent()
we can add indentation to the row labels in the stub.
pizzaplace |> dplyr::group_by(type, size) |> dplyr::summarize( sold = dplyr::n(), income = sum(price), .groups = "drop" ) |> gt(rowname_col = "size", groupname_col = "type") |> tab_header(title = "Pizzas Sold in 2015") |> fmt_integer(columns = sold) |> fmt_currency(columns = income) |> summary_rows( fns = list(label = "All Sizes", fn = "sum"), side = "top", fmt = list( ~ fmt_integer(., columns = sold), ~ fmt_currency(., columns = income) ) ) |> tab_options( summary_row.background.color = "gray95", row_group.background.color = "#FFEFDB", row_group.as_column = TRUE ) |> tab_stub_indent( rows = everything(), indent = 2 )
2-6
v0.7.0
(Aug 25, 2022)
Other part creation/modification functions:
tab_caption()
,
tab_footnote()
,
tab_header()
,
tab_info()
,
tab_options()
,
tab_row_group()
,
tab_source_note()
,
tab_spanner_delim()
,
tab_spanner()
,
tab_stubhead()
,
tab_style_body()
,
tab_style()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.