SummaryTables_WithAttributes: SummaryTables_WithAttributes

Description Usage Arguments Details Author(s) Examples

View source: R/SummaryTables_WithAttributes.R

Description

Produces a DT::datatable of cover summaries for species, growth habit, noxious status, woody vs. non-woody, sage-grouse group, preferred forbs for sage-grouse, ground cover indicators, canopy gap, as well as soil stability ratings, and presence of trace species. Tables can be summarized across the entire ecological site(s), or within each individual plot. Outputs are html objects that can be directly downloaded to Excel.

Usage

1
SummaryTables(EcoSitePlots, Species_plots_ecosite, SummaryVar, SummarizeBy, Attributed_Pks)

Arguments

EcoSitePlots

Combined TerrADat and LMF dataframe, subset to your ecological site. Returned object from consecutive Combine_AIM_LMF and SubsetEcologicalSite functions.

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

c("Species", "GrowthHabitSub", "Noxious", "Woody", "SageGrouseGroup", "PreferredForb", "TraceSpecies", "GroundCover", "Gap", "SoilStability")

SummarizeBy

c("Plot", "EcologicalSite")

Attributed_Pks

simplified dataframe with PrimaryKeys associated with each shapefile attribute

Details

To get Attributed_Pks- attribute_title <- c("ALLOT_NAME", "ALLOT_NO", "PAST_NAME") TDat_LMF_Attributed <- AttributePlots(TDat_LMF = TDat_LMF, shapefile_name = shapefile_name, shapefile_path = shapefile_path, attribute_title = attribute_title) Attributed_Pks <- dplyr::select(TDat_LMF_Attributed, PrimaryKey, all_of(attribute_title))

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
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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
#To summarize ground cover variables across each individual plot:

SummaryTables_WithAttributes(EcoSitePlots, Species_plots_ecosite,
              SummaryVar = "GroundCover",
              SummarizeBy = "Plot",
              Attributed_Pks = Attributed_Pks)

#To summarize ground cover variables across an ecological site(s):

SummaryTables_WithAttributes(EcoSitePlots, Species_plots_ecosite,
              SummaryVar = "GroundCover",
              SummarizeBy = "EcologicalSite",
              Attributed_Pks = Attributed_Pks)

## The function is currently defined as
function(EcoSitePlots, Species_plots_ecosite, 
                          SummaryVar, SummarizeBy, 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)

# Prep species richness for trace species

#Prep

