-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path05-Variations.Rmd
executable file
·436 lines (378 loc) · 22.9 KB
/
05-Variations.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
```{r setupvar, include=FALSE}
rm(list = ls()) ; invisible(gc()) ; set.seed(43)
library(knitr)
library(tidyverse)
library(dplyr)
theme_set(bayesplot::theme_default())
opts_chunk$set(
echo = F, message = F, warning = F, fig.height = 6, fig.width = 8,
cache = T, cache.lazy = F)
varcols <- c(species = "red", tree = "lightgreen",
sample = "lightblue", measure = "orange")
log_abs_trans <- function() {
scales::trans_new(
name = "log_abs",
transform = function(x) log(abs(x)),
inverse = function(x) exp(x));
}
cv <- function(traits){
if(any(is.na(traits)))
traits=traits[!is.na(traits)]
N=length(traits)
y_bar=mean(traits)
s2_hat=var(traits)
cv_2=s2_hat/y_bar^2
cv_1=sqrt(cv_2)
gamma_1=sum(((traits-y_bar)/s2_hat^0.5)^3)/N
gamma_2=sum(((traits-y_bar)/s2_hat^0.5)^4)/N
bias=cv_2^(3/2)/N*(3*cv_2^0.5-2*gamma_1)
bias2=cv_1^3/N-cv_1/4/N-cv_1^2*gamma_1/2/N-cv_1*gamma_2/8/N
cv1=sd(traits)/mean(traits)
cv4=cv_1-bias2
re=cv4
return(re)
}
```
```{r cvdata}
# cv <- googlesheets4::read_sheet("https://docs.google.com/spreadsheets/d/19eULgGa02RS6hwn2ngeEu4akF2YdaQGHS5xSac2hIYI/edit?usp=sharing",
# "traits") %>%
cv <- readxl::read_excel("data/hydroITV.xlsx", "traits") %>%
filter(StudyLevel == "tree") %>%
mutate(SpeciesLong = paste(Genus, Species)) %>%
mutate_at(c("gmin", "RWC", "FvFm", "LA", "LT", "LDMC", "CC", "Ptlp", "SLA", "LSWC"), abs) %>%
mutate_at(c("gmin", "RWC", "FvFm", "LA", "LT", "LDMC", "CC", "Ptlp", "SLA", "LSWC"), log) %>%
group_by(SpeciesLong) %>%
summarise_at(c("LA", "SLA", "LT", "CC", "LDMC", "LSWC", "Ptlp", "gmin"), funs(cv))
cv <- bind_rows(cv,
ungroup(cv) %>%
summarise_all(mean) %>%
mutate(SpeciesLong = "mean"))
cv_long <- reshape2::melt(cv, "SpeciesLong", variable.name = "trait", value.name = "CV") %>%
mutate(trait = recode(trait, "Ptlp" = "pi[TLP]", "gmin" = "g[min]"))
```
```{r, eval=F}
# on the link between CV and mu
# googlesheets4::read_sheet("https://docs.google.com/spreadsheets/d/19eULgGa02RS6hwn2ngeEu4akF2YdaQGHS5xSac2hIYI/edit#gid=0",
# range = "traits") %>%
readxl::read_excel("data/hydroITV.xlsx", "traits") %>%
filter(StudyLevel == "tree") %>%
mutate(SpeciesLong = paste(Genus, Species)) %>%
mutate_at(c("gmin", "LA", "LT", "LDMC", "CC", "Ptlp", "SLA", "LSWC"), abs) %>%
mutate_at(c("gmin", "LA", "LT", "LDMC", "CC", "Ptlp", "SLA", "LSWC"), log) %>%
dplyr::select(SpeciesLong, gmin, LA, LT, LDMC, CC, Ptlp, SLA, LSWC) %>%
reshape2::melt("SpeciesLong", variable.name = "Trait") %>%
na.omit() %>%
mutate(Trait = recode(Trait, "Ptlp" = "pi[TLP]", "gmin" = "g[min]")) %>%
group_by(Trait, SpeciesLong) %>%
summarise(cv = cv(value), mean = mean(value)) %>%
ggplot(aes(x = mean, y = cv)) +
geom_point() +
facet_wrap(~ Trait, scales = "free", nrow = 2, labeller = label_parsed) +
ylab(expression(CV[4])) + xlab(expression(mu)) +
geom_smooth(method = "lm") +
ggpubr::stat_cor()
```
```{r datavar}
# ft <- googlesheets4::read_sheet("https://docs.google.com/spreadsheets/d/19eULgGa02RS6hwn2ngeEu4akF2YdaQGHS5xSac2hIYI/edit?usp=sharing",
# "traits")
ft <- readxl::read_excel("data/hydroITV.xlsx", "traits")
vars_meas <- filter(ft, StudyLevel == "measure") %>%
dplyr::select(Sample, Measure, LA, SLA, LT, CC, LDMC, FvFm, RWC, LSWC, Ptlp, gmin) %>%
reshape2::melt(c("Sample", "Measure"), variable.name = "trait") %>%
na.omit() %>%
group_by(trait, Sample) %>%
group_by(trait) %>%
do(var = nlme::lme(log(abs(value)) ~ 1, random=~1|Sample, data = .) %>%
ape::varcomp(scale = F, cum = F) %>%
as.vector() %>%
data.frame(level = c("Sample", "Measure"), variance = as.vector(.))) %>%
unnest(var) %>%
select(-`.`) %>%
group_by(trait) %>%
mutate(pct = variance / sum(variance)*100) %>%
mutate(study = "Measure / Sample")
vars_leaf <- filter(ft, StudyLevel == "leaf") %>%
dplyr::select(Tree, Sample, LA, SLA, LT, CC, LDMC, FvFm, RWC, LSWC, Ptlp, gmin) %>%
reshape2::melt(c("Tree", "Sample"), variable.name = "trait") %>%
na.omit() %>%
group_by(trait, Tree) %>%
group_by(trait) %>%
do(var = nlme::lme(log(abs(value)) ~ 1, random=~1|Tree, data = .) %>%
ape::varcomp(scale = F, cum = F) %>%
as.vector() %>%
data.frame(level = c("Tree", "Sample"), variance = as.vector(.))) %>%
unnest(var) %>%
select(-`.`) %>%
group_by(trait) %>%
mutate(pct = variance / sum(variance)*100) %>%
mutate(study = "Sample / Tree")
vars_tree <- filter(ft, StudyLevel == "tree") %>%
dplyr::select(Species, Tree, LA, SLA, LT, CC, LDMC, FvFm, RWC, LSWC, Ptlp, gmin) %>%
reshape2::melt(c("Species", "Tree"), variable.name = "trait") %>%
na.omit() %>%
group_by(trait, Species) %>%
group_by(trait) %>%
do(var = nlme::lme(log(abs(value)) ~ 1, random=~1|Species, data = .) %>%
ape::varcomp(scale = F, cum = F) %>%
as.vector() %>%
data.frame(level = c("Species", "Tree"), variance = as.vector(.))) %>%
unnest(var) %>%
select(-`.`) %>%
group_by(trait) %>%
mutate(pct = variance / sum(variance)*100) %>%
mutate(study = "Tree / Species")
vars <- bind_rows(vars_meas, vars_leaf, vars_tree) %>%
mutate(trait = recode(trait, "Ptlp" = "pi[TLP]", "gmin" = "g[min]", "FvFm" = "frac(Fv,Fm)")) %>%
mutate(level = factor(level, levels = c("Species", "Tree", "Sample", "Measure"))) %>%
mutate(study = factor(study, levels = c("Measure / Sample", "Sample / Tree", "Tree / Species"))) %>%
mutate(pct_text = paste0(round(pct), "%")) %>%
mutate(pct_text = gsub("^0%", "", pct_text))
rm(vars_meas, vars_leaf, vars_tree)
```
# Traits variation
Subsequent analysis aimed to assess variations in leaf traits among species, individuals, leaves and measurements.
## Methods
### Variance partitionning
Variance partitioning was obtained using linear mixed models for every trait and each pairs of levels studied. We aim to understand how much of the leaf trait variation is due to :
- measurement error,
- within-tree leaf variation,
- leaf sample repetitions among trees,
- intra- and inter-specific variation.
*example for intra- and inter-specific variation*: We estimated the among-species variance in our trait of interest from the comparison of the observed variance within and between species. In this case, *Tree* and *Species* are considered random effects but tree is nested in species.
model <- lme(trait~1, random = ~1|Species/Tree, data)
### Coefficient of variation (CV)
Coefficient of variation (CV) is defined as the standard deviation divided by the mean and expressed as a percentage.
It does not require any *ad hoc* assumptions.
It is unitless and therefore convenient to compare variation of traits among species.
According to @Yang2020,
the best ITV estimator is CV1 when N >100.
$$CV1=\frac{sd(traits)}{mean(traits)}$$
For non-normal distribution of raw data or even after a logarithm transformation, CV4, or Bao's estimator, is preferred:
$$CV4=CV1-(\frac{CV1^3}{N}-\frac{CV1}{4N}-\frac{CV1^2\times\gamma_1}{2N}-\frac{CV1\times\gamma_2}{8N})$$
Where gamma is Pearson's measure of skewness and kurtosis of the trait sample distribution.
Log-transformation places less weight on the extreme large values resulting in a more robust estimation of ITV.
It also reduced the skewness of the data, which makes it easier to handle.
We will calculate CV4 using the [`CV` package](from https://www.github.com/guochunshen/CV).
For each trait, we described the magnitude of intraspecific variation by calculating coefficients of variation (CV) across each species.
The log-transformation reduces the proportional bias of ITV [@Yang2020].
CV only makes sense only on positive data, so we take the $abs(P_{TLP})$.
*Beware: CV was sometimes calculated for n<10 samples for some trait per species!*
## Results
```{r tab1, eval=F}
data <- googlesheets4::read_sheet("https://docs.google.com/spreadsheets/d/19eULgGa02RS6hwn2ngeEu4akF2YdaQGHS5xSac2hIYI/edit#gid=0",
range = "traits") %>%
mutate(Species = paste(Genus, Species)) %>%
mutate(Tree = paste(Plot, SubPlot, TreeFieldNum)) %>%
mutate(Sample = paste(Tree, Sample)) %>%
mutate(Measure = paste(Sample, Measure)) %>%
dplyr::select(StudyLevel, Species, Tree, Sample, Measure, LA, SLA, LT, CC, LDMC, LSWC, Ptlp, gmin) %>%
reshape2::melt(c("StudyLevel", "Species", "Tree", "Sample", "Measure"), variable.name = "Trait") %>%
filter(Trait == "LA") %>%
group_by(StudyLevel) %>%
summarise(Species = length(unique(Species)), Tree = length(unique(Tree)),
Sample = length(unique(Sample)), Measure = length(unique(Measure)))
```
```{r figVarPart, fig.width=8, fig.height=8, fig.cap=" Variance partitioning of leaf traits across study levels. Variance partitioning was obtained using linear mixed models for every trait and each pairs of levels studied: measurement error, i.e. measurement repetitions among leave samples, within-tree leaf variation, i.e. leaf sample repetitions among trees, and intra- and inter-specific variation, i.e. individual repetitions among species. Leaf traits include specific leaf area (SLA), leaf dry matter content (LDMC), leaf fresh thickness (LT), leaf area (LA) leaf chlorophyll content (CC), leaf saturated water content (LSWC), leaf water potential at which leaf cells lose turgor ($\\pi_{TLP}$), and leaf minimum conductance ($g_{min}$)."}
g <- vars %>%
filter(!(trait %in% c("frac(Fv,Fm)", "RWC"))) %>%
ggplot(aes(x = study, y = pct, fill = level)) +
geom_bar(stat = "identity", position = "stack") +
geom_text(aes(y = pct, label = pct_text), col = "white", position = position_stack(vjust = .5)) +
scale_fill_manual(expression(sigma^2),
values = unname(varcols[c("species", "tree", "sample", "measure", "residual")])) +
xlab("Trait") + ylab("Percentage of variance") +
scale_x_discrete(labels = scales::parse_format()) +
facet_wrap(.~trait, labeller = "label_parsed", nrow = 2) +
theme(legend.position = "bottom", axis.text.x = element_text(angle = 90), axis.title.x = element_blank())
g
ggsave("~/Téléchargements/Fig4.eps", g, dpi = 600, width = 8, height = 8, device = cairo_ps)
```
```{r cvspfig, fig.cap="Intraspecific coefficient of variation for leaf traits across species. Coefficient of variation used was $CV_4$. Leaf traits include specific leaf area (SLA), leaf dry matter content (LDMC), leaf fresh thickness (LT), leaf area (LA) leaf chlorophyll content (CC), leaf saturated water content (LSWC), leaf water potential at which leaf cells lose turgor ($\\pi_{TLP}$), and leaf minimum conductance ($g_{min}$). Dashed grey line shows the mean across species with the value given in black as a percentage.", fig.height=6, fig.width=8}
g <- cv_long %>%
filter(SpeciesLong != "mean") %>%
ggplot(aes(x = trait, y = CV)) +
geom_boxplot(outlier.shape = NA) +
geom_jitter(aes(col = SpeciesLong)) +
geom_text(aes(label = paste0(round(CV, 2)*100, "%")), y = 0.55, col = "black",
data = filter(cv_long, SpeciesLong == "mean")) +
theme(axis.title.x = element_blank(), axis.text.x = element_text(), legend.text = element_text(face = "italic")) +
ylab(expression(CV[4])) +
scale_color_manual("Species", values = ggpubfigs::friendly_pal(10, name = "bright_seven", type = "continuous")) +
scale_x_discrete(labels = scales::label_parse())
g
# ggsave("~/Téléchargements/Fig3.eps", g, dpi = 600, width = 8, height = 6, device = cairo_ps)
ggsave("~/Téléchargements/Fig3.png", g, dpi = 600, width = 8, height = 6)
```
**Sylvain:**
* Leaf traits show moderate non-negligible CV within species (8-16%) except high for $g_{min}$ and LDMC (resp. 39% and 33%) and low for LT (4%), with strong variation among species for LDMC (from 4% with *P stevensonii* to 76% with *T. melonii*).
* Leaf traits show strong interspecific variation (40-63%), except for SLA and LDMC (resp. 9% and 24%), but also strong intraspecific variation for all traits (30-91%)
* Leaf trait intraspecific variation is mostly due to the individual tree (55-88%) except for a strong variability across samples within tree for LA and CC (resp. 79% and 100%)
* Leaf trait intra-sample variation is almost only due to sample (82-100%) except for a non-negligible measure error within sample for LT and $\pi_{TLP}$ (resp. 9% and 14%)
* Coefficient of variation and variance partitioning thus provide complementary information, with for instance high individual variation with SLA (91%) due to species weak variability (9%) more than intraspecific variability (CV=8%) (=>see SI boxplots)
* Results can drive sampling, e.g. $\pi_{TLP}$ ii a better candidate than $g_{min}$ at the interspecific level with both strong species variability (55%) and a low coefficient of intraspecific variation (16%)
* All together results indicate non-negligible intraspecific trait variation, including hydraulic traits, questioning sampling methodology and determinants of this variation unexplained by measurement error or within individual variation across samples
**Marion:**
* All traits exhibited considerable intraspecific variation, with CVs ranging from approximately 4–39% (Fig. \@ref(fig:cvspfig)). LT, CC and SLA exhibited low variation at 4 %, 5% and 8 % respectively. LA, $P_{tlp}$, LSWC had intermediate variation, from 13-16 %. LDMC and $g_{min}$) varied with the highest CVs ≥ 30 %.
* We have two species with composed leaves: Tachgali melinonii and Jacarando copaia. Throughout all the traits, these two species expressed high (sometimes the highest) CV, meaning the highest dispersion of individuals, highest ITV for these species. We must be careful with this interpretation as we measured the leaflets and not the leaves. But leaflets may be more plastic than leaves.
* we must be aware of estimation biais: CV4 may overestimate ITV when the distribution of raw or log-transformed trait data is close to the normal distribution [@Yang 2020].
## Discussion
CV allows us to compare the distribution of trait values when those are expressed in different units.
The higher the CV is, the higher the dispersion of the individual values around the mean.
CV offers a way to directly compare variation among species with different abundances [@Helsen2017].
Studies have shown a positive relationship between species ITV and niche breadth [@Clark2010]
species with larger ITV tend to have larger geographical ranges than species with smaller ITV [@Brown1984].
## SIs
### CV table
```{r cvsptab}
knitr::kable(cv, caption = "Coefficients of variation ($CV_4$) across each species.", digits = 3)
```
### Individual variation
```{r}
filter(ft, StudyLevel == "tree") %>%
mutate(Ptlp = -Ptlp) %>%
dplyr::select(Genus, Species, Tree, LA, SLA, LT, CC, LDMC, LSWC, Ptlp, gmin) %>%
reshape2::melt(c("Genus", "Species", "Tree"), variable.name = "trait") %>%
na.omit() %>%
filter(value > 0) %>%
group_by(trait) %>%
summarise(V = round(quantile(value, 0.95)/quantile(value, 0.05), 1))
filter(ft, StudyLevel == "leaf") %>%
mutate(Ptlp = -Ptlp) %>%
dplyr::select(Genus, Species, Tree, LA, SLA, LT, CC, LDMC, LSWC, Ptlp, gmin) %>%
reshape2::melt(c("Genus", "Species", "Tree"), variable.name = "trait") %>%
na.omit() %>%
filter(value > 0) %>%
group_by(trait) %>%
summarise(V = round(quantile(value, 0.95)/quantile(value, 0.05), 1))
filter(ft, StudyLevel == "measure") %>%
mutate(Ptlp = -Ptlp) %>%
dplyr::select(Genus, Species, Tree, LA, SLA, LT, CC, LDMC, LSWC, Ptlp, gmin) %>%
reshape2::melt(c("Genus", "Species", "Tree"), variable.name = "trait") %>%
na.omit() %>%
filter(value > 0) %>%
group_by(trait) %>%
summarise(V = round(quantile(value, 0.95)/quantile(value, 0.05), 1))
```
```{r indBoxplots, fig.cap="Traits distributions when testing for individual variation.", fig.width=8}
g <- filter(ft, StudyLevel == "tree") %>%
mutate(Ptlp = -Ptlp) %>%
dplyr::select(Genus, Species, Tree, LA, SLA, LT, CC, LDMC, LSWC, Ptlp, gmin) %>%
reshape2::melt(c("Genus", "Species", "Tree"), variable.name = "trait") %>%
na.omit() %>%
mutate(trait = recode(trait, "LA" = "LA~(cm^2)", "SLA" = "SLA~(cm^2~g^{-1})", "LT" = "LT~(mu~m)",
"CC" = "CC~(g~cm^{-2})", "LDMC" = "LDMC~(g~g^{-1})", "LSWC" = "LSWC~(g~g^{-1})",
"Ptlp" = "-pi[TLP]~(MPa)", "gmin" = "g[min]~(mmol~m^{-2}~s^{-1})")) %>%
mutate(SpeciesLong = paste(Genus, Species)) %>%
ggplot(aes(SpeciesLong, value)) +
geom_boxplot(aes(fill = SpeciesLong), col = "black") +
scale_fill_manual("Species", values = ggpubfigs::friendly_pal(10, name = "bright_seven", type = "continuous")) +
facet_wrap(~ trait, scales = "free_y", labeller = label_parsed, nrow = 2) +
theme(axis.title = element_blank(), axis.text.x = element_blank(), axis.ticks.x = element_blank(),
legend.text = element_text(face = "italic"), legend.position = "bottom") +
guides(fill = guide_legend(nrow = 4)) +
scale_y_log10()
g
# ggsave("~/Téléchargements/Fig2.eps", g, dpi = 600, width = 9, height = 6, device = cairo_ps)
ggsave("~/Téléchargements/Fig2.png", g, dpi = 600, width = 9, height = 6, bg = "white")
```
```{r indBoxplotsDate, fig.cap="Traits distributions when testing for individual variation and sampling date.", fig.height=8, fig.width=8}
filter(ft, StudyLevel == "tree") %>%
unnest(DateField) %>%
mutate(DateField = lubridate::date(DateField)) %>%
dplyr::select(DateField, Genus, Species, Tree, LA, SLA, LT, CC, LDMC, RWC, LSWC, Ptlp, gmin) %>%
reshape2::melt(c("DateField", "Genus", "Species", "Tree"), variable.name = "trait") %>%
na.omit() %>%
mutate(trait = recode(trait, "Ptlp" = "-pi[TLP]", "FvFm" = "frac(Fv,Fm)", "gmin" = "g[min]")) %>%
mutate(SpeciesLong = paste(Genus, Species)) %>%
ggplot(aes(as.character(DateField), value, group = DateField)) +
geom_boxplot(alpha = 0.5, col = "lightgrey") +
geom_point(alpha = 0.5) +
viridis::scale_color_viridis("Leaf") +
scale_fill_discrete("Species") +
facet_wrap(~ trait, scales = "free_y", labeller = label_parsed) +
xlab("") +
scale_y_continuous(trans = "log_abs") +
theme(axis.text.x = element_text(angle = 90))
```
```{r indDBH, fig.cap="Traits distributions when testing for individual variation and diameter.", fig.height=8, fig.width=4}
filter(ft, StudyLevel == "tree") %>%
mutate(Ptlp = -Ptlp, SLA = 1/SLA, LSWC = 1/LSWC, LA = 1/LA) %>%
dplyr::select(Genus, Species, Tree, LA, SLA, LT, CC, LDMC, LSWC, Ptlp, gmin, DBH) %>%
reshape2::melt(c("Genus", "Species", "Tree", "DBH"), variable.name = "trait") %>%
na.omit() %>%
mutate(trait = recode(trait, "LA" = "frac(1,LA)~(cm^-2)", "SLA" = "frac(1,SLA)~(cm^-2~g^{1})", "LT" = "LT~(mu~m)",
"CC" = "CC~(g~cm^{-2})", "LDMC" = "LDMC~(g~g^{-1})", "LSWC" = "frac(1,LSWC)~(g~g^{-1})",
"Ptlp" = "-pi[TLP]~(MPa)", "gmin" = "g[min]~(mmol~m^{-2}~s^{-1})")) %>%
mutate(SpeciesLong = paste(Genus, Species)) %>%
ggplot(aes(DBH, value)) +
geom_point(alpha = 0.5) +
viridis::scale_color_viridis("Leaf") +
scale_fill_discrete("Species") +
facet_wrap(~ trait, scales = "free_y", labeller = label_parsed, ncol = 2) +
xlab("Diameter at breast height (cm)") + ylab("") +
geom_smooth(method = "lm", formula = y~log(x)) +
scale_y_log10()
```
```{r indTWIsp, fig.cap="Traits distributions when testing for species and individual variation with topography.", fig.width=8}
g <- filter(ft, StudyLevel == "tree") %>%
mutate(Ptlp = -Ptlp, SLA = 1/SLA, LSWC = 1/LSWC, LA = 1/LA) %>%
dplyr::select(Genus, Species, Tree, LA, SLA, LT, CC, LDMC, LSWC, Ptlp, gmin, TWI) %>%
reshape2::melt(c("Genus", "Species", "Tree", "TWI"), variable.name = "trait") %>%
na.omit() %>%
mutate(trait = recode(trait, "LA" = "frac(1,LA)~(cm^-2)", "SLA" = "frac(1,SLA)~(cm^-2~g^{1})", "LT" = "LT~(mu~m)",
"CC" = "CC~(g~cm^{-2})", "LDMC" = "LDMC~(g~g^{-1})", "LSWC" = "frac(1,LSWC)~(g~g^{-1})",
"Ptlp" = "-pi[TLP]~(MPa)", "gmin" = "g[min]~(mmol~m^{-2}~s^{-1})")) %>%
mutate(SpeciesLong = paste(Genus, Species)) %>%
ggplot(aes(TWI, value)) +
geom_point(aes(col = paste(Genus, Species)), alpha = 0.5) +
facet_wrap(~ trait, scales = "free_y", labeller = label_parsed, nrow = 2) +
xlab("Topographic wetness index") +
geom_smooth(method = "lm", col = "black") +
geom_smooth(method = "lm", aes(col = paste(Genus, Species)), se = F) +
scale_color_manual("Species", values = ggpubfigs::friendly_pal(10, name = "bright_seven", type = "continuous")) +
facet_wrap(~ trait, scales = "free_y", labeller = label_parsed, nrow = 2) +
theme(legend.text = element_text(face = "italic"), legend.position = "bottom") +
guides(color = guide_legend(nrow = 4)) +
scale_y_log10() + scale_x_log10()
g
# ggsave("~/Téléchargements/Fig5.eps", g, dpi = 600, width = 9, height = 6, device = cairo_ps)
ggsave("~/Téléchargements/Fig5.png", g, dpi = 600, width = 9, height = 6)
```
### Leaf variation
```{r leafBoxplots, fig.cap="Traits distributions when testing for leaf variation.", fig.width=8}
filter(ft, StudyLevel == "leaf") %>%
mutate(Ptlp = -Ptlp) %>%
dplyr::select( Tree, Sample, LA, SLA, LT, CC, LDMC, RWC, Ptlp, gmin) %>%
reshape2::melt(c("Tree", "Sample"), variable.name = "trait") %>%
na.omit() %>%
mutate(trait = recode(trait, "LA" = "LA~(cm^2)", "SLA" = "SLA~(cm^2~g^{-1})", "LT" = "LT~(mu~m)",
"CC" = "CC~(g~cm^{-2})", "LDMC" = "LDMC~(g~g^{-1})", "LSWC" = "LSWC~(g~g^{-1})",
"Ptlp" = "-pi[TLP]~(MPa)", "gmin" = "g[min]~(mmol~m^{-2}~s^{-1})")) %>%
ggplot(aes(as.factor(Tree), value, fill = as.factor(Tree))) +
geom_boxplot(col = "black") +
facet_wrap(~ trait, scales = "free_y", labeller = label_parsed, nrow = 2) +
theme(axis.title = element_blank(), axis.text.x = element_text(angle = 90),
legend.position = "bottom", legend.box="vertical", legend.margin=margin()) +
scale_y_log10() +
scale_fill_manual("Tree", values = ggpubfigs::friendly_pal(4, name = "bright_seven", type = "continuous"))
```
### Measurement error
```{r measureBoxplots, fig.cap="Traits distributions when testing for measurement error.", fig.width=8}
filter(ft, StudyLevel == "measure") %>%
mutate(Ptlp = -Ptlp) %>%
dplyr::select(Sample, Measure, LA, SLA, LT, CC, LDMC, LSWC, Ptlp, gmin) %>%
reshape2::melt(c("Sample", "Measure"), variable.name = "trait") %>%
na.omit() %>%
group_by(Sample, Measure, trait) %>%
summarise(value = mean(value, na.rm = T)) %>%
mutate(trait = recode(trait, "LA" = "LA~(cm^2)", "SLA" = "SLA~(cm^2~g^{-1})", "LT" = "LT~(mu~m)",
"CC" = "CC~(g~cm^{-2})", "LDMC" = "LDMC~(g~g^{-1})", "LSWC" = "LSWC~(g~g^{-1})",
"Ptlp" = "-pi[TLP]~(MPa)", "gmin" = "g[min]~(mmol~m^{-2}~s^{-1})")) %>%
ggplot(aes(as.factor(Sample), value, col = as.factor(Sample))) +
geom_boxplot() +
facet_wrap(~ trait, scales = "free", labeller = label_parsed, nrow = 2) +
xlab("Sample") +
theme(axis.title = element_blank(), legend.position = "bottom") +
scale_y_log10() +
scale_color_manual("Sample", values = ggpubfigs::friendly_pal(5, name = "bright_seven", type = "continuous"))
```