-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path12_fig_S3_plot.R
More file actions
53 lines (44 loc) · 1.2 KB
/
12_fig_S3_plot.R
File metadata and controls
53 lines (44 loc) · 1.2 KB
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
library(ggplot2)
library(gridExtra)
figures_dir <- "./export/figures"
objects_dir <- "./export/objects"
dir.create(figures_dir, showWarnings = FALSE, recursive = TRUE)
dir.create(objects_dir, showWarnings = FALSE, recursive = TRUE)
plots_3a <- readRDS("./export/objects/fig_S3A_panels.rds")
plots_3b <- readRDS("./export/objects/fig_S3B_panels.rds")
plots <- c(plots_3a, plots_3b)
plots <- plots[-c(5, 6, 7, 11)]
add_enum <- function(p, label) {
p +
labs(tag = paste0(label)) +
theme(
plot.title = element_text(hjust = 0.5, vjust = 1),
plot.title.position = "plot",
plot.tag = element_text(hjust = 0, vjust = 1, face = "bold", size = 24),
plot.tag.position = c(0, 1),
plot.margin = margin(6, 6, 6, 6)
)
}
add_enum_list <- function(plots) {
Map(function(p, i) add_enum(p, LETTERS[i]), plots, seq_along(plots))
}
plots <- add_enum_list(plots)
layout_matrix <- rbind(
c(1, 2, 3, 4),
c(5, 6, 7, 8),
c(9, 10, 11, 12),
c(13, 13, 14, 14)
)
final_plot <- grid.arrange(
grobs = plots,
layout_matrix = layout_matrix
)
ggplot2::ggsave(
filename = "./export/figures/fig_S3.png",
plot = final_plot,
width = 20,
height = 25,
units = "in",
dpi = 600,
bg = "white"
)