Description Usage Arguments Details Author(s) Examples
View source: R/SageGrouseSummaries_WithAttributes.R
Returns boxplot of Sage-Grouse indicator percent cover within your specified ecological site(s), colored by allotment information. Select one Sage-Grouse indicator in the inputs. Will return NULL if your specified state does not contain Type I Sage-Grouse habitat. Currently hard-coded with BLM naming convention for allotments, will update to generalize.
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") |
Attributed_Pks |
simplified dataframe with PrimaryKeys associated with each shapefile attribute |
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.
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))
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 | # For interactive plot:
plotly::ggplotly(SageGrouseSummaries_WithAttributes(EcoSitePlots, Species_plots_ecosite,
SummaryVar = "SageGrouseGroup",
Interactive = TRUE, Attributed_Pks = Attributed_Pks), tooltip = "text")
# For static plot:
SageGrouseSummaries_WithAttributes(EcoSitePlots, Species_plots_ecosite,
SummaryVar = "SageGrouseGroup", Interactive = FALSE, Attributed_Pks = Attributed_Pks)
## The function is currently defined as
function(EcoSitePlots_Attributed, Species_plots_ecosite,
Interactive, SummaryVar, Attributed_Pks){
SageGrouseStates <- c("CO", "UT", "NV", "CA", "WY", "MT", "ID", "OR", "WA", "ND", "SD")
#Prep
SpeciesList <- SpeciesList
Family, SpeciesState,
SynonymOf, UpdatedSpeciesCode)
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_attributed <- merge(Species_plots_ecosite, Attributed_Pks, by = "PrimaryKey", all = TRUE)
unique()
EcoSitePlots_Attributed <- merge(EcoSitePlots, Attributed_Pks, by = "PrimaryKey", all = TRUE)
Attribute_Fill <- scales::seq_gradient_pal("#009966", "#E69F00", "Lab")(seq(0,1, length.out = length(unique(Species_plots_ecosite_attributed$PAST_NAME))))
Species_plots_ecosite_attributed <- merge(Species_plots_ecosite_attributed , 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, ALLOT_NAME, ALLOT_NO, PAST_NAME)
dplyr::mutate_if(is.numeric, round , digits = 2)
filter(!is.na(SG_Group)) # only filter this for the sage-grouse plots
if(!EcoSitePlots_Attributed$State
else{
if(SummaryVar == "PreferredForb"){
PrefForb <- Species_plots_ecosite_attributed
filter(!is.na(SG_Group))
mutate(PreferredForb = (SG_Group == "PreferredForb"))
subset(PreferredForb == TRUE)
subset(AH_SpeciesCover > 0.0000)
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 ,
"Allotment: ", ALLOT_NAME,
"Pasture: ", PAST_NAME,
sep = "<br>"))) +
geom_boxplot(width = .6 , outlier.shape = NA) +
geom_jitter(width = .15 , size = 2 , 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){
#add this if statement to every plot. it will return NULL if the dataframe is empty
SG_Plots <- if (nrow(PrefForb) < 1) {SG_Plots <- NULL} else{
ggplot(PrefForb , aes(x = Species , y = AH_SpeciesCover)) +
geom_boxplot(width = .6 , outlier.shape = NA) +
geom_jitter(width = .15 , size = 2, aes(color = PAST_NAME, shape = Noxious)) +
scale_color_manual(values = Attribute_Fill, na.value="#000000") +
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"){
##SG GROUP
if(Interactive){
SG_Plots <- ggplot(Species_plots_ecosite_attributed, 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 ,
"Allotment: ", ALLOT_NAME,
"Pasture: ", PAST_NAME,
sep = "<br>"))) +
geom_boxplot(width = .6 , outlier.shape = NA) +
geom_jitter(width = .15 , size = 2 , 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_attributed , aes(x = SG_Group , y = AH_SpeciesCover)) +
geom_boxplot(width = .6 , outlier.shape = NA) +
geom_jitter(width = .15 , size = 2, aes(color = PAST_NAME, shape = Noxious)) +
scale_y_continuous(limits = c(0 , 100)) +
theme_light() +
labs(y = "Percent Cover") +
scale_color_manual(values = Attribute_Fill, na.value="#000000") +
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_Attributed
AH_SagebrushCover ,
AH_SagebrushCover_Live ,
AH_SagebrushCover_Dead,
ALLOT_NAME,
ALLOT_NO,
PAST_NAME)
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 ,
"Allotment: ", ALLOT_NAME,
"Pasture: ", PAST_NAME,
sep = "<br>"))) +
geom_boxplot(width = .6 , outlier.shape = NA) +
geom_jitter(width = .15 , size = 2 , 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 = .6 , outlier.shape = NA) +
geom_jitter(width = .15 , size = 2, aes(color = PAST_NAME)) +
scale_y_continuous(limits = c(0 , 100)) +
theme_light() +
scale_color_manual(values = Attribute_Fill, na.value="#000000") +
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.