
Plot rates vs. trait data over time-steps
Source:R/plot_rates_vs_trait_data_over_time.R
plot_rates_vs_trait_data_over_time.RdPlot rates vs. trait data as extracted for all trait_data_dftime-steps.
Data are extracted from the output of a deepSTRAPP run carried out with
run_deepSTRAPP_over_time()) over multiple time-steps.
For each time-step, returns a plot showing rates vs. trait data. If the trait data are 'continuous', the plot is a scatter plot. If the trait data are 'categorical' or 'biogeographic', the plot is a boxplot.
If a PDF file path is provided in PDF_file_path, all plots will be saved directly in a unique PDF file,
with one page per plot/time-step.
Usage
plot_rates_vs_trait_data_over_time(
deepSTRAPP_outputs,
rate_type = "net_diversification",
select_trait_levels = "all",
color_scale = NULL,
colors_per_levels = NULL,
display_plot = TRUE,
PDF_file_path = NULL,
return_mean_rates_vs_trait_data_df = FALSE
)Arguments
- deepSTRAPP_outputs
List of elements generated with
run_deepSTRAPP_over_time()that runs the whole deepSTRAPP workflow over multiple time-steps.- rate_type
A character string specifying the type of diversification rates to plot. Must be one of 'speciation', 'extinction' or 'net_diversification' (default). Even if the
deepSTRAPP_outputsobject was generated withrun_deepSTRAPP_over_time()for testing another type of rates, the object will contain data for all types of rates.- select_trait_levels
(Vector of) character string. Only for categorical and biogeographic trait data. To provide a list of a subset of states/ranges to plot. Names must match the ones found in the
deepSTRAPP_outputs. Default isallwhich means all states/ranges will be plotted.- color_scale
Vector of character string. List of colors to use to build the color scale with
grDevices::colorRampPalette()to display the points. Color scale from lowest values to highest rate values. Only for continuous data. Default =NULLwill use the 'Spectral' color palette inRColorBrewer::brewer.pal().- colors_per_levels
Named character string. To set the colors to use to plot data points and box for each state/range. Names = states/ranges; values = colors. If
NULL(default), the default ggplot2 color palette (scales::hue_pal()) will be used. Only for categorical and biogeographic data.- 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".
- return_mean_rates_vs_trait_data_df
Logical. Whether to include in the output the data.frame of mean rates per trait values/states/ranges computed for each posterior sample over all time-steps. Default is
FALSE.
Value
The function returns a list with at least one element.
rates_vs_trait_ggplotsA list of objects of classesggandggplotordered as in$time_steps. Each element corresponds to a ggplot for a givenfocal_time. They can be displayed on the console withprint(output$rates_vs_trait_ggplots[[i]]). They correspond to the plots being displayed on the console one by one when the function is run, ifdisplay_plot = TRUE, and can be further modify for aesthetics using the ggplot2 grammar.
If the trait data are 'continuous', the plots are scatter plots showing how diversification rates varies with trait values. If the trait data are 'categorical' or 'biogeographic', the plots are boxplots showing diversification rates per states/ranges.
Each plot also displays summary statistics for the STRAPP test associated with the data displayed:
An observed statistic computed across the mean traits/ranges and rates values shown on the plot. This is not the statistic of the STRAPP test itself, which is conducted across all BAMM posterior samples.
The quantile of null statistic distribution at the significant threshold used to define test significance. The test will be considered significant (i.e., the null hypothesis is rejected) if this value is higher than zero.
The p-value of the associated STRAPP test.
Optional summary data.frame:
mean_rates_vs_trait_data_dfA data.frame with three columns providing the$mean_ratesand$trait_valueobserved along branches at the differentfocal_time. Rates are averaged across all BAMM posterior samples. This is the raw data used to draw each plot for eachfocal_time. Included ifreturn_mean_rates_vs_trait_data_df = TRUE.
If a PDF_file_path is provided, the function will also generate a unique PDF file with one plot/page per $time_steps.
Details
The main input deepSTRAPP_outputs is the typical output of run_deepSTRAPP_over_time().
It provides information on results of a STRAPP test performed over multiple time-steps.
Plots are built based on both trait data and diversification data as extracted for the time-steps.
Such data are recorded in the outputs of a deepSTRAPP run carried out with run_deepSTRAPP_over_time().
return_updated_trait_data_with_Mapmust be set toTRUEso that the trait data used to compute the tests are returned among the outputs under$updated_trait_data_with_Map_over_time. Alternatively, and more efficiently,extract_trait_data_melted_dfcan be set toTRUEso that trait data are already returned in a melted data.frame among the outputs under$trait_data_df_over_time.extract_diversification_data_melted_dfmust be set toTRUEso that the diversification rates are returned among the outputs under$diversification_data_df_over_time.
For plotting a single focal_time, see plot_rates_vs_trait_data_for_focal_time().
See also
Associated functions in deepSTRAPP: run_deepSTRAPP_over_time() plot_rates_vs_trait_data_for_focal_time()