SummaryTables_Height: SummaryTables_Height

Description Usage Arguments Author(s) Examples

View source: R/SummaryTables_Height.R

Description

Produces a DT::datatable of height summaries grouped by individual species, growth habit, or sagebrush species. Summarized across each individual plot or across the entire ecological site(s). Outputs are html objects that can be directly downloaded to Excel.

Usage

1
SummaryTables_Height(Species_plots_ecosite, SummaryVar, SummarizeBy, GroupBy)

Arguments

Species_plots_ecosite

Combined AIM and LMF species indicator, subset to your ecological site(s). Returned output from Combine_AIM_LMF_Species and SubsetEcologicalSite_Species.

SummaryVar

"Height"

SummarizeBy

c("Plot", "EcologicalSite")

GroupBy

c("Species", "GrowthHabit", "Sagebrush")

Author(s)

Rachel Burke, ecologist/analyst @ Jornada

Examples

  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
# To summarize heights by growth habit for each individual plot:

SummaryTables_Height(Species_plots_ecosite, SummaryVar = "Height",
                     SummarizeBy = "Plot", GroupBy = "GrowthHabit")

# To summarize heights by growth habit across the ecological site(s):

SummaryTables_Height(Species_plots_ecosite, SummaryVar = "Height",
                     SummarizeBy = "EcologicalSite", GroupBy = "GrowthHabit")


