forked from JKRWard/SNES-git-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlotting_our_evolution.Rmd
70 lines (48 loc) · 2.2 KB
/
Plotting_our_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
---
output:
html_document:
theme: cerulean
---
# **The evolutionary lottery**
<br>
This workshop has been adapted from materials developed by [RSE Sheffield](https://github.com/RSE-Sheffield/collaborative_github_exercise)
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}
library(dplyr)
library(tidyr)
library(ggplot2)
library(plotly)
library(webshot)
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(paste("params", spp, sep= "/"))
# 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)
```