Column labels can be modified from their default values (the names of the
columns from the input table data). When you create a gt table object
gt(), column names effectively become the column labels. While this
serves as a good first approximation, column names aren't often appealing as
column labels in a gt output table. The
provides the flexibility to relabel one or more columns and we even have the
option to use the
html() helper functions for rendering column
labels from Markdown or using HTML.
A table object that is created using the
One or more named arguments of column names from the input
Allows for the use of a list as an input alternative to
It's important to note that while columns can be freely relabeled, we
continue to refer to columns by their original column names. Column names in
a tibble or data frame must be unique whereas column labels in gt have
no requirement for uniqueness (which is useful for labeling columns as, say,
measurement units that may be repeated several times—usually under
different spanner column labels). Thus, we can still easily distinguish
between columns in other gt function calls (e.g., in all of the
fmt*() functions) even though we may lose distinguishability in column
labels once they have been relabeled.
An object of class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
# Use `countrypops` to create a gt table; # label all the table's columns to # present better tab_1 <- countrypops %>% dplyr::select(-contains("code")) %>% dplyr::filter(country_name == "Mongolia") %>% tail(5) %>% gt() %>% cols_label( country_name = "Name", year = "Year", population = "Population" ) # Use `countrypops` to create a gt table; # label columns as before but make them # bold with markdown formatting tab_2 <- countrypops %>% dplyr::select(-contains("code")) %>% dplyr::filter(country_name == "Mongolia") %>% tail(5) %>% gt() %>% cols_label( country_name = md("**Name**"), year = md("**Year**"), population = md("**Population**") )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.