5 Customizing the look
In this chapter, we polish the look starting from the following table.
5.1 First, know the column names: show_header_names()
To change headers, you need to know the internal column names.
You can see column names such as label (the variable-name column), stat_1, stat_2 (each group), and p.value.
5.2 Changing headers: modify_header()
**…**for bold,\n(two spaces + newline) for a line break{level}(group name),{n}(group size),{N}(overall size), and{p}(proportion) are available
5.3 Spanning headers: modify_spanning_header()
5.4 Changing footnotes
To remove footnotes, use remove_footnote_header(columns = all_stat_cols()).
5.5 Abbreviation notes: modify_abbreviation()
5.6 Table title: modify_caption()
5.7 Bold and italics
5.8 Hiding columns and reordering rows
5.9 Editing the contents directly: modify_table_body()
A gtsummary table internally holds a data frame called table_body. With modify_table_body() you can edit it directly with dplyr functions.
Example: rewrite the Unknown (missing) rows as “Missing”
Most customizations can be done with the dedicated modify_*() functions. It is handy to remember modify_table_body() as a last resort.
5.10 Themes: changing formatting all at once
You can switch the format for a particular journal or the language all at once. A theme applies to all tables built after it is set.
Setting a theme prints a Setting theme ... message in red, but it is not an error.
5.10.1 Journal formats
"jama", "lancet", "nejm", and "qjecon" are available. In the JAMA format, statistics are combined into one cell as “Median (IQR)”, and the p-value format also changes.
5.10.2 Language: Japanese
Headers, footnotes, and test names become Japanese (you translate the variable labels yourself). Other languages are available too (e.g. "es", "fr", "de"; see ?theme_gtsummary_language).
5.10.3 Compact display
5.10.4 Resetting
Writing the themes together at the top of your script keeps the format of all tables in a paper consistent.
theme_gtsummary_journal("jama")
theme_gtsummary_compact()- Check column names with
show_header_names()→modify_header()/modify_spanning_header() - Footnotes:
modify_footnote_header(); abbreviations:modify_abbreviation(); title:modify_caption() bold_labels(),italicize_levels(),bold_p(),sort_p(),modify_column_hide()- Themes:
theme_gtsummary_journal(),theme_gtsummary_language(),theme_gtsummary_compact()