41 Supplementary Figure 14
41.1 Summary
This is the accessory documentation of Figure S14.
The Figure can be recreated by running the R script plot_SF14.R
:
cd $BASE_DIR
Rscript --vanilla R/fig/plot_SF14.R \
\
2_analysis/raxml/lg04.1_155N.raxml.support \
2_analysis/raxml/lg12.3_155N.raxml.support 2_analysis/raxml/lg12.4_155N.raxml.support
41.2 Details of plot_SF14.R
In the following, the individual steps of the R script are documented. It is an executable R script that depends on the accessory R package GenomicOriginsScripts, as well as on the packages hypoimg, hypogen and patchwork
41.2.1 Config
The scripts start with a header that contains copy & paste templates to execute or debug the script:
#!/usr/bin/env Rscript
# run from terminal:
# Rscript --vanilla R/fig/plot_SF14.R \
# 2_analysis/raxml/lg04.1_155N.raxml.support \
# 2_analysis/raxml/lg12.3_155N.raxml.support \
# 2_analysis/raxml/lg12.4_155N.raxml.support
# ===============================================================
# This script produces Suppl. Figure 14 of the study "Rapid radiation in a
# highly diverse marine environment" by Hench, Helmkampf, McMillan and Puebla
# ---------------------------------------------------------------
# ===============================================================
# args <- c("2_analysis/raxml/lg04.1_155N.raxml.support",
# "2_analysis/raxml/lg12.3_155N.raxml.support",
# "2_analysis/raxml/lg12.4_155N.raxml.support")
# script_name <- "R/fig/plot_SF14.R"
<- commandArgs(trailingOnly = FALSE) args
The next section processes the input from the command line.
It stores the arguments in the vector args
.
The needed R packages are loaded and the script name and the current working directory are stored inside variables (script_name
, plot_comment
).
This information will later be written into the meta data of the figure to help us tracing back the scripts that created the figures in the future.
Then we drop all the imported information besides the arguments following the script name and print the information to the terminal.
# setup -----------------------
::activate()
renvlibrary(GenomicOriginsScripts)
library(hypoimg)
library(hypogen)
library(ape)
library(ggtree)
library(patchwork)
cat('\n')
<- args[5] %>%
script_name str_remove(., '--file=')
<- script_name %>%
plot_comment str_c('mother-script = ', getwd(), '/', .)
<- process_input(script_name, args) args
#> ── Script: R/fig/plot_SF14.R ────────────────────────────────────────────
#> Parameters read:
#> ★ 1: 2_analysis/raxml/lg04.1_155N.raxml.support
#> ★ 2: 2_analysis/raxml/lg12.3_155N.raxml.support
#> ★ 3: 2_analysis/raxml/lg12.4_155N.raxml.support
#> ────────────────────────────────────────── /current/working/directory ──
The directory containing the PCA data is received and stored in a variable. Also the default color scheme is updated and the size of the hamlet ann.
# config -----------------------
<- as.character(args[1])
tree_file_lg04_1 <- as.character(args[2])
tree_file_lg12_3 <- as.character(args[3]) tree_file_lg12_4
<- c(tree_file_lg04_1, tree_file_lg12_3, tree_file_lg12_4) %>%
trees map(.f = function(file){
read.tree(file) %>%
root(phy = ., outgroup = "PL17_160floflo")}
)
<- rgb(.6, .6, .6)
clr_neutral <- 'circular' lyout
<- trees %>%
tree_data map(.f = function(tree_in){
open_tree(ggtree(tree_in, layout = lyout), 180) %>%
$data %>%
.mutate(spec = ifelse(isTip, str_sub(label, -6, -4), "ungrouped"),
support = as.numeric(label),
support_class = cut(support, c(0,50,70,90,100)) %>%
as.character() %>% factor(levels = c("(0,50]", "(50,70]", "(70,90]", "(90,100]"))
)} )
<- plot_outl_tree(tree_data[[1]])
p1 <- plot_outl_tree(tree_data[[2]], show_legend = FALSE)
p2 <- plot_outl_tree(tree_data[[3]], show_legend = FALSE) p3
<- p1 + p2 + p3 + plot_annotation(tag_levels = 'a') + plot_layout(ncol = 1) p_done
Finally, we can export Figure S14.
hypo_save(plot = p_done,
filename = "figures/SF14.pdf",
width = f_width,
height = f_width * 1.5,
device = cairo_pdf,
bg = "transparent",
comment = plot_comment)