tab_footnote: Add a table footnote

Description Usage Arguments Details Value Figures Function ID See Also Examples

View source: R/tab_create_modify.R

Description

The tab_footnote() function can make it a painless process to add a footnote to a gt table. There are two components to a footnote: (1) a footnote mark that is attached to the targeted cell text, and (2) the footnote text (that starts with the corresponding footnote mark) that is placed in the table's footer area. Each call of tab_footnote() will add a different note, and one or more cells can be targeted via the location helper functions (e.g., cells_body(), cells_column_labels(), etc.).

Usage

1
tab_footnote(data, footnote, locations)

Arguments

data

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

footnote

The text to be used in the footnote. We can optionally use the md() and html() functions to style the text as Markdown or to retain HTML elements in the footnote text.

locations

The cell or set of cells to be associated with the footnote. Supplying any of the cells_*() helper functions is a useful way to target the location cells that are associated with the footnote text. These helper functions are: cells_title(), cells_stubhead(), cells_column_spanners(), cells_column_labels(), cells_row_groups(), cells_stub(), cells_body(), cells_summary(), and cells_grand_summary(). Additionally, we can enclose several cells_*() calls within a list() if we wish to link the footnote text to different types of locations (e.g., body cells, row group labels, the table title, etc.).

Details

The formatting of the footnotes can be controlled through the use of various parameters in the tab_options() function:

Value

An object of class gt_tbl.

Figures

Function ID

2-6

See Also

Other Create or Modify Parts: tab_header(), tab_options(), tab_row_group(), tab_source_note(), tab_spanner_delim(), tab_spanner(), tab_stubhead(), tab_style()

Examples

 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
# Use `sza` to create a gt table; color
# the `sza` column using the `data_color()`
# function, then, add a footnote to the
# `sza` column label explaining what the
# color scale signifies
tab_1 <-
  sza %>%
  dplyr::filter(
    latitude == 20 &
      month == "jan" &
      !is.na(sza)
  ) %>%
  dplyr::select(-latitude, -month) %>%
  gt() %>%
  data_color(
    columns = vars(sza),
    colors = scales::col_numeric(
      palette = c("white", "yellow", "navyblue"),
      domain = c(0, 90))
  ) %>%
  tab_footnote(
    footnote = "Color indicates height of sun.",
    locations = cells_column_labels(
      columns = vars(sza))
  )

gt documentation built on Aug. 6, 2020, 1:07 a.m.