-
Notifications
You must be signed in to change notification settings - Fork 200
/
html-13-adding_footnotes.Rmd
79 lines (75 loc) · 2.07 KB
/
html-13-adding_footnotes.Rmd
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
title: "html-13-adding_footnotes"
output:
- html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(gt)
library(tidyverse)
```
Create a table with footnotes in various cell types
```{r}
# Input table
tbl <-
dplyr::tribble(
~date, ~rowname, ~value_1, ~value_2,
"2018-02-10", "1", 20.4, 361.1,
"2018-02-10", "2", 10.9, 743.3,
"2018-02-10", "3", 34.6, 344.7,
"2018-02-10", "4", 8.3, 342.3,
"2018-02-11", "5", 28.3, 234.9,
"2018-02-11", "6", 75.5, 190.9,
"2018-02-11", "7", 63.1, 2.3,
"2018-02-11", "8", 25.8, 184.3,
"2018-02-11", "9", 5.2, 197.2,
"2018-02-11", "10", 55.3, 284.6
)
```
```{r}
gt(
data = tbl,
groupname_col = "date"
) %>%
tab_header(title = "The Table Title", subtitle = "The subtitle.") %>%
tab_spanner(
label = "values",
columns = starts_with("value")
) %>%
tab_footnote(
footnote = "This is an even smaller number.",
locations = cells_body(columns = value_1, rows = 9)
) %>%
tab_footnote(
footnote = "This is a small number.",
locations = cells_body(columns = value_1, rows = 4)
) %>%
tab_footnote(
footnote = "First data cell.",
locations = cells_body(columns = "value_1", rows = 1)
) %>%
tab_footnote(
footnote = "The first row group",
locations = cells_row_groups(groups = ends_with("10"))
) %>%
tab_footnote(
footnote = "Two sets of values",
locations = cells_column_spanners(spanners = starts_with("val"))
) %>%
tab_footnote(
footnote = "A stub cell.",
locations = cells_stub(rows = 1)
) %>%
tab_footnote(
footnote = md("`value_1` is the first column of values."),
locations = cells_column_labels(columns = value_1)
) %>%
tab_footnote(
footnote = md("The `title` can get a footnote."),
locations = cells_title(groups = "title")
) %>%
tab_footnote(
footnote = md("The `subtitle` can likewise get a footnote."),
locations = cells_title(groups = "subtitle")
)
```