Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ plot_ancestral_states <- function(
#' network is represented, otherwise a weighted network is assumed.
#' @param tree The phylogeny of the symbiont clade (e.g. parasites, herbivores). Object of class `phylo`.
#' @param host_tree The phylogeny belonging to the hosts. Object of class `phylo`.
#' @param widths Used in a call to `patchwork::wrap_plots()`. The relative widths of each column
#' in the plot grid.
#' @param heights Used in a call to `patchwork::wrap_plots()`. The relative heights of each row
#' in the plot grid.
#'
#' See the examples on how to change the color scale.
#'
Expand Down Expand Up @@ -473,7 +477,8 @@ plot_ancestral_states <- function(
plot_matrix_phylo <- function(
net, at_nodes, tree, host_tree, type = "states", state = 2, repertoire = "fundamental",
modules = NULL, module_order = NULL, find_modules = TRUE,
threshold = 0.9, point_size = 3, dodge_width = 0.025, colors = NULL, ladderize = FALSE
threshold = 0.9, point_size = 3, dodge_width = 0.025, colors = NULL, ladderize = FALSE,
widths = c(1,1), heights = c(3,1)
) {
# Check inputs
if (!is.matrix(net)) stop("`net` should be a matrix.")
Expand Down Expand Up @@ -533,7 +538,7 @@ plot_matrix_phylo <- function(
module_plot + ggplot2::labs(tag = "B"),
patchwork::guide_area(),
host_plot + ggplot2::labs(tag = "C"),
ncol = 2, widths = c(1, 1), heights = c(3, 1), guides = "collect"
ncol = 2, widths = widths, heights = heights, guides = "collect"
)
}

Expand Down
16 changes: 12 additions & 4 deletions man/plot_matrix_phylo.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions vignettes/articles/evolnets.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
warning = FALSE,
message = FALSE,
eval = FALSE
message = FALSE
)
```

```{r, echo=FALSE}
options(rmarkdown.html_vignette.check_title = FALSE)
```


`evolnets` is an R package for summarizing the posterior distribution produced by Bayesian inference of ancestral networks. Currently, the only available approach specific for inference of ecological interactions is based on the model of host-repertoire evolution implemented originally in [RevBayes](https://revbayes.github.io/tutorials/host_rep/host_rep.html) and then in [TreePPL](https://treeppl.org). If you are unfamiliar with this model, check out this [paper in Systematic Biology](https://doi.org/10.1093/sysbio/syaa019) where the model is introduced. <!-- There are, however, other approaches that can produce posterior distributions of ancestral interactions, such as DEC models of geographic range evolution. evolnets also supports outputs from such analyses produced by RevBayes and BioGeoBEARS. -->

Even though the approach used here can be applied to a variety of biological systems, it was developed with host-symbiont interactions in mind, so I'll be using the words *host* and *symbiont*. They could, in principle, be replaced by terms like *host* and *parasite*, *resource* and *consumer*, *lower trophic level* and *higher trophic level*, or any other two groups of nodes that form a bipartite network.
Expand Down Expand Up @@ -136,7 +138,9 @@ pp_at_deep_nodes[, c("Fabaceae", "Capparaceae", "Rosaceae"), ]

We can see that Fabaceae was most likely an ancestral hosts for Pieridae butterflies. Capparaceae might have been a host at the origin of Pieridae, but most certainly starting at node "Index_128". On the other hand, the probability that these butterflies used Rosaceae as a host is very small.

Instead of just looking at numbers, we can plot the ancestral hosts for all internal nodes in the symbiont tree. For that, we have to choose a probability threshold over which to plot (default is 0.9). Ancestral states are colored by modules in the extant network, so we have to either define the modules first or let it be done within the plotting function. Let's plot both trees, the interaction matrix, and the ancestral states at once, like so:
Instead of just looking at numbers, we can plot the ancestral hosts for all internal nodes in the symbiont tree. For that, we have to choose a probability threshold over which to plot (default is 0.9). Ancestral states are colored by modules in the extant network, so we have to either define the modules first or let it be done within the plotting function. As this is a stochastic process, the modules will change a little every time the `plot_matrix_phylo()` is called.

Let's plot both trees, the interaction matrix, and the ancestral states at once, like so:

```{r}
at_nodes <- posterior_at_nodes(history, tree, host_tree)
Expand All @@ -162,14 +166,14 @@ The main goal of `evolnets` is to reconstruct the evolution of networks. We can

`posterior_at_ages( )` finds the symbiont lineages that were extant at given time points in the past and calculates the posterior probability for interactions between these symbionts and each host based on samples from the MCMC. The first element of `at_ages` contains the sampled networks and the second, the posterior probabilities.

```{r}
```{r, eval = FALSE}
ages <- c(60, 50, 40, 0)
at_ages <- posterior_at_ages(history, ages, tree, host_tree)
```

Then, we can make different interaction matrices based on two things: the minimum posterior probability for an interaction to be included in the network, and whether we want a binary or a weighted network.

```{r}
```{r, eval = FALSE}
weighted_nets_50 <- get_summary_networks(at_ages, threshold = 0.5, weighted = TRUE)
binary_nets_90 <- get_summary_networks(at_ages, threshold = 0.9, weighted = FALSE)

Expand All @@ -183,13 +187,13 @@ binary_nets_90 <- get_summary_networks(at_ages, threshold = 0.9, weighted = FALS

### Sampled networks

```{r}
```{r, eval = FALSE}
samples_at_ages <- get_sampled_networks(at_ages)
```

Then, we can calculate network properties for each sampled network.

```{r}
```{r, eval = FALSE}
# calculate posterior distribution of nestedness
Nz <- index_at_ages_samples(samples_at_ages, index = "NODF", nnull = 10)

Expand Down
Loading