## The function is currently defined as
function (Species_plots_ecosite, SummaryVar, SummarizeBy, GroupBy)
{
    SpeciesList <- SpeciesList %>% dplyr::select(Species, ScientificName,
        CommonName, Family, SpeciesState, SynonymOf, UpdatedSpeciesCode,
        SpeciesState) %>% dplyr::mutate(link = paste("https://plants.sc.egov.usda.gov/core/profile?symbol=",
        Species, sep = ""))
    Species_plots_ecosite <- merge(Species_plots_ecosite, SpeciesList,
        by = c("Species", "SpeciesState")) %>% dplyr::select(Species,
        ScientificName, CommonName, Family, PrimaryKey, PlotID,
        AH_SpeciesCover, AH_SpeciesCover_n, Hgt_Species_Avg,
        Hgt_Species_Avg_n, GrowthHabit, GrowthHabitSub, Duration,
        Noxious, SG_Group, link, SpeciesState, SynonymOf, UpdatedSpeciesCode) %>%
        dplyr::mutate_if(is.numeric, round, digits = 2)
    Species_plots_ecosite$Noxious <- gsub("YES", "Yes", Species_plots_ecosite$Noxious)
    Species_plots_ecosite$Noxious <- gsub("NO", "No", Species_plots_ecosite$Noxious)
    HgtPrep <- Species_plots_ecosite %>% filter(!is.na(Hgt_Species_Avg)) %>%
        filter(!is.na(GrowthHabitSub))
    if (SummaryVar == "Height" & SummarizeBy == "Plot" & GroupBy ==
        "GrowthHabit") {
        table <- HgtPrep %>% group_by(GrowthHabitSub, Duration,
            PrimaryKey, PlotID) %>% summarize(AverageHeight_cm = mean(Hgt_Species_Avg),
            Standard_Deviation_cm = sd(Hgt_Species_Avg), MinHeight_cm = min(Hgt_Species_Avg),
            MaxHeight_cm = max(Hgt_Species_Avg), n = sum(Hgt_Species_Avg_n)) %>%
            mutate_if(is.numeric, round, digits = 2) %>% DT::datatable(extensions = "Buttons",
            filter = "top", options = list(scrollX = TRUE, dom = "Bfrtip",
                buttons = list(list(extend = "collection", buttons = c("csv",
                  "excel"), text = "Download Table"))), caption = paste("Heights by functional group in: ",
                toString(EcologicalSiteId)), rownames = FALSE)
    }
    if (SummaryVar == "Height" & SummarizeBy == "EcologicalSite" &
        GroupBy == "GrowthHabit") {
        table <- HgtPrep %>% group_by(GrowthHabitSub, Duration) %>%
            summarize(AverageHeight_cm = mean(Hgt_Species_Avg),
                Standard_Deviation_cm = sd(Hgt_Species_Avg),
                MinHeight_cm = min(Hgt_Species_Avg), MaxHeight_cm = max(Hgt_Species_Avg),
                n = sum(Hgt_Species_Avg_n)) %>% mutate_if(is.numeric,
            round, digits = 2) %>% DT::datatable(extensions = "Buttons",
            filter = "top", options = list(scrollX = TRUE, dom = "Bfrtip",
                buttons = list(list(extend = "collection", buttons = c("csv",
                  "excel"), text = "Download Table"))), caption = paste("Heights by functional group in: ",
                toString(EcologicalSiteId)), rownames = FALSE)
    }
    if (SummaryVar == "Height" & SummarizeBy == "Plot" & GroupBy ==
        "Species") {
        table <- HgtPrep %>% dplyr::select(-link) %>% group_by(PlotID,
            PrimaryKey, Species, ScientificName, CommonName,
            GrowthHabitSub, Duration) %>% dplyr::select(GrowthHabitSub,
            Duration, PlotID, PrimaryKey, Hgt_Species_Avg, Hgt_Species_Avg_n) %>%
            DT::datatable(extensions = "Buttons", filter = "top",
                options = list(scrollX = TRUE, dom = "Bfrtip",
                  buttons = list(list(extend = "collection",
                    buttons = c("csv", "excel"), text = "Download Table"))),
                caption = (paste("Species heights in: ", toString(EcologicalSiteId))),
                rownames = FALSE)
    }
    if (SummaryVar == "Height" & SummarizeBy == "EcologicalSite" &
        GroupBy == "Species") {
        table <- HgtPrep %>% group_by(Species, ScientificName,
            CommonName, GrowthHabitSub, Duration) %>% summarize(AverageHeight_cm = mean(Hgt_Species_Avg),
            Standard_Deviation_cm = sd(Hgt_Species_Avg), MinHeight_cm = min(Hgt_Species_Avg),
            MaxHeight_cm = max(Hgt_Species_Avg), n = sum(Hgt_Species_Avg_n)) %>%
            mutate_if(is.numeric, round, digits = 2) %>% DT::datatable(extensions = "Buttons",
            filter = "top", options = list(scrollX = TRUE, dom = "Bfrtip",
                buttons = list(list(extend = "collection", buttons = c("csv",
                  "excel"), text = "Download Table"))), caption = (paste("Heights by species in ",
                toString(EcologicalSiteId))), rownames = FALSE)
    }
    if (SummaryVar == "Height" & SummarizeBy == "Plot" & GroupBy ==
        "Sagebrush") {
        table <- HgtPrep %>% filter(!is.na(SG_Group)) %>% subset(SG_Group ==
            "Sagebrush") %>% group_by(PlotID, PrimaryKey, Species,
            ScientificName, CommonName, SG_Group) %>% dplyr::select(Species,
            PlotID, PrimaryKey, Hgt_Species_Avg, Hgt_Species_Avg_n) %>%
            mutate_if(is.numeric, round, digits = 2) %>% DT::datatable(extensions = "Buttons",
            filter = "top", options = list(scrollX = TRUE, dom = "Bfrtip",
                buttons = list(list(extend = "collection", buttons = c("csv",
                  "excel"), text = "Download Table"))), caption = (paste("Heights by sagebrush species by plots within ",
                toString(EcologicalSiteId))), rownames = FALSE)
    }
    if (SummaryVar == "Height" & SummarizeBy == "EcologicalSite" &
        GroupBy == "Sagebrush") {
        table <- HgtPrep %>% filter(!is.na(SG_Group)) %>% subset(SG_Group ==
            "Sagebrush") %>% group_by(Species, ScientificName,
            CommonName, SG_Group) %>% summarize(AverageHeight_cm = mean(Hgt_Species_Avg),
            Standard_Deviation_cm = sd(Hgt_Species_Avg), MinHeight_cm = min(Hgt_Species_Avg),
            MaxHeight_cm = max(Hgt_Species_Avg), n = sum(Hgt_Species_Avg_n)) %>%
            mutate_if(is.numeric, round, digits = 2) %>% DT::datatable(extensions = "Buttons",
            filter = "top", options = list(scrollX = TRUE, dom = "Bfrtip",
                buttons = list(list(extend = "collection", buttons = c("csv",
                  "excel"), text = "Download Table"))), caption = (paste("Heights by sagebrush species in ",
                toString(EcologicalSiteId))), rownames = FALSE)
    }
    return(table)
  }

R-Burke/SiteSummaryTool documentation built on Oct. 15, 2020, 8:21 p.m.