#Detected in richness only on plot
RichnessPresent <- Species_plots_ecosite_attributed 
#Detected in LPI on plot
LPI_Present <- Species_plots_ecosite_attributed 
#Removes duplicates
LPI_Present_String <- unique(LPI_Present$Species)
#Removes values from richness that also occurred in LPI
RichnessSpecies_Only <- RichnessPresent[!(RichnessPresent[["Species"]] 
#Removes duplicates
TraceCover_List <- unique(RichnessSpecies_Only$Species)
#Get into dataframe (just select state species that were trace)
TraceSpeciesCover <- Species_plots_ecosite_attributed[Species_plots_ecosite_attributed[["Species"]] 

TraceCover_Table_SpList <- TraceSpeciesCover 
                dplyr::select(Species, ScientificName , Family , GrowthHabit ,
                GrowthHabitSub , Duration, Noxious , SG_Group ,
                SynonymOf , CommonName ,
                UpdatedSpeciesCode, link, ALLOT_NAME, ALLOT_NO, PAST_NAME) 

if(SummaryVar == "Species" & SummarizeBy == "Plot"){
  #hyperlink species
  Species_plots_ecosite_attributed$Species <- paste0("<a href='",Species_plots_ecosite_attributed$link,"'>",Species_plots_ecosite_attributed$Species,"</a>")
  
  table <- Species_plots_ecosite_attributed 
           DT::datatable(escape = FALSE, extensions = 'Buttons', filter = "top" , 
                  options = list(scrollX = TRUE ,
                            dom = 'Bfrtip',
                            buttons =
                            list(list(extend = 'collection', buttons = c('csv', 'excel'),
                            text = 'Download Table'))) , 
                  caption = (paste("Percent Cover by Species by Plot within " , toString(EcologicalSiteId))) , 
                  rownames = FALSE)
}

if(SummaryVar == "Species" & SummarizeBy == "EcologicalSite"){
  #For summarizing across all plots
  Species_cover_summary <- Species_plots_ecosite_attributed 
                           mutate(Tally = 1) 
                           group_by(Species , GrowthHabit , GrowthHabitSub , 
                           Duration , Noxious , ScientificName , 
                           CommonName , SG_Group, link) 
                           summarize(AveragePercentCover = mean(AH_SpeciesCover) ,
                           StandardDeviation = sd(AH_SpeciesCover),
                           MinCover = min(AH_SpeciesCover) ,
                           MaxCover = max(AH_SpeciesCover) , n = sum(Tally)) 
                           mutate_if(is.numeric, round , digits = 2) 
                           dplyr::select(Species, ScientificName, 
                           AveragePercentCover, StandardDeviation,
                           MinCover, MaxCover, n, GrowthHabit, 
                           GrowthHabitSub, Duration, 
                           Noxious, CommonName, SG_Group, link)
 
  #hyperlink species
  Species_cover_summary$Species <- paste0("<a href='",Species_cover_summary$link,"'>", Species_cover_summary$Species,"</a>")
  
  table <- Species_cover_summary 
                                                            extensions = 'Buttons', 
                                                            filter = "top" , 
                                                            options = list(scrollX = TRUE ,
                                                            dom = 'Bfrtip',
                                                            buttons =
                                                            list(list(
                                                            extend = 'collection',
                                                            buttons = c('csv', 'excel'),
                                                            text = 'Download Table'))) , 
                                                            caption = (paste("Average Percent Cover Values Across" , toString(EcologicalSiteId))) , 
                                                            rownames = FALSE)
}


if(SummaryVar== "GrowthHabitSub" & SummarizeBy == "Plot"){
  
       table <-  Species_plots_ecosite_attributed 
                 group_by(PrimaryKey , PlotID , GrowthHabitSub , Duration) 
                 summarize(PercentCover = sum(AH_SpeciesCover)) 
                 mutate_if(is.numeric, round , digits = 2) 
                 filter(!is.na(GrowthHabitSub)) 
                 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("Percent Cover by Structure and Functional Group by Plot  within " , 
                                   toString(EcologicalSiteId))), 
                  rownames = FALSE)
}

if(SummaryVar == "GrowthHabitSub" & SummarizeBy == "EcologicalSite"){
    #removes trace species
    table <- Species_plots_ecosite_attributed 
                              mutate(Tally = 1) 
                              group_by(GrowthHabitSub, Duration, Tally) 
              summarize(AveragePercentCover = mean(AH_SpeciesCover) ,
              StandardDeviation = sd(AH_SpeciesCover),
              MinCover = min(AH_SpeciesCover) ,
              MaxCover = max(AH_SpeciesCover) , n = sum(Tally)) 
              mutate_if(is.numeric, round , digits = 2) 
              select(-Tally) 
              filter(!is.na(GrowthHabitSub)) 
              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("Percent Cover by Structure and Functional Group in " , 
                                   toString(EcologicalSiteId))), 
                  rownames = FALSE)
    
}

if(SummaryVar== "Noxious" & SummarizeBy == "Plot"){
  
  table <- EcoSitePlots 
                   rename(NonNoxious = AH_NonNoxCover, Noxious = AH_NoxCover) 
                   dplyr::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("Percent Cover Noxious Versus Non by Plot within " , 
                                                  toString(EcologicalSiteId))) , 
                                 rownames = FALSE)
}

