Skip to content
Snippets Groups Projects
Commit 0cb5c0d4 authored by Francesco Sabatini's avatar Francesco Sabatini
Browse files

Updated selection, based on sPlot3.0_v1.1

parent 875508d4
No related branches found
No related tags found
No related merge requests found
......@@ -63,7 +63,7 @@ Extract all plots containing at least one species in the xylem list.
```{r, message=F, results=F, warning=F}
species_list <- xylem_data$Species
plot.sel <- DT2 %>%
filter(DT2$species %in% species_list) %>%
filter(DT2$Species %in% species_list) %>%
dplyr::select(PlotObservationID) %>%
distinct() %>%
pull(PlotObservationID)
......@@ -76,19 +76,19 @@ header.xylem <- header %>%
plot.sel <- header.xylem$PlotObservationID
DT.xylem <- DT2 %>%
filter(taxon_group %in% c("Vascular plant", "Unknown")) %>%
filter(Taxon_group %in% c("Vascular plant", "Unknown")) %>%
filter(PlotObservationID %in% plot.sel)
```
Out of the `r length(species_list)` species in the sRoot list, `r sum(unique(DT2$species) %in% species_list)` species are present in sPlot, for a total of `r nrow(DT.xylem %>% filter(species %in% species_list))` records, across `r length(plot.sel)` plots.
Out of the `r length(species_list)` species in the sRoot list, `r sum(unique(DT2$Species) %in% species_list)` species are present in sPlot, for a total of `r nrow(DT.xylem %>% filter(Species %in% species_list))` records, across `r length(plot.sel)` plots.
# 2 Extract woody species
This is partial selection, as we don't have information on the growth form of all species in sPlot
```{r}
#Select all woody species and extract relevant traits from TRY
woody_species_traits <- sPlot.traits %>%
dplyr::select(species, GrowthForm, is.tree.or.tall.shrub, n,
dplyr::select(Species, GrowthForm, is.tree.or.tall.shrub, n,
starts_with("StemDens"),
starts_with("Stem.cond.dens"),
starts_with("StemConduitDiameter"),
......@@ -97,7 +97,7 @@ woody_species_traits <- sPlot.traits %>%
starts_with("PlantHeight"),
starts_with("Wood"),
starts_with("SpecificRootLength_mean")) %>%
filter( (species %in% species_list) |
filter( (Species %in% species_list) |
grepl(pattern = "tree|shrub", x = GrowthForm) |
is.tree.or.tall.shrub==T
) %>%
......@@ -133,7 +133,7 @@ Codes correspond to those reported in [TRY](https://www.try-db.org/TryWeb/Home.p
```{r}
#subset DT.xylem to only retain woody species
DT.xylem <- DT.xylem %>%
filter(species %in% (woody_species_traits$species))
filter(Species %in% (woody_species_traits$Species))
nrow(DT.xylem)
```
......@@ -149,23 +149,23 @@ combine.cover <- function(x){
}
DT.xylem <- DT.xylem %>%
dplyr::select(PlotObservationID, species,Layer, Relative.cover) %>%
dplyr::select(PlotObservationID, Species,Layer, Relative_cover) %>%
# normalize relative cover to 1 for each plot x layer combination
left_join({.} %>%
group_by(PlotObservationID, Layer) %>%
summarize(Tot.Cover=sum(Relative.cover), .groups="drop"),
summarize(Tot.Cover=sum(Relative_cover), .groups="drop"),
by=c("PlotObservationID", "Layer")) %>%
mutate(Relative.cover=Relative.cover/Tot.Cover) %>%
group_by(PlotObservationID, species) %>%
mutate(Relative_cover=Relative_cover/Tot.Cover) %>%
group_by(PlotObservationID, Species) %>%
# merge layers together
summarize(Relative.cover=combine.cover(Relative.cover), .groups="drop") %>%
summarize(Relative_cover=combine.cover(Relative_cover), .groups="drop") %>%
ungroup() %>%
# normalize relative cover to 1 after merging layers together
left_join({.} %>%
group_by(PlotObservationID) %>%
summarize(Tot.Cover=sum(Relative.cover), .groups="drop"),
summarize(Tot.Cover=sum(Relative_cover), .groups="drop"),
by="PlotObservationID") %>%
mutate(Relative.cover=Relative.cover/Tot.Cover)
mutate(Relative_cover=Relative_cover/Tot.Cover)
nrow(DT.xylem)
```
......@@ -174,7 +174,7 @@ double check that covers are properly standardized
DT.xylem %>%
filter(PlotObservationID %in% sample(header.xylem$PlotObservationID, 10, replace=F)) %>%
group_by(PlotObservationID) %>%
summarize(tot.cover=sum(Relative.cover), .groups="drop")
summarize(tot.cover=sum(Relative_cover), .groups="drop")
```
......@@ -185,24 +185,23 @@ Calculate CWM and trait coverage for each trait and each plot. Select plots havi
# Merge species data table with traits
CWM.xylem0 <- DT.xylem %>%
as_tibble() %>%
dplyr::select(PlotObservationID, species, Relative.cover) %>%
dplyr::select(PlotObservationID, Species, Relative_cover) %>%
left_join(xylem_data %>%
dplyr::rename(species=Species) %>%
dplyr::select(species, P50, Ks),
by="species")
dplyr::select(Species, P50, Ks),
by="Species")
# Calculate CWM for each trait in each plot
CWM.xylem1 <- CWM.xylem0 %>%
group_by(PlotObservationID) %>%
summarize_at(.vars= vars(P50:Ks),
.funs = list(~weighted.mean(., Relative.cover, na.rm=T)),
.funs = list(~weighted.mean(., Relative_cover, na.rm=T)),
.groups="drop") %>%
dplyr::select(PlotObservationID, order(colnames(.))) %>%
pivot_longer(-PlotObservationID, names_to="trait", values_to="trait.value")
# Calculate coverage for each trait in each plot
CWM.xylem2 <- CWM.xylem0 %>%
mutate_at(.funs = list(~if_else(is.na(.),0,1) * Relative.cover),
mutate_at(.funs = list(~if_else(is.na(.),0,1) * Relative_cover),
.vars = vars(P50:Ks)) %>%
group_by(PlotObservationID) %>%
summarize_at(.vars= vars(P50:Ks),
......@@ -232,7 +231,7 @@ variance2.fun <- function(trait, abu){
CWM.xylem3 <- CWM.xylem0 %>%
group_by(PlotObservationID) %>%
summarize_at(.vars= vars(P50:Ks),
.funs = list(~variance2.fun(., Relative.cover))) %>%
.funs = list(~variance2.fun(., Relative_cover))) %>%
dplyr::select(PlotObservationID, order(colnames(.))) %>%
pivot_longer(-PlotObservationID, names_to="trait", values_to="trait.variance")
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment