38 Supplementary Figure 11
38.1 Summary
This is the accessory documentation of Figure S11.
The Figure can be recreated by running the R script plot_SF11.R
:
cd $BASE_DIR
Rscript --vanilla R/fig/plot_SF11.R \
2_analysis/newhyb/nh_input/NH.Results/
38.2 Details of plot_SF11.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
38.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_SF11.R \
# 2_analysis/newhyb/nh_input/NH.Results/
# ===============================================================
# This script produces Suppl. Figure 11 of the study "Rapid radiation in a
# highly diverse marine environment" by Hench, Helmkampf, McMillan and Puebla
# ---------------------------------------------------------------
# ===============================================================
# args <- c("2_analysis/newhyb/nh_input/NH.Results/")
# script_name <- "R/fig/plot_SF11.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(prismatic)
library(paletteer)
library(patchwork)
library(ggtext)
library(hypoimg)
library(hypogen)
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_SF11.R ────────────────────────────────────────────
#> Parameters read:
#> ★ 1: 2_analysis/newhyb/nh_input/NH.Results/
#> ────────────────────────────────────────── /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]) base_dir
# locate hybridization data files
<- dir(base_dir) folders
# load data and create plots by location
<- c("bel", "hon", "pan") %>%
p_loc map(plot_loc)
# compose figure from the individual panels
<- (p_loc[[1]] + guides(fill = guide_legend(title = "Hybrid Class")) + theme_hyb(legend.position = c(1,1)) ) +
p_done 2]] + theme_hyb() ) +
(p_loc[[3]] + theme_hyb() ) +
(p_loc[[plot_layout(ncol = 1, heights = c(10,15,3) %>% label_spacer())+
plot_annotation(tag_levels = 'a')
Finally, we can export Figure S11.
# export the final figure
hypo_save(filename = "figures/SF11.pdf",
plot = p_done,
height = 16,
width = 10,
device = cairo_pdf,
comment = plot_comment)