forked from YPARK/gtex-fqtl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfigure.util.R
51 lines (38 loc) · 1.13 KB
/
figure.util.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
48
49
50
51
match.widths <- function(p.list) {
require(grid)
require(gridExtra)
require(gtable)
require(ggplot2)
g.list <- lapply(p.list, ggplotGrob)
max.width <- g.list[[1]]$widths[2:5]
for(j in 2:length(g.list)) {
max.width <- grid::unit.pmax(max.width, g.list[[j]]$widths[2:5])
}
for(j in 1:length(g.list)) {
g.list[[j]]$widths[2:5] <- as.list(max.width)
}
return(g.list)
}
grid.vcat <- function(p.list, ...) {
g.list <- match.widths(p.list)
ret <- grid.arrange(grobs = g.list, ncol = 1, newpage = FALSE, ...)
}
match.heights <- function(p.list) {
require(grid)
require(gridExtra)
require(gtable)
require(ggplot2)
g.list <- lapply(p.list, ggplotGrob)
max.width <- g.list[[1]]$heights[2:5]
for(j in 2:length(g.list)) {
max.width <- grid::unit.pmax(max.width, g.list[[j]]$heights[2:5])
}
for(j in 1:length(g.list)) {
g.list[[j]]$heights[2:5] <- as.list(max.width)
}
return(g.list)
}
grid.hcat <- function(p.list, ...) {
g.list <- match.heights(p.list)
ret <- grid.arrange(grobs = g.list, nrow = 1, newpage = FALSE, ...)
}