SummaryTables_Height_WithAttributes: SummaryTables_Height_WithAttributes

Description Usage Arguments Author(s) Examples

View source: R/SummaryTables_Height_WithAttributes.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). Fields for spatial attribute are included (currently hard coded for BLM grazing allotment naming convention. Outputs are html objects that can be directly downloaded to Excel.

Usage

1
SummaryTables_Height(Species_plots_ecosite, SummaryVar, SummarizeBy, GroupBy, Attributed_Pks)

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")

Attributed_Pks

simplified dataframe with PrimaryKeys associated with each shapefile attribute

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

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

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

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


## The function is currently defined as
function(Species_plots_ecosite, 
                          SummaryVar, SummarizeBy, GroupBy, Attributed_Pks){

#Prep
SpeciesList <- SpeciesList 
                                             Family, SpeciesState, 
                                             SynonymOf, UpdatedSpeciesCode, SpeciesState) 
  dplyr::mutate(link = paste("https://plants.sc.egov.usda.gov/core/profile?symbol=", Species, sep = ""))

#Merge with species list so we can hover for scientific name

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) 

#Merge with Attributed_Pks
Species_plots_ecosite_attributed <- merge(Species_plots_ecosite, Attributed_Pks, by = "PrimaryKey", all = TRUE) 
                                    unique() 

EcoSitePlots_Attributed <- merge(EcoSitePlots, Attributed_Pks, by = "PrimaryKey", all = TRUE)

    
#Get Noxious versus Non in Standard Format
    
Species_plots_ecosite_attributed$Noxious <- gsub("YES" , "Yes", Species_plots_ecosite_attributed$Noxious)
Species_plots_ecosite_attributed$Noxious <- gsub("NO", "No", Species_plots_ecosite_attributed$Noxious)  

HgtPrep <- Species_plots_ecosite_attributed 
           filter(!is.na(GrowthHabitSub))  

if(SummaryVar == "Height" & SummarizeBy == "Plot" & GroupBy == "GrowthHabit"){
  
 table  <- HgtPrep 
              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),
              Allotment = ALLOT_NAME,
              Pasture = PAST_NAME)
              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 
                     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"){
  # Figure out why this isn't working
  #HgtPrep$Species <- paste0("<a href='",HgtPrep$link,"'>", HgtPrep$Species,"</a>")
              
  table <- HgtPrep 
                                           ScientificName , CommonName , 
                                           GrowthHabitSub, Duration) 
                                   dplyr::select(GrowthHabitSub , Duration , PlotID , 
                                   PrimaryKey , Hgt_Species_Avg , 
                                   Hgt_Species_Avg_n, ALLOT_NAME, ALLOT_NO, PAST_NAME) 
                                   dplyr::rename(Allotment = ALLOT_NAME, 
                                                 AllotmentNumber = ALLOT_NO, 
                                                 Pasture = PAST_NAME) 
                                   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 
                                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 
                 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, ALLOT_NAME, ALLOT_NO, PAST_NAME) 
                  dplyr::rename(Allotment = ALLOT_NAME, 
                  AllotmentNumber = ALLOT_NO, 
                  Pasture = PAST_NAME) 
                  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 
                          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.