
Plot multiple mapped phylogenies of trait/range evolution vs. diversification rates and regime shifts over time-steps
Source:R/plot_traits_vs_rates_on_phylogeny_over_time.R
plot_traits_vs_rates_on_phylogeny_over_time.RdPlot two mapped phylogenies with evolutionary data with branches cut off for each time-step.
Main input = output of a deepSTRAPP run over time using run_deepSTRAPP_over_time()).
Left facet: plot the evolution of trait data/geographic ranges on the left time-calibrated phylogeny.
For continuous data: Each branch is colored according to the estimates value of the traits.
For categorical and biogeographic data: Each branch is colored according to the posterior probability of being in a given state/range. Color for each state/range are overlaid using transparency to produce a single plot for all states/ranges.
Right facet: plot the evolution of diversification rates and location of regime shits estimated from a BAMM (Bayesian Analysis of Macroevolutionary Mixtures). Each branch is colored according to the estimated rates of speciation, extinction, or net diversification stored in an object of class
bammdata. Rates can vary along time, thus colors evolved along individual branches.
This function is a wrapper of run_deepSTRAPP_for_focal_time() used to plot mapped phylogenies for
a unique given focal_time.
Returns one plot per focal time in $time_steps.
If a PDF file path is provided in PDF_file_path, the plots will be saved directly in a PDF file,
with one page per focal time in $time_steps.
Usage
plot_traits_vs_rates_on_phylogeny_over_time(
deepSTRAPP_outputs,
color_scale = NULL,
colors_per_levels = NULL,
add_ACE_pies = TRUE,
cex_pies = 0.5,
rate_type = "net_diversification",
keep_initial_colorbreaks = FALSE,
add_regime_shifts = TRUE,
configuration_type = "MAP",
sample_index = 1,
adjust_size_to_prob = TRUE,
regimes_fill = "grey",
regimes_size = 1,
regimes_pch = 21,
regimes_border_col = "black",
regimes_border_width = 1,
...,
display_plot = TRUE,
PDF_file_path = NULL
)Arguments
- deepSTRAPP_outputs
List of elements generated with
run_deepSTRAPP_over_time(), that summarize the results of a STRAPP run over multiple time-steps in the past.- color_scale
Vector of character string. List of colors to use to build the color scale with
grDevices::colorRampPalette()showing the evolution of a continuous trait. From lowest values to highest values. (For continuous trait data only)- colors_per_levels
Named character string. To set the colors to use to map each state/range posterior probabilities. Names = states/ranges; values = colors. If
NULL(default), the color scale provideddensityMapswill be used. (For categorical and biogeographic data only)- add_ACE_pies
Logical. Whether to add pies of posterior probabilities of states/ranges at internal nodes on the mapped phylogeny. Default =
TRUE.- cex_pies
Numerical. To adjust the size of the ACE pies. Default =
0.5.- rate_type
A character string specifying the type of diversification rates to plot. Must be one of 'speciation', 'extinction' or 'net_diversification' (default).
- keep_initial_colorbreaks
Logical. Whether to keep the same color breaks as used for the most recent focal time. Typically, the current time (t = 0). Default =
FALSE.- add_regime_shifts
Logical. Whether to add the location of regime shifts on the phylogeny (Step 2). Default is
TRUE.- configuration_type
A character string specifying how to select the location of regime shifts across posterior samples.
configuration_type = "MAP": Use the average locations recorded in posterior samples with the Maximum A Posteriori probability (MAP) configuration. This regime shift configuration is the most frequent configuration among the posterior samples (SeeBAMMtools::getBestShiftConfiguration()). This is the default option.configuration_type = "MSC": Use the average locations recorded in posterior samples with the Maximum Shift Credibility (MSC) configuration. This regime shift configuration has the highest product of marginal probabilities across branches (SeeBAMMtools::maximumShiftCredibility()).configuration_type = "index": Use the configuration of a unique posterior sample those index is provided insample_index.
- sample_index
Integer. Index of the posterior samples to use to plot the location of regime shifts. Used only if
configuration_type = index. Default =1.- adjust_size_to_prob
Logical. Whether to scale the size of the symbols showing the location of regime shifts according to the marginal shift probability of the shift happening on each location/branch. This will only works if there is an
$MSP_treeelement summarizing the marginal shift probabilities across branches in theBAMM_object. Default isTRUE.- regimes_fill
Character string. Set the color of the background of the symbols showing the location of regime shifts. Equivalent to the
bgargument inBAMMtools::addBAMMshifts(). Default is"grey".- regimes_size
Numerical. Set the size of the symbols showing the location of regime shifts. Equivalent to the
cexargument inBAMMtools::addBAMMshifts(). Default is1.- regimes_pch
Integer. Set the shape of the symbols showing the location of regime shifts. Equivalent to the
pchargument inBAMMtools::addBAMMshifts(). Default is21.- regimes_border_col
Character string. Set the color of the border of the symbols showing the location of regime shifts. Equivalent to the
colargument inBAMMtools::addBAMMshifts(). Default is"black".- regimes_border_width
Numerical. Set the width of the border of the symbols showing the location of regime shifts. Equivalent to the
lwdargument inBAMMtools::addBAMMshifts(). Default is1.- ...
Additional graphical arguments to pass down to
phytools::plot.contMap(),phytools::plot.simmap(),plot_densityMaps_overlay(),BAMMtools::plot.bammdata(),BAMMtools::addBAMMshifts(), andpar().- display_plot
Logical. Whether to display the plot generated in the R console. Default is
TRUE.- PDF_file_path
Character string. If provided, the plot will be saved in a PDF file following the path provided here. The path must end with ".pdf".
Value
If display_plot = TRUE, the function displays the successive plots with two facets in the R console:
(Left) A time-calibrated phylogeny displaying the evolution of trait/biogeographic data.
(Right) A time-calibrated phylogeny displaying diversification rates and regime shifts. A plot per time-steps is generated and displayed successively in the console.
If PDF_file_path is provided, the plots will be exported in a unique PDF file with one page per time-step.
Details
The main input deepSTRAPP_outputs is the typical output of run_deepSTRAPP_over_time().
It provides information on results of a STRAPP run performed over multiple time-steps, and can also encompass
updated phylogenies with mapped trait evolution and diversification rates and regimes shifts if appropriate arguments are set.
return_updated_trait_data_with_Mapmust be set toTRUEso that the trait data extracted for the given$time_stepsand the list of updated versions of mapped phylogenies (contMap/densityMaps) is returned among the outputs under$updated_trait_data_with_Map_over_time. The updatedcontMap/densityMapsconsist in cutting off branches and mappings that are younger than the successive$time_steps.return_updated_BAMM_objectmust be set toTRUEso that the list ofupdated_BAMM_objectwith phylogenies and mapped diversification rates cut-off at the successive$time_stepsare returned among the outputs under$updated_BAMM_objects_over_time.
$MAP_BAMM_object and $MSC_BAMM_object elements are required in the elements of $updated_BAMM_objects_over_time to plot regime shift locations
following the "MAP" or "MSC" configuration_type respectively.
A $MSP_tree element is required to scale the size of the symbols showing the location of regime shifts according marginal shift probabilities.
(If adjust_size_to_prob = TRUE).
Alternatively, the main input deepSTRAPP_outputs can be the output of run_deepSTRAPP_over_time(),
providing results of STRAPP tests over multiple time-steps. In this case, you must provide a focal_time to select the
unique time-step used for plotting.
return_updated_trait_data_with_Mapmust be set toTRUEso that the trait data extracted and the updated version of mapped phylogenies (contMap/densityMaps) are returned among the outputs under$updated_trait_data_with_Map_over_time.return_updated_BAMM_objectmust be set toTRUEso that theBAMM_objectswith phylogeny and mapped diversification rates cut-off at the specified time-steps are returned among the outputs under$updated_BAMM_objects_over_time.
For plotting a single time-step (i.e., $focal_time) at once, see plot_traits_vs_rates_on_phylogeny_for_focal_time().
See also
plot_contMap() phytools::plot.densityMap() plot_densityMaps_overlay() plot_BAMM_rates()
Function in deepSTRAPP needed to produce the deepSTRAPP_outputs as input: run_deepSTRAPP_over_time()
Function in deepSTRAPP to a single time-step at once: plot_traits_vs_rates_on_phylogeny_for_focal_time()