if(SummaryVar== "Noxious" & SummarizeBy == "EcologicalSite"){
 
 prep <-  EcoSitePlots 
                            dplyr::rename(NonNoxious = AH_NonNoxCover, Noxious = AH_NoxCover) 
                            gather(key = "Noxious", value = Percent,
                                   NonNoxious:Noxious) 
                            dplyr::mutate(Tally = 1) 
 
 prep$Noxious <- gsub("NonNoxious" , "No", prep$Noxious)
 prep$Noxious <- gsub("Noxious", "Yes", prep$Noxious)
  
   table <-   prep 
              summarize(AveragePercentCover = mean(Percent) ,
              StandardDeviation = sd(Percent),
              MinCover = min(Percent) ,
              MaxCover = max(Percent) , n = sum(Tally)) 
              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("Percent Cover Noxious Versus Non in " , 
                                    toString(EcologicalSiteId))) , 
                   rownames = FALSE)
  
}

if(SummaryVar == "Woody" & SummarizeBy == "Plot"){
  
   table <-  Species_plots_ecosite_attributed 
                  group_by(GrowthHabit , PrimaryKey , PlotID) 
                  summarize(PercentCover = sum(AH_SpeciesCover)) 
                  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("Percent Cover Woody vs. Non by Plot within: " , toString(EcologicalSiteId))) , 
                      rownames = FALSE)
  
}

if(SummaryVar == "Woody" & SummarizeBy == "EcologicalSite"){

    table <- Species_plots_ecosite_attributed 
              mutate(Tally = 1) 
              group_by(GrowthHabit , Tally) 
              summarize(AveragePercentCover = mean(AH_SpeciesCover) ,
              StandardDeviation = sd(AH_SpeciesCover),
              MinCover = min(AH_SpeciesCover) ,
              MaxCover = max(AH_SpeciesCover) , n = sum(Tally)) 
              subset(AveragePercentCover > 0.0000) 
              mutate_if(is.numeric, round , digits = 2) 
              dplyr::select(-Tally) 
              filter(!is.na(GrowthHabit)) 
              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("Percent Cover Woody vs. Non in: " , 
                                             toString(EcologicalSiteId))) , 
                                       rownames = FALSE)
    
}


if(SummaryVar == "SageGrouseGroup" & SummarizeBy == "Plot"){
   table <-     Species_plots_ecosite_attributed 
                filter(!is.na(AH_SpeciesCover)) 
                group_by(SG_Group, PrimaryKey , PlotID) 
                summarize(PercentCover = sum(AH_SpeciesCover)) 
                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("Percent Cover by Sage-Grouse Group by Plot within: " , 
                                   toString(EcologicalSiteId))), 
                  rownames = FALSE)
}

if(SummaryVar == "SageGrouseGroup" & SummarizeBy == "EcologicalSite"){
  
 table <-  Species_plots_ecosite_attributed 
    filter(!is.na(AH_SpeciesCover)) 
    group_by(SG_Group, Tally) 
    summarize(AveragePercentCover = mean(AH_SpeciesCover) ,
              StandardDeviation = sd(AH_SpeciesCover),
              MinCover = min(AH_SpeciesCover) ,
              MaxCover = max(AH_SpeciesCover) , n = sum(Tally)) 
              mutate_if(is.numeric, round , digits = 2) 
              dplyr::select(-Tally) 
              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("Percent Cover by Sage-Grouse Group in " , 
                                  toString(EcologicalSiteId))) , 
                 rownames = FALSE)
  
}

if(SummaryVar == "PreferredForb" & SummarizeBy == "Plot"){
  
   table <- Species_plots_ecosite_attributed 
            mutate(PreferredForb = (SG_Group == "PreferredForb")) 
            subset(PreferredForb == TRUE) 
            subset(AH_SpeciesCover > 0.0000) 
            filter(!is.na(AH_SpeciesCover)) 
            group_by(Species, PrimaryKey , PlotID) 
            summarize(PercentCover = sum(AH_SpeciesCover)) 
            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("Percent Cover by Preferred Forb By Plot within " , 
                                   toString(EcologicalSiteId))) , 
                  rownames = FALSE)
  
  
}

