-
Notifications
You must be signed in to change notification settings - Fork 391
/
plot_trait_evolution.Rmd
executable file
·117 lines (74 loc) · 3.49 KB
/
plot_trait_evolution.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
output:
html_document:
theme: cerulean
---
# **Evolutionary lottery of skull and beak morphology**
<br>
> [**Beak and skull shapes in birds of prey (“raptors”) are strongly coupled and largely controlled by size.**](http://eprints.whiterose.ac.uk/99452/1/Bright%20et%20al.%202016_SelfArchive.pdf)
gif provided by the awesome **Jen Bright** [**\@MorphobeakGeek**](https://twitter.com/MorphobeakGeek)!
![](gif.gif)
In this exercise we will **use a github repo** to collaboratively collate and *simulate evolutionary trajectories for each participants' species* ***body size*** using a simple brownian motion evolutionary model. This assumes evolutionary steps to progress comletely at random. You could say:
#### it's a bit of lottery!
<br>
Each participant has **created and contributed a file** specifying the parameters required to simulate and plot their species evolutionary trajectory. We've collect all participants' files in the master repo. Next we need to simulate species trajectories plot them up.
Participants will then get to **see the skull and beak shape** corresponding to their species relative body size!
***
### setup
First we load the required packages and create some objects to compile data on trait evolution for each species.
```{r warning=F, message=FALSE}
require(dplyr)
require(ggplot2)
require(plotly)
set.seed(1)
t <- 0:100 # generate time vector
dt <- NULL # generate object to compile time-series data
cols <- NULL # generate object to compile trendline colours
```
***
### Simulate trait evolution, iterate over all species files in `params/` folder
We'll use the parameters supplied in your scripts to generate brownian trait evolution trendline for each species.
```{r}
spp.files <- dir("params/")[dir("params/") != "params_tmpl.R"]
for(spp in spp.files){
# source parameters for each species
source(file.path("params", spp))
# generate trait evolution time-series and compile plotting data
dt <- rbind(dt, data.frame(t,
trait = c(0, rnorm(n = length(t) - 1, sd = sqrt(sig2)) %>% cumsum()),
species = species.name))
cols <- c(cols, color)
}
```
### Plot trait evolution timeseries
Use the data generated to plot all species.
```{r fig.width = 9}
p <- ggplot(data = dt, aes(x = t, y = trait, group = species, colour = species)) +
geom_line() +
scale_colour_manual(values = cols)
ggplotly(p)
```
<br>
***
## **Skulls!** find the skull associated with your species:
<br>
Skulls are organised from **largest** to **smallest**. The largest skulls are **vulture-like**, (e.g. **no. 50, the Andean condor** [*Vultur gryphus*](https://en.wikipedia.org/wiki/Andean_condor)) and the smallest are **falconet-like**, (e.g. **no. 1 Collared falconet** [*Microhierax caerulescens*](https://en.wikipedia.org/wiki/Collared_falconet))
```{r, echo=FALSE, results='asis'}
skull <- dt[dt$t == 100,]
skull <- skull[order(skull$trait, decreasing = T),]
gf <- list.files("gif/")
if(length(gf) > 0){
max.x <- max(abs(dt$trait))
breaks <- seq(-max.x, max.x, length.out = 50)
bins <- cut(skull$trait, breaks = breaks, include.lowest = T, labels = F)
for(i in 1:nrow(skull)){
cat("### **No: ",bins[i], "** ***", as.character(skull$species[i]),"***", "\n", "\n", sep = "")
cat("![](gif/", gf[bins[i]], ")", "\n", "\n", sep = "")
}
}
```
### Session Info
```{r}
sessioninfo::session_info()
```
This projects uses [`renv`](https://rstudio.github.io/renv/articles/renv.html) for dependency management.