-
Notifications
You must be signed in to change notification settings - Fork 1
/
table.R
47 lines (40 loc) · 914 Bytes
/
table.R
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
#*************************************
## Displaying tables as grid graphics*
#*************************************
library(grid)
library(gridExtra)
library(gtable)
# Default table
grid.table(my_table)
# Custom table - Add borders
g <- tableGrob(my_table, rows = NULL)
g <-
gtable_add_grob(g,
grobs = rectGrob(gp = gpar(fill = NA, lwd = 2)),
t = 2, b = nrow(g), l = 1, r = ncol(g)
)
g <-
gtable_add_grob(g,
grobs = rectGrob(gp = gpar(fill = NA, lwd = 2)),
t = 1, l = 1, r = ncol(g)
)
grid.draw(g)
# Custom table - Dashed line as separators and minimal theme
g <- tableGrob(my_table,
rows = NULL,
theme = ttheme_minimal()
)
separators <-
replicate(ncol(g) - 2,
segmentsGrob(
x1 = unit(0, "npc"),
gp = gpar(lty = 2)
),
simplify = FALSE
)
g <- gtable_add_grob(g,
grobs = separators,
t = 2, b = nrow(g),
l = seq_len(ncol(g) - 2) + 2
)
grid.draw(g)