DDvTDtools::assert_DDvTD_wd() library(DDvTDtools); library(tidyverse); library(cowplot) ggs <- purrr::map( DDvTDtools::arg_para(), function(para) { print(para) ltt <- DDvTDtools::plot_avg_ltt(para) + ggplot2::theme( title = ggplot2::element_blank(), axis.title.x = ggplot2::element_blank(), axis.title.y = ggplot2::element_blank() ) + ggplot2::coord_cartesian( ylim = c(2, 200) ) n_plot <- DDvTDtools::plot_n_distrib(para) + ggplot2::theme( plot.title = ggplot2::element_text(size = 6) ) gg <- cowplot::plot_grid( ltt, n_plot, nrow = 1, ncol = 2, rel_widths = c(0.7, 0.3), align = "h" ) return(gg) } ) plot_area <- ggs %>% cowplot::plot_grid( plotlist = ., labels = LETTERS[1:20], label_x = 0.1, nrow = 5, ncol = 4 ) xlabs <- lapply( X = c(0, 0.1, 0.2, 0.4), FUN = function(x) { cowplot::ggdraw() + cowplot::draw_label( label = bquote(mu[0] ~ "=" ~ .(x)), fontface = "bold", hjust = 0.5, size = 20, angle = 0 ) } ) xlabs <- xlabs %>% cowplot::plot_grid( plotlist = ., nrow = 1, ncol = 4 ) ylabs <- purrr::map2( .x = c(rep(40, 4), 80), .y = c(5, 10, 15, 60, 15), .f = function(x, y) { cowplot::ggdraw() + cowplot::draw_label( label = paste0("K = ", x, "\n", y, " myr"), angle = 90, hjust = 0.25, vjust = 0.8, size = 15 ) }) ylabs <- cowplot::plot_grid( ylabs[[1]], ylabs[[2]], ylabs[[3]], ylabs[[4]], ylabs[[5]], nrow = 5, ncol = 1 ) y_axis_title <- cowplot::ggdraw() + cowplot::draw_label( label = "Number of lineages", angle = 90, hjust = 0.5, vjust = 0.7, # fontface = "bold", size = 20 ) # x_axis_title <- cowplot::ggdraw() + cowplot::draw_label( # label = "Time (in myr)", # # fontface = "bold", # size = 20 # ) x_axis_title <- purrr::map( 1:4, function(x) { cowplot::plot_grid( cowplot::ggdraw() + cowplot::draw_label( label = "Time (in myr)", size = 20), NULL, nrow = 1, ncol = 2, rel_widths = c(0.7, 0.3) ) } ) %>% cowplot::plot_grid( plotlist = ., nrow = 1, ncol = 4 ) full_plot <- cowplot::plot_grid( NULL, NULL, xlabs, ylabs, y_axis_title, plot_area, NULL, NULL, x_axis_title, nrow = 3, ncol = 3, rel_widths = c(0.05, 0.025, 0.925), rel_heights = c(0.05, 0.9, 0.05) ) ggplot2::ggsave( "figures/fig_2.png", plot = full_plot, width = 540, height = 285, units = "mm", dpi = 600)