knitr::opts_chunk$set( collapse = TRUE, comment = "#>", echo = T, message = T, warning = F, cache = T )
Install TreeData
devtools::install_github("VincyaneBadouard/TreeData", build_vignettes = TRUE)
Load the packages
library(TreeData) library(knitr) library(kableExtra) library(shiny) library(shinydashboard) library(shinyjs) library(shinyWidgets) library(data.table) library(ggplot2)
# TreeData::RunApp() # doest' work, why? shiny::runGitHub( "VincyaneBadouard/TreeData", subdir = "inst/app") # data.tree, stringdist
Load the example dataset stored in the package
data("TestData")
Bota
- Family_TreeDataCor (character): corrected Family name
- FamilyCorSource (character): source of the Family correction
- Genus_TreeDataCor (character): corrected Genus name
- Species_TreeDataCor (character): corrected Species name
- BotanicalCorrectionSource (character): source of the Genus and Species
correction
- ScientificName_TreeDataCor (character): corrected ScientificName
- VernName_TreeDataCor (character): completed if information available at IdTree
level.
Life Status
- LifeStatus_TreeDataCor (logical): corrected stem life status.
Taper
- TaperDBH_TreeDataCor (numeric): corrected trees diameter at default HOM
Diameter
- Diameter_TreeDataCor (numeric): corrected trees diameter at default HOM
- DiameterCorrectionMeth (character): diameter correction methode = "taper"/"local linear regression"/"weighted mean"
/phylogenetic hierarchical("species"/"genus"/"family"/"stand")/"shift realignment"/"Same value".
- POM_TreeDataCor (factor): POM value at which the corrected diameters are proposed. Corresponds to the 1st POM value at which the stem was measured
- HOM_TreeDataCor (numeric): HOM value at which the corrected diameters are proposed. Corresponds to the DefaultHOM if Taper correction applied. If not, corresponds to the 1st HOM value at which the stem was measured
Recruitment
- CorrectedRecruit (logical): TRUE: the row was added to represent the year when the stem was larger than the minimum diameter, but absent from the dataset. FALSE: original dataset row.
GeneralErrorsDetection()
BotanicalCorrection()
StatusCorrection()
TaperCorrection()
DiameterCorrection()
RecruitmentCorrection()
StatusCorrectionPlot()
DiameterCorrectionPlot()
BotanicalCorrectionPlot()
Detect errors - Remove duplicated rows - Check missing value in X-YTreeUTM/PlotArea/Plot/Subplot/Year/TreeFieldNum/ IdTree/IdStem/Diameter/POM/HOM/Family/Genus/Species/VernName - Check missing value (NA/0) in the measurement variables: "Diameter", "HOM", "TreeHeight", "StemHeight" - Check of the unique association of the IdTree with plot, subplot and TreeFieldNum (at the site scale) - Check duplicated IdTree/IdStem in a census (at the site scale) - Check for trees outside the subplot (not implemented yet) - Check invariant coordinates per IdTree/IdStem - Check fix Plot and Subplot number (not implemented yet)
Rslt <- GeneralErrorsDetection(TestData) # The detected errors unique(Rslt[Comment != "", Comment]) Rslt[Comment != "", ]
Rslt <- BotanicalCorrection(TestData, Source = "TPL", WFOData = NULL)
if UseSize argument chosen : if Diameter != NA -> Alive If (the value in bold is modified by the value given after the arrow): (the ">" gives the chronological order of the sequence)
Dead > Alive -> NA
Status_corr <- StatusCorrection(TestData, InvariantColumns = c("Site", "Genus", "Species", "Family", "ScientificName"), DeathConfirmation = 2, UseSize = FALSE, AddRowsForForgottenCensuses = TRUE, DetectOnly = FALSE, RemoveRBeforeAlive = TRUE, RemoveRAfterDeath = TRUE) Status_corr[LifeStatus!=LifeStatus_TreeDataCor] Status_corr[IdStem == "101362_1_auto", .(IdStem, LifeStatus, LifeStatus_TreeDataCor, Diameter, Year, Comment)] # Les années (Year) sont rangées par ordre croissant avant correction donc les NA se retrouvent à la fin. Le NA est entre deux vivants (TRUE) donc corrigé TRUE. La dernière ligne n'apparait pas sur le graphique car Year = NA donc pas plotable. # pdf("LifeStatusCorrectionPlots.pdf", width = 25, height = 10) LifeStatusCorrectionPlot(Status_corr, OnlyCorrected = T, SeveralWindows = F) # dev.off()
Transform the tree diameter measured at a given height into the diameter corresponding to the default measurement height (HOM), using an allometry.
Data <- data.table(IdStem = "A", ScientificName = "Tree", Year = c(1998, 2008, 2016, 2017, 2018, 2019, 2021), IdCensus = factor(c(1998, 2008, 2016, 2017, 2018, 2019, 2021), ordered = TRUE), Diameter = c(19, 19, 21.4, 22.6, 23.1, 23.1, 23.6), HOM = c(1.30, 3.25, 3.25, 3.25, 3.25, 3.25, 3.25)) Rslt <- TaperCorrection(Data, DefaultHOM = 1.3, TaperParameter = function(DAB, HOM) 0.156 - 0.023 * log(DAB) - 0.021 * log(HOM), TaperFormula = function(DAB, HOM, TaperParameter, DefaultHOM) DAB / (exp(- TaperParameter*(HOM - DefaultHOM)))) DiameterCorrectionPlot(Rslt, CorCol = "TaperDBH_TreeDataCor")
Rslt <- TaperCorrection(Status_corr, DefaultHOM = 1.3, TaperParameter = function(DAB, HOM) 0.156 - 0.023 * log(DAB) - 0.021 * log(HOM), TaperFormula = function(DAB, HOM, TaperParameter, DefaultHOM) DAB / (exp(- TaperParameter*(HOM - DefaultHOM)))) DiameterCorrectionPlot(Rslt, CorCol = "TaperDBH_TreeDataCor", OnlyCorrected = TRUE, SeveralWindows = T)
Diam_corr <- DiameterCorrection( Status_corr, KeepMeas = c("MaxHOM", "MaxDate"), DefaultHOM = 1.3, MaxDBH = 500, PositiveGrowthThreshold = 5, NegativeGrowthThreshold = -2, Pioneers = NULL, PioneersGrowthThreshold = 7.5, WhatToCorrect = c("POM change", "punctual", "shift"), CorrectionType = "individual", Digits = 1L, DBHCorForDeadTrees = FALSE, coef = 0.9, DetectOnly = FALSE)
# pdf("DiameterCorrectionPlots_TestData2.pdf", width = 25, height = 10) DiameterCorrectionPlot(Diam_corr, OnlyCorrected = TRUE, SeveralWindows = F) # dev.off()
Rslt <- RecruitmentCorrection(Diam_corr, KeepMeas = c("MaxHOM", "MaxDate"), MinDBH = 10, PositiveGrowthThreshold = 5, InvariantColumns = c("Site", "Genus_TreeDataCor", "Species_TreeDataCor", "Family_TreeDataCor", "ScientificName_TreeDataCor"), DetectOnly = FALSE) IdCorr <- Rslt[CorrectedRecruit %in% TRUE, IdStem] TreesCorr <- Rslt[IdStem %in% IdCorr, .(IdStem, Year, Diameter, Diameter_TreeDataCor, CorrectedRecruit)] ggplot(TreesCorr) + aes(x = Year, y = Diameter_TreeDataCor) + geom_line(linewidth = 0.5, colour = "#112446") + geom_point(shape = "circle", size = 1.5, mapping = aes(color = CorrectedRecruit)) + theme_minimal() + facet_wrap(vars(IdStem), scales = "free")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.