Description Usage Arguments Author(s) Examples
View source: R/SummaryTables.R
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.
1 | SummaryTables(EcoSitePlots, Species_plots_ecosite, SummaryVar, SummarizeBy)
|
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") |
Rachel Burke, ecologist/analyst @ Jornada
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 | #To summarize ground cover variables across each individual plot:
SummaryTables(EcoSitePlots, Species_plots_ecosite,
SummaryVar = "GroundCover",
SummarizeBy = "Plot")
#To summarize ground cover variables across an ecological site(s):
SummaryTables(EcoSitePlots, Species_plots_ecosite,
SummaryVar = "GroundCover",
SummarizeBy = "EcologicalSite")
## The function is currently defined as
function (EcoSitePlots, Species_plots_ecosite, SummaryVar, SummarizeBy)
{
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)
RichnessPresent <- Species_plots_ecosite %>% filter(is.na(AH_SpeciesCover))
LPI_Present <- Species_plots_ecosite %>% filter(AH_SpeciesCover >
0)
LPI_Present_String <- unique(LPI_Present$Species)
RichnessSpecies_Only <- RichnessPresent[!(RichnessPresent[["Species"]] %in%
LPI_Present_String), ]
TraceCover_List <- unique(RichnessSpecies_Only$Species)
TraceSpeciesCover <- Species_plots_ecosite[Species_plots_ecosite[["Species"]] %in%
TraceCover_List, ]
TraceCover_Table_SpList <- TraceSpeciesCover %>% dplyr::select(Species,
ScientificName, Family, GrowthHabit, GrowthHabitSub,
Duration, Noxious, SG_Group, SynonymOf, CommonName, UpdatedSpeciesCode,
link) %>% unique()
if (SummaryVar == "Species" & SummarizeBy == "Plot") {
Species_plots_ecosite$Species <- paste0("<a href='",
Species_plots_ecosite$link, "'>", Species_plots_ecosite$Species,
"</a>")
table <- Species_plots_ecosite %>% 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("Percent Cover by Species by Plot within ",
toString(EcologicalSiteId))), rownames = FALSE)
}
if (SummaryVar == "Species" & SummarizeBy == "EcologicalSite") {
Species_cover_summary <- Species_plots_ecosite %>% filter(!is.na(AH_SpeciesCover)) %>%
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)
Species_cover_summary$Species <- paste0("<a href='",
Species_cover_summary$link, "'>", Species_cover_summary$Species,
"</a>")
table <- Species_cover_summary %>% 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("Average Percent Cover Values Across",
toString(EcologicalSiteId))), rownames = FALSE)
}
if (SummaryVar == "GrowthHabitSub" & SummarizeBy == "Plot") {
table <- Species_plots_ecosite %>% 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") {
table <- Species_plots_ecosite %>% filter(!is.na(AH_SpeciesCover)) %>%
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 %>% dplyr::select(PlotID, PrimaryKey,
AH_NoxCover, AH_NonNoxCover) %>% 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::select(PlotID, PrimaryKey,
AH_NoxCover, AH_NonNoxCover) %>% 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 %>% group_by(Noxious) %>% 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 %>% filter(!is.na(AH_SpeciesCover)) %>%
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 %>% filter(!is.na(AH_SpeciesCover)) %>%
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) %>% 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 %>% filter(!is.na(SG_Group)) %>%
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 %>% filter(!is.na(SG_Group)) %>%
filter(!is.na(AH_SpeciesCover)) %>% mutate(Tally = 1) %>%
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 %>% mutate(PreferredForb = (SG_Group ==
"PreferredForb")) %>% subset(PreferredForb == TRUE) %>%
subset(AH_SpeciesCover > 0) %>% 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 %>% mutate(PreferredForb = (SG_Group ==
"PreferredForb")) %>% subset(PreferredForb == TRUE) %>%
subset(AH_SpeciesCover > 0) %>% 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) %>% 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 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)
RichnessPresent$Species <- paste0("<a href='", RichnessPresent$link,
"'>", RichnessPresent$Species, "</a>")
table <- RichnessPresent %>% 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 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 %>% arrange(Species) %>%
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 %>% dplyr::select(PlotID, PrimaryKey,
BareSoilCover, TotalFoliarCover, FH_TotalLitterCover,
FH_RockCover) %>% gather(key = Indicator, value = Percent,
BareSoilCover:FH_RockCover) %>% mutate(Tally = 1) %>%
group_by(PlotID, PrimaryKey, Indicator) %>% mutate_if(is.numeric,
round, digits = 2) %>% select(-Tally) %>% 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 %>% dplyr::select(PlotID, PrimaryKey,
BareSoilCover, TotalFoliarCover, FH_TotalLitterCover,
FH_RockCover) %>% gather(key = Indicator, value = Percent,
BareSoilCover:FH_RockCover) %>% mutate(Tally = 1) %>%
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 %>% dplyr::select(PlotID, PrimaryKey,
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(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 %>% dplyr::select(PlotID, PrimaryKey,
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 %>% dplyr::select(PlotID, PrimaryKey,
SoilStability_All, SoilStability_Protected, SoilStability_Unprotected) %>%
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 %>% dplyr::select(PlotID, PrimaryKey,
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)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.