Draws borders between every column and every row of a gt table, giving it a
full grid, with an option to extend the borders around the column and row
labels.
Usage
gt_border_grid(gt_object, color = "black", weight = 1, include_labels = FALSE)
Arguments
- gt_object
A gt table object to modify.
- color
Character. The border color. Defaults to "black".
- weight
Numeric. The border thickness in pixels. Defaults to 1.
- include_labels
Logical. Should the borders extend around the row and
column labels? Defaults to FALSE.
Value
Returns a modified gt table with the grid borders applied.
Details
Column borders are drawn with gtExtras::gt_add_divider() on every column but
the last, and the row borders are added as scoped CSS on the .gt_row top
border. A table id is resolved or generated first, since that CSS is keyed on
#<table_id>.
Examples
library(gt)
gt(head(mtcars)) %>% gt_border_grid()
| mpg |
cyl |
disp |
hp |
drat |
wt |
qsec |
vs |
am |
gear |
carb |
|---|
| 21.0 |
6 |
160 |
110 |
3.90 |
2.620 |
16.46 |
0 |
1 |
4 |
4 |
| 21.0 |
6 |
160 |
110 |
3.90 |
2.875 |
17.02 |
0 |
1 |
4 |
4 |
| 22.8 |
4 |
108 |
93 |
3.85 |
2.320 |
18.61 |
1 |
1 |
4 |
1 |
| 21.4 |
6 |
258 |
110 |
3.08 |
3.215 |
19.44 |
1 |
0 |
3 |
1 |
| 18.7 |
8 |
360 |
175 |
3.15 |
3.440 |
17.02 |
0 |
0 |
3 |
2 |
| 18.1 |
6 |
225 |
105 |
2.76 |
3.460 |
20.22 |
1 |
0 |
3 |
1 |
# heavier gray lines, including around the labels
gt(head(iris)) %>%
gt_border_grid(color = "#BBBBBB", weight = 2, include_labels = TRUE)
| Sepal.Length |
Sepal.Width |
Petal.Length |
Petal.Width |
Species |
|---|
| 5.1 |
3.5 |
1.4 |
0.2 |
setosa |
| 4.9 |
3.0 |
1.4 |
0.2 |
setosa |
| 4.7 |
3.2 |
1.3 |
0.2 |
setosa |
| 4.6 |
3.1 |
1.5 |
0.2 |
setosa |
| 5.0 |
3.6 |
1.4 |
0.2 |
setosa |
| 5.4 |
3.9 |
1.7 |
0.4 |
setosa |