if(SummaryVar == "PreferredForb" & SummarizeBy == "EcologicalSite"){
  
  table <- Species_plots_ecosite_attributed 
           mutate(PreferredForb = (SG_Group == "PreferredForb")) 
           subset(PreferredForb == TRUE) 
           subset(AH_SpeciesCover > 0.0000) 
           filter(!is.na(AH_SpeciesCover)) 
           filter(!is.na(AH_SpeciesCover)) 
           mutate(Tally = 1) 
           group_by(Species, Tally) 
           summarize(AveragePercentCover = mean(AH_SpeciesCover) ,
                     StandardDeviation = sd(AH_SpeciesCover),
                     MinCover = min(AH_SpeciesCover) ,
                     MaxCover = max(AH_SpeciesCover) , n = sum(Tally)) 
           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("Percent Cover by Preferred Forb in " , 
                                         toString(EcologicalSiteId))) , 
                        rownames = FALSE)
  
}

if(SummaryVar == "TraceSpecies" & SummarizeBy == "Plot"){
  
          RichnessPresent <-  RichnessPresent 
          dplyr::select(Species, ScientificName , GrowthHabit ,
          GrowthHabitSub , Duration, Noxious , SG_Group, 
          PrimaryKey, PlotID, link, ALLOT_NAME, ALLOT_NO, PAST_NAME) 

          RichnessPresent$Species <- paste0("<a href='",RichnessPresent$link,"'>", RichnessPresent$Species,"</a>")
  
          table <- RichnessPresent 
                   DT::datatable(escape = FALSE, extensions = 'Buttons', 
                         filter = "top" , options = list(scrollX = TRUE ,
                         dom = 'Bfrtip',
                         buttons =
                         list(list(
                         extend = 'collection',
                         buttons = c('csv', 'excel'),
                         text = 'Download Table'))) , 
                         caption = (paste("Trace Species by Plot within " , 
                                         toString(EcologicalSiteId))) , 
                         rownames = FALSE)
  
}

if(SummaryVar == "TraceSpecies" & SummarizeBy == "EcologicalSite"){
  
  
  TraceCover_Table_SpList$Species <- paste0("<a href='",TraceCover_Table_SpList$link,"'>", TraceCover_Table_SpList$Species,"</a>")
 
   table <- TraceCover_Table_SpList 
                              select(-link) 
                              DT::datatable(escape = FALSE, 
                                            extensions = 'Buttons', 
                                            filter = "top" , 
                                            options = list(scrollX = TRUE ,
                                            dom = 'Bfrtip',
                                            buttons =
                                            list(list(
                                            extend = 'collection',
                                            buttons = c('csv', 'excel'),
                                            text = 'Download Table'))) , 
                                            caption = (paste("Trace species in " , 
                                                       toString(EcologicalSiteId))) , 
                                                       rownames = FALSE)
  
   
}

if(SummaryVar == "GroundCover" & SummarizeBy == "Plot"){

            table <- EcoSitePlots 
                     TotalFoliarCover , FH_TotalLitterCover , 
                     FH_RockCover, ALLOT_NAME, ALLOT_NO, PAST_NAME) 
                     gather(key = Indicator , value = Percent, 
                     BareSoilCover:FH_RockCover) 
                     group_by(PlotID, PrimaryKey, Indicator) 
                     mutate_if(is.numeric, round , digits = 2) 
                     rename(PercentCover = Percent) 
                     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("Percent cover by plot within " , 
                                                    toString(EcologicalSiteId))) , 
                                             rownames = FALSE)
}

