Description Usage Arguments Details Author(s) Examples
View source: R/SummaryFigures_Height.R
Returns a static or interactive (plotly-friendly) ggplot boxplot summarizing species heights across your ecological site(s) based on summary variables (Growth habit, individual species, or sagebrush.)
1 | SummaryFigures_Height(Species_plots_ecosite, EcologicalSiteId, SummaryVar, GroupBy, Interactive)
|
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. |
EcologicalSiteId |
Full ecological site id, list of ecological sites, or object |
SummaryVar |
"Height"" |
GroupBy |
c("Species", "GrowthHabit", "Sagebrush") |
Interactive |
logical. If TRUE, boxplot aesthetics will be set up for interactive plotly::ggplotly object. If FALSE, will return static box plot. |
If GroupBy == "Species", returns a list of plots that must be called on- boxplots are broken up by GrowthHabitSub, with individual species within each group as faceting row. Y values are height in cm. See example for how to call on plot. If GroupBy == "GrowthHabit", returns a boxplot. X values are growth habit, Y values are height in cm. If GroupBy == "Sagebrush", returns a boxplot. X values are sagebrush species, Y values are height in cm.
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 | # If SummaryVar == "Height", GroupBy == "GrowthHabit", Interactive == TRUE:
plotly::ggplotly(SummaryFigures_Height(Species_plots_ecosite,
EcologicalSiteId, SummaryVar = "Height",
GroupBy = "GrowthHabit", Interactive = TRUE),
tooltip = "text")
# If SummaryVar == "Height", GroupBy == "GrowthHabit", Interactive == FALSE:
SummaryFigures_Height(Species_plots_ecosite, EcologicalSiteId,
SummaryVar = "Height", GroupBy = "GrowthHabit",
Interactive = FALSE)
# If SummaryVar == "Height", GroupBy == "Species", Interactive == TRUE:
Plots <- SummaryFigures_Height(Species_plots_ecosite,
EcologicalSiteId,
SummaryVar = "Height",
GroupBy = "Species",
Interactive = TRUE)
plotly::ggplotly((Plots[["Graminoid.Annual"]]), tooltip = "text")
# If SummaryVar == "Height", GroupBy == "Species", Interactive == FALSE:
Plots <- SummaryFigures_Height(Species_plots_ecosite,
EcologicalSiteId,
SummaryVar = "Height",
GroupBy = "Species",
Interactive = FALSE)
Plots[["Graminoid.Annual"]]
## The function is currently defined as
function (Species_plots_ecosite, EcologicalSiteId, SummaryVar,
GroupBy, Interactive)
{
NoxNonPal_Fill <- c("grey75", "#D55E00")
NoxNonPal_Dot <- c("grey33", "#993300")
HgtPrep <- Species_plots_ecosite %>% filter(!is.na(Hgt_Species_Avg)) %>%
filter(!is.na(GrowthHabitSub))
if (SummaryVar == "Height" & GroupBy == "Species") {
if (Interactive) {
Plots <- lapply(X = split(HgtPrep, list(HgtPrep$GrowthHabitSub,
HgtPrep$Duration), drop = TRUE), FUN = function(HgtPrep) {
current_plot <- ggplot(HgtPrep, aes(x = Species,
y = Hgt_Species_Avg, text = paste("Plot Id: ",
PlotID, "PrimaryKey: ", PrimaryKey, "Species: ",
Species, "Average Height: ", Hgt_Species_Avg,
"Average Height , n: ", Hgt_Species_Avg_n,
sep = "<br>"))) + geom_boxplot(width = 0.6,
outlier.shape = NA) + geom_jitter(width = 0.15,
shape = 21) + scale_y_continuous(limits = c(0,
100)) + theme_light() + coord_flip() + theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank(), axis.line.y = element_blank()) +
facet_grid(rows = vars(Species), switch = "y",
scales = "free_y", drop = TRUE)
return(current_plot)
})
}
if (!Interactive) {
Plots <- lapply(X = split(HgtPrep, list(HgtPrep$GrowthHabitSub,
HgtPrep$Duration), drop = TRUE), FUN = function(HgtPrep) {
current_plot <- ggplot(HgtPrep, aes(x = Species,
y = Hgt_Species_Avg)) + geom_boxplot(width = 0.6,
outlier.shape = NA) + geom_jitter(width = 0.15,
size = 1, aes(color = Noxious)) + scale_color_manual(values = NoxNonPal_Dot) +
scale_y_continuous(limits = c(0, 100)) + theme_light() +
labs(x = "Species", y = "Average Height, cm",
caption = paste("Species height in: ", toString(EcologicalSiteId),
sep = "")) + theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank(), axis.line.y = element_blank()) +
coord_flip() + facet_grid(rows = vars(Species),
switch = "y", scales = "free_y", drop = TRUE)
return(current_plot)
})
}
}
if (SummaryVar == "Height" & GroupBy == "GrowthHabit") {
if (Interactive) {
Plots <- ggplot(HgtPrep, aes(x = GrowthHabit, y = Hgt_Species_Avg,
text = paste("Plot Id: ", PlotID, "PrimaryKey: ",
PrimaryKey, "Species: ", Species, "Average Height (cm): ",
Hgt_Species_Avg, "Average Height , n: ", Hgt_Species_Avg_n,
sep = "<br>"))) + geom_boxplot() + geom_jitter(width = 0.1,
shape = 21) + theme_light() + theme(axis.ticks.y = element_blank(),
axis.line.y = element_blank(), axis.title.y = element_blank(),
axis.title.x = element_blank(), axis.text.y = element_blank()) +
coord_flip() + facet_grid(rows = vars(GrowthHabitSub),
switch = "y", scales = "free_y", drop = TRUE)
}
if (!Interactive) {
Plots <- ggplot(HgtPrep, aes(x = GrowthHabit, y = Hgt_Species_Avg)) +
geom_boxplot() + geom_jitter(width = 0.2, aes(text = PlotID)) +
labs(x = "Growth Habit", y = "Average Height, cm",
caption = paste("Species height in: ", toString(EcologicalSiteId),
sep = "")) + theme_light() + theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank(), axis.line.y = element_blank()) +
coord_flip() + facet_grid(rows = vars(GrowthHabitSub),
switch = "y", scales = "free_y", drop = TRUE)
}
}
if (SummaryVar == "Height" & GroupBy == "Sagebrush") {
Sagebrush <- HgtPrep %>% subset(SG_Group == "Sagebrush")
if (nrow(Sagebrush) < 1) {
Plots <- NULL
}
else {
if (Interactive) {
Plots <- ggplot(Sagebrush, aes(x = Species, y = Hgt_Species_Avg,
text = paste("Plot Id: ", PlotID, "PrimaryKey: ",
PrimaryKey, "Species: ", Species, "Average Height (cm): ",
Hgt_Species_Avg, "Average Height , n: ",
Hgt_Species_Avg_n, sep = "<br>"))) + geom_boxplot() +
geom_jitter(width = 0.1, shape = 21) + theme_light() +
theme(axis.ticks.y = element_blank(), axis.line.y = element_blank(),
axis.title.y = element_blank(), axis.title.x = element_blank(),
axis.text.y = element_blank()) + facet_grid(rows = vars(Species),
scales = "free_y", drop = TRUE) + coord_flip()
}
if (!Interactive) {
Plots <- ggplot(Sagebrush, aes(x = Species, y = Hgt_Species_Avg)) +
geom_boxplot() + geom_jitter(width = 0.1, shape = 21) +
theme_light() + theme(axis.ticks.y = element_blank(),
axis.line.y = element_blank()) + labs(x = "Species",
y = "Average Height, cm", caption = paste("Species height in: ",
toString(EcologicalSiteId), sep = "")) +
coord_flip()
}
}
}
return(Plots)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.