Description Usage Arguments Details Author(s) Examples
View source: R/SageGrouseSummaries.R
Returns boxplot of Sage-Grouse indicator percent cover within your specified ecological site(s). Select one Sage-Grouse indicator in the inputs. Will return NULL if your specified state does not contain Type I Sage-Grouse habitat
1 | SageGrouseSummaries(EcoSitePlots, Species_plots_ecosite, Interactive, SummaryVar)
|
EcoSitePlots |
Combined TerrADat and LMF dataframe, subset to your ecological site. Returned object from consecutive Combine_AIM_LMF() and SubsetEcologicalSite(). |
Species_plots_ecosite |
Combined TerrADat and LMF species indicators, subset to your ecological site. Returned object from consecutive Combine_AIM_LMF_Species() and SubsetEcologicalSite_Species(). |
Interactive |
logical. If TRUE, boxplot aesthetics will be set up for interactive plotly::ggplotly object. If FALSE, will return static box plot. |
SummaryVar |
c("PreferredForb", "SageGrouseGroup", "Sagebrush") |
SummaryVar == "PreferredForb"" returns cover values grouped by individual species on preferred forb list. SummaryVar == "SageGrouseGroup" returns cover values grouped by NonSagebrushShrub, PreferredForb, Sagebrush, ShortStaturePerennialGrass, and TallStaturePerennialGrass. SummaryVar == "Sagebrush"" returns cover values group by individual sagebrush species.
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 | # For interactive plot:
plotly::ggplotly(SageGrouseSummaries(EcoSitePlots, Species_plots_ecosite,
SummaryVar = "SageGrouseGroup",
Interactive = TRUE), tooltip = "text")
# For static plot:
SageGrouseSummaries(EcoSitePlots, Species_plots_ecosite,
SummaryVar = "SageGrouseGroup", Interactive = FALSE)
## The function is currently defined as
function (EcoSitePlots, Species_plots_ecosite, Interactive, SummaryVar)
{
SageGrouseStates <- c("CO", "UT", "NV", "CA", "WY", "MT",
"ID", "OR", "WA", "ND", "SD")
SpeciesList <- SpeciesList %>% dplyr::select(Species, ScientificName,
CommonName, Family, SpeciesState, SynonymOf, UpdatedSpeciesCode) %>%
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, PrimaryKey, PlotID, AH_SpeciesCover,
AH_SpeciesCover_n, Hgt_Species_Avg, Hgt_Species_Avg_n,
GrowthHabit, GrowthHabitSub, Duration, Noxious, SG_Group,
link) %>% dplyr::mutate_if(is.numeric, round, digits = 2) %>%
filter(!is.na(SG_Group))
if (!EcoSitePlots$State %in% SageGrouseStates) {
SG_Plots <- paste0("No type I Sage-Grouse Habitat in ",
State)
}
else {
if (SummaryVar == "PreferredForb") {
PrefForb <- Species_plots_ecosite %>% filter(!is.na(SG_Group)) %>%
mutate(PreferredForb = (SG_Group == "PreferredForb")) %>%
subset(PreferredForb == TRUE) %>% subset(AH_SpeciesCover >
0)
if (Interactive) {
SG_Plots <- if (nrow(PrefForb) < 1) {
SG_Plots <- NULL
}
else {
ggplot(PrefForb, aes(x = Species, y = AH_SpeciesCover,
text = paste("Primary Key: ", PrimaryKey,
"Plot ID: ", PlotID, "Species: ", ScientificName,
"Code: ", Species, "Sage-Grouse Group: ",
SG_Group, "Duration: ", Duration, "Percent Cover: ",
AH_SpeciesCover, "Noxious: ", Noxious,
sep = "<br>"))) + geom_boxplot(width = 0.6,
outlier.shape = NA) + geom_jitter(width = 0.15,
size = 1, shape = 21) + scale_y_continuous(limits = c(0,
100)) + theme_light() + labs(y = "Percent Cover") +
ggtitle(paste("Percent Cover, Preferred Forbs: ",
toString(EcologicalSiteId))) + theme(axis.title.y = element_blank(),
axis.title.x = element_blank(), axis.text.y = element_blank(),
axis.ticks.y = element_blank(), panel.grid.major.y = element_blank()) +
facet_grid(rows = vars(Species), drop = TRUE,
scales = "free") + coord_flip()
}
}
if (!Interactive) {
SG_Plots <- if (nrow(PrefForb) < 1) {
SG_Plots <- NULL
}
else {
ggplot(PrefForb, aes(x = Species, y = AH_SpeciesCover)) +
geom_boxplot(width = 0.6, outlier.shape = NA) +
geom_jitter(width = 0.15, size = 1) + scale_y_continuous(limits = c(0,
100)) + theme_light() + labs(y = "Percent Cover") +
ggtitle(paste("Percent Cover, Preferred Forbs: ",
toString(EcologicalSiteId))) + theme(panel.grid.major.y = element_blank()) +
coord_flip()
}
}
return(SG_Plots)
}
if (SummaryVar == "SageGrouseGroup") {
if (Interactive) {
SG_Plots <- ggplot(Species_plots_ecosite, aes(x = SG_Group,
y = AH_SpeciesCover, text = paste("Primary Key: ",
PrimaryKey, "Plot ID: ", PlotID, "Species: ",
ScientificName, "Code: ", Species, "Sage-Grouse Group: ",
SG_Group, "Percent Cover: ", AH_SpeciesCover,
"Noxious: ", Noxious, sep = "<br>"))) + geom_boxplot(width = 0.6,
outlier.shape = NA) + geom_jitter(width = 0.15,
size = 1, shape = 21) + scale_y_continuous(limits = c(0,
100)) + theme_light() + ggtitle(paste("Percent Cover, Sage-Grouse Group: ",
toString(EcologicalSiteId))) + theme(axis.title.y = element_blank(),
axis.title.x = element_blank(), axis.text.y = element_blank(),
axis.ticks.y = element_blank(), panel.grid.major.y = element_blank()) +
facet_grid(rows = vars(SG_Group), drop = TRUE,
scales = "free") + coord_flip()
}
if (!Interactive) {
SG_Plots <- ggplot(Species_plots_ecosite, aes(x = SG_Group,
y = AH_SpeciesCover)) + geom_boxplot(width = 0.6,
outlier.shape = NA) + geom_jitter(width = 0.15,
size = 1) + scale_y_continuous(limits = c(0,
100)) + theme_light() + labs(y = "Percent Cover") +
ggtitle(paste("Percent Cover, Sage-Grouse Group: ",
toString(EcologicalSiteId))) + theme(panel.grid.major.y = element_blank(),
axis.text.y = element_blank(), axis.title.y = element_blank()) +
facet_grid(rows = vars(SG_Group), switch = "y",
scales = "free", drop = TRUE) + coord_flip()
}
return(SG_Plots)
}
}
if (SummaryVar == "Sagebrush") {
SageBrushCover <- EcoSitePlots %>% dplyr::select(PlotID,
PrimaryKey, AH_SagebrushCover, AH_SagebrushCover_Live,
AH_SagebrushCover_Dead) %>% mutate_if(is.numeric,
round, digits = 2) %>% gather(key = SageBrushCover,
value = Percent, AH_SagebrushCover:AH_SagebrushCover_Dead)
if (nrow(SageBrushCover) < 1) {
SG_Plots <- NULL
}
else {
if (Interactive) {
SG_Plots <- ggplot(SageBrushCover, aes(x = SageBrushCover,
y = Percent, text = paste("Primary Key: ",
PrimaryKey, "Plot ID: ", PlotID, "Percent Cover: ",
Percent, sep = "<br>"))) + geom_boxplot(width = 0.6,
outlier.shape = NA) + geom_jitter(width = 0.15,
size = 1, shape = 21) + scale_y_continuous(limits = c(0,
100)) + theme_light() + labs(y = "Percent Cover") +
ggtitle(paste("Percent Cover, Sagebrush: ",
toString(EcologicalSiteId))) + theme(axis.title.y = element_blank(),
axis.text.y = element_blank(), axis.title.x = element_blank(),
axis.ticks.y = element_blank(), panel.grid.major.y = element_blank()) +
facet_grid(rows = vars(SageBrushCover), scales = "free",
drop = TRUE) + coord_flip()
}
if (!Interactive) {
SG_Plots <- ggplot(SageBrushCover, aes(x = SageBrushCover,
y = Percent)) + geom_boxplot(width = 0.6, outlier.shape = NA) +
geom_jitter(width = 0.15, size = 1) + scale_y_continuous(limits = c(0,
100)) + theme_light() + labs(y = "Percent Cover",
x = "Sagebrush cover") + ggtitle(paste("Percent Cover, Sagebrush: ",
toString(EcologicalSiteId))) + theme(panel.grid.major.y = element_blank(),
axis.text.y = element_blank()) + facet_grid(rows = vars(SageBrushCover),
drop = TRUE, scales = "free") + coord_flip()
}
return(SG_Plots)
}
}
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.