if(SummaryVar == "GroundCover" & SummarizeBy == "EcologicalSite"){
  
        table <- EcoSitePlots 
                                                TotalFoliarCover , FH_TotalLitterCover , 
                                                FH_RockCover) 
                 gather(key = Indicator , value = Percent, 
                 BareSoilCover:FH_RockCover) 
                 group_by(Indicator) 
                 summarize(AveragePercentCover = mean(Percent) ,
                 Standard_Deviation = sd(Percent) ,
                 Low = min(Percent) ,
                 High = max(Percent), n = sum(Tally)) 
                 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("Average percent cover in " , 
                                         toString(EcologicalSiteId))) , 
                        rownames = FALSE)

}

if(SummaryVar == "Gap" & SummarizeBy == "Plot"){

  table  <- EcoSitePlots 
                             GapCover_25_50 , GapCover_51_100 , 
                             GapCover_101_200 , GapCover_200_plus , 
                             GapCover_25_plus, ALLOT_NAME, ALLOT_NO, PAST_NAME) 
                             gather(key = Gap_Class_cm , 
                             value = Percent , GapCover_25_50:GapCover_25_plus) 
                             mutate_if(is.numeric , round, digits = 2) 
                             group_by(PlotID , PrimaryKey) 
                             mutate_if(is.numeric, round , digits = 2) 
                             rename(Percent_Cover = Percent) 
                             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("Percent cover by canopy gap class by plot within " , 
                                                           toString(EcologicalSiteId))) , 
                                           rownames = FALSE)
}

if(SummaryVar == "Gap" & SummarizeBy == "EcologicalSite"){
  
  table <- EcoSitePlots 
                                          GapCover_25_50 , GapCover_51_100 , 
                                          GapCover_101_200 , GapCover_200_plus , 
                                          GapCover_25_plus) 
                            gather(key = Gap_Class_cm , 
                            value = Percent , GapCover_25_50:GapCover_25_plus) 
                            mutate_if(is.numeric , round, digits = 2) 
                            group_by(Gap_Class_cm) 
                            summarize(AveragePercentCover = mean(Percent) ,
                            StandardDeviation = sd(Percent),
                            MinPercentCover = min(Percent) ,
                            MaxPercentCover = max(Percent)) 
                            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("Percent cover by canopy gap class in: " , 
                                             toString(EcologicalSiteId))) , 
                                      rownames = FALSE)
  
}
  
if(SummaryVar == "SoilStability" & SummarizeBy == "Plot"){
  
        table <-  EcoSitePlots 
                                   SoilStability_All , 
                                   SoilStability_Protected , 
                                   SoilStability_Unprotected, ALLOT_NAME, ALLOT_NO, PAST_NAME) 
                  gather(key = Veg , value = Rating , 
                  SoilStability_All:SoilStability_Unprotected) 
                  mutate_if(is.numeric, round, digits = 2)  
                  group_by(PrimaryKey , PlotID) 
                  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("Soil stability ratings by plot in: " , 
                                         toString(EcologicalSiteId))) , 
                                rownames = FALSE)

}

if(SummaryVar == "SoilStability" & SummarizeBy == "EcologicalSite"){
  
           table <-  EcoSitePlots 
                                           SoilStability_All , 
                                           SoilStability_Protected , 
                                           SoilStability_Unprotected) 
                                      gather(key = Veg , value = Rating , 
                                      SoilStability_All:SoilStability_Unprotected) 
                                      mutate_if(is.numeric, round, digits = 2)  
                                      group_by(Veg) 
                                      summarize(AverageSoilStability = mean(Rating , na.rm = TRUE) ,
                                      StandardDeviation = sd(Rating , na.rm = TRUE) ,
                                      MinSoilStability = min(Rating , na.rm = TRUE) ,
                                      MaxSoilStability = max(Rating, na.rm = TRUE)) 
                                      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("Average soil stability ratings in: " , 
                                            toString(EcologicalSiteId))) , 
                           rownames = FALSE)

}

return(table)

}

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