-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasic_deterministic_trees.Rmd
186 lines (158 loc) · 10.2 KB
/
basic_deterministic_trees.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
---
title: Deterministic Trees
output: github_document
---
```{r, message = F, warning = F}
devtools::load_all()
```
The function <b>deterministic_tree()</b> allows the user to make trees from deterministic inputs. The input arguments are given below, as well a limited exploration of what most the arguments do.
### Input arguments
<b>splits</b> : (int) Indicates number of levels beyond starting branch. <br>
<b>length</b> : (dbl) Indicates length of a branch. <br>
<b>scale_length</b> : (lgl) Indicates if lengths should be scaled at each new level. <br>
<b>length_scale</b> : (dbl) Indicates rate in which branch lengths shorten at each level. Vector or single value. <br>
<b>trunk_scale</b> : (dbl) Used to vary the relative size of the "trunk"
<b>children</b> : (int) Indicates number of new branches at each new level. <br>
<b>start_angle</b> : (dbl) Indicates angle in radians of starting branch, measured ccw from +y direction. <br>
<b>angle</b> : (dbl) Indicates angle in radian between each branch at a split. <br>
<b>scale_angle</b> : (lgl) Indicates if branch split angles should be scaled at each new level. <br>
<b>angle_scale</b> : (lgl) Indicates rate at which angles should decrease <br>
<b>thickness</b> : (dbl) Indicates thickness of a branch. <br>
<b>scale_thickness</b> : (lgl) Indicates if thickness should should shrink at each new level <br>
<b>thickness_scale</b> : (dbl) Indicates rate in which branch thicknesses should shrink <br>
<b>taper</b> : (lgl) Indicates if branches should taper. <br>
<br>
<b>man_lengths</b> : Manually select branch length for starting branch and branches at each level. <br>
<b>man_angles</b> : Manually select angles between branches at each split by level. <br>
<b>man_split_thickness</b> : Manually select thickness of each branch at each split in order. <br>
<b>man_begin_thick</b> : Manually select starting thickness. <br>
<b>man_end_thick</b> : Manually select ending thickness. <br>
<b>man_children</b> : Manually select number of branches at split by level. <br>
<b>sib_lgth_ratio</b> : Only works if equal number of children at each split. Indicates relative length of children. <br>
<b>sib_thk_ratio</b> : Only works if equal number of children at each split. Indicates relative thickness of children. <br>
<br>
<b>title</b> : (chr) Optional title for output tree. <br>
<b>plot</b> : (lgl) Default to T for plotting <br>
<b>datadump</b> : (lgl) Default to F. Set to T get relevant data.
### Testing "splits" input with others set to default
```{r, fig.align='center'}
par(mfrow=c(2,3), mar=c(1,1,1,1))
deterministic_tree(splits = 1, title = "splits = 1")
deterministic_tree(splits = 2, title = "splits = 2")
deterministic_tree(title = "default splits = 3")
deterministic_tree(splits = 4, title = "splits = 4")
deterministic_tree(splits = 5, title = "splits = 5")
deterministic_tree(splits = 6, title = "splits = 6")
# Check for improper "splits" input
rbind(deterministic_tree(splits = 0.3),
deterministic_tree(splits = -2),
deterministic_tree(splits = "test"))
```
### Test "children" and "man_children" with others set to default
```{r, fig.align='center'}
par(mfrow=c(2,2), mar=c(1,1,1,1))
deterministic_tree(children = 1, title = "children = 1")
deterministic_tree(title = "default children = 2")
deterministic_tree(children = 3, title = "children = 3")
deterministic_tree(children = 4, title = "children = 4")
```
```{r, fig.align='center'}
par(mfrow=c(2,2), mar=c(1,1,1,1))
deterministic_tree(man_children = c(3,2,3), title = "man_children = c(3,2,3)")
deterministic_tree(man_children = c(3,2,2,4,4), title = "man_children = c(3,2,2,4,4)")
# Having "man_children" length =/= "splits" changes "splits" to length.
deterministic_tree(man_children = c(4,4), title = "man_children = c(4,4)")
deterministic_tree(man_children = c(3,3,3,3,3), title = "man_children = c(3,3,3,3,3)")
```
### The role of tapering and scaling at each split for "splits = 5"
```{r, fig.align='center'}
par(mfrow=c(2,3), mar=c(1,1,1,1))
deterministic_tree(splits = 5, title = "all = T")
deterministic_tree(splits = 5, taper = F, title = "scale_thickness = T, taper = F")
deterministic_tree(splits = 5, scale_thickness = F, taper = F, title = "scale_thickness = F, taper = F")
deterministic_tree(splits = 5, scale_length = F, title = "scale_length = F")
deterministic_tree(splits = 5, scale_angle = F, title = "scale_angle = F")
# Check for improper inputs
rbind(deterministic_tree(taper = 2),
deterministic_tree(scale_length = "test"),
deterministic_tree(scale_angle = 1.5))
```
### Exploring "angle_scale" with "splits = 5"
```{r, fig.align='center'}
par(mfrow=c(2,2), mar=c(1,1,1,1))
deterministic_tree(splits = 5, title = "default angle_scale = 1.127838")
deterministic_tree(splits = 5, angle_scale = 1.5, title = "scale_angle = 1.5")
deterministic_tree(splits = 5, angle_scale = 2, title = "scale_angle = 2")
deterministic_tree(splits = 5, angle_scale = 0.75, title = "scale_angle = 0.75")
```
### Exploring "length_scale" with "splits = 5"
```{r, fig.align='center'}
par(mfrow=c(2,3), mar=c(1,1,1,1))
deterministic_tree(splits = 5, length_scale = 1.2, title = "length_scale = 1.2")
deterministic_tree(splits = 5, title = "default length_scale = 1.4")
deterministic_tree(splits = 5, length_scale = 2, title = "length_scale = 2")
deterministic_tree(splits = 5, length_scale = 0.75, title = "length_scale = 0.75")
deterministic_tree(splits = 5, length_scale = c(2,2,1.5,1,1), title = "length_scale = c(2,2,1.5,1,1)")
deterministic_tree(splits = 5, length_scale = c(1,1,1.5,2,2), title = "length_scale = c(1,1,1.5,2,2)")
```
### Exploring "thickness_scale" with "splits = 5". Starting thickness = 2 unless stated otherwise.
```{r, fig.align='center'}
par(mfrow=c(2,2), mar=c(1,1,1,1))
deterministic_tree(splits = 5, thickness_scale = 1.2, title = "thickness_scale = 1.2")
deterministic_tree(splits = 5, title = "default thickness_scale = 1.61803")
deterministic_tree(splits = 5, thickness_scale = 2, title = "thickness_scale = 10")
# Values less than 1 increase thickness
deterministic_tree(splits = 5, thickness_scale = 0.8, thickness = 0.5, title = "thickness = 0.5, thickness_scale = 0.8")
```
### Exploring "sib_lgth_ratio" -> "children" determined by length of vector "sib_lgth_ratio"
```{r, fig.align='center'}
par(mfrow=c(2,2), mar=c(1,1,1,1))
deterministic_tree(sib_lgth_ratio = c(1,2), title = "sib_lgth_ratio = c(1,2)")
deterministic_tree(sib_lgth_ratio = c(1,2,1), title = "children = 3, sib_lgth_ratio = c(1,2,1)")
# As written if branch given a length of zero, that doesn't mean it won't still have its own children
deterministic_tree(sib_lgth_ratio = c(1,0,1), title = "children = 3, sib_lgth_ratio = c(1,0,1)")
deterministic_tree(sib_lgth_ratio = c(1,2,2,1), title = "children = 4, sib_lgth_ratio = c(1,2,2,1)")
```
```{r, fig.align='center'}
par(mfrow=c(2,3), mar=c(1,1,1,1))
deterministic_tree(splits = 8, sib_lgth_ratio = c(1,2), title = "splits = 8, sib_lgth_ratio = c(1,2)")
deterministic_tree(splits = 6, sib_lgth_ratio = c(1,2,1), title = "splits = 6, sib_lgth_ratio = c(1,2,1)")
deterministic_tree(splits = 5, sib_lgth_ratio = c(1,2,2,1), title = "splits = 5, sib_lgth_ratio = c(1,2,2,1)")
deterministic_tree(splits = 5, sib_lgth_ratio = c(2,1,1,2), title = "splits = 5, sib_lgth_ratio = c(1,2,2,1)")
deterministic_tree(splits = 6, sib_lgth_ratio = c(1,2,3), title = "splits = 6, sib_lgth_ratio = c(1,2,3)")
deterministic_tree(splits = 6, sib_lgth_ratio = c(2,1,2), title = "splits = 6, sib_lgth_ratio = c(1,2,3)")
```
### Similarly, "sib_thk_ratio" effects the thickness.
```{r, fig.align='center'}
par(mfrow=c(2,2), mar=c(1,1,1,1))
deterministic_tree(sib_thk_ratio = c(1,2), title = "sib_thk_ratio = c(1,2)")
deterministic_tree(sib_thk_ratio = c(1,2,1), title = "children = 3, sib_thk_ratio = c(1,2,1)")
deterministic_tree(sib_thk_ratio = c(1,2,3), title = "children = 3, sib_thk_ratio = c(1,2,3)")
deterministic_tree(sib_thk_ratio = c(1,2,2,1), title = "children = 4, sib_thk_ratio = c(1,2,2,1)")
```
```{r, fig.align='center'}
par(mfrow=c(2,3), mar=c(1,1,1,1))
deterministic_tree(splits = 8, sib_thk_ratio = c(1,2), title = "splits = 8, sib_thk_ratio = c(1,2)")
deterministic_tree(splits = 6, sib_thk_ratio = c(1,2,1), title = "splits = 6, sib_thk_ratio = c(1,2,1)")
deterministic_tree(splits = 5, sib_thk_ratio = c(1,1.5,1.5,1), title = "splits = 5, sib_thk_ratio = c(1,1.5,1.5,1)")
deterministic_tree(splits = 5, sib_thk_ratio = c(1.5,1,1,1.5), title = "splits = 5, sib_thk_ratio = c(1.5,1,1,1.5)")
deterministic_tree(splits = 6, sib_thk_ratio = c(1,1.5,2), title = "splits = 6, sib_thk_ratio = c(1,1.5,2)")
deterministic_tree(splits = 6, sib_thk_ratio = c(1.5,1,1.5), title = "splits = 6, sib_thk_ratio = c(1.5,1,1.5)")
```
### Both
```{r, fig.align='center'}
par(mfrow=c(2,3), mar=c(1,1,1,1))
deterministic_tree(splits = 8, sib_lgth_ratio = c(1,2), sib_thk_ratio = c(2,1), title = "see code")
deterministic_tree(splits = 7, sib_lgth_ratio = c(1,3,1), sib_thk_ratio = c(1,2,1), title = "see code")
deterministic_tree(splits = 6, sib_lgth_ratio = c(1,2,2,1), sib_thk_ratio = c(1.5,1,1,1.5), title = "see code")
deterministic_tree(splits = 5, sib_lgth_ratio = c(2,1,1,2), sib_thk_ratio = c(1,1.5,1.5,1), title = "see code")
deterministic_tree(splits = 6, sib_lgth_ratio = c(1,2,3), sib_thk_ratio = c(2,1.5,1), title = "see code")
deterministic_tree(splits = 6, sib_lgth_ratio = c(2,1,2), sib_thk_ratio = c(1,2,1), title = "see code")
```
### Explore "trunk_scale". It simply shrinks the starter branch. Other arguments: "splits = 6, angle_scale = 1.25, sib_lgth_ratio = c(1,5,1), sib_thk_ratio = c(1,2,1)"
```{r, fig.align='center'}
par(mfrow=c(1,3), mar=c(1,1,1,1))
deterministic_tree(splits = 7, angle_scale = 1.25, sib_thk_ratio = c(1,2,1), sib_lgth_ratio = c(1,5,1), title = "default: trunk_scale = 1")
deterministic_tree(splits = 7, trunk_scale = 0.75, angle_scale = 1.25, sib_thk_ratio = c(1,2,1), sib_lgth_ratio = c(1,5,1), title = "trunk_scale = 0.75")
deterministic_tree(splits = 7, trunk_scale = 0.25, angle_scale = 1.25, sib_thk_ratio = c(1,2,1), sib_lgth_ratio = c(1,5,1), title = "trunk_scale = 0.25")
```