#' This function will plot a z-score distribution for SOS/EOS across years.
#'
#' @export
#' @title Plot Z-score distribution for SOS/EOS
#' @param critdat dataframe, a specific dataframe format (CritDates) containing a list of critical dates - created in function 'FS_fExtractAllCriticalDates'
fPlotCritDate_Zscores <- function(critdat) {
colors <- c("ECW" = "#e7d4e8", "SOS10" = "#1a9850", "SOS25" = "#91cf60", "SOS50" = "#d9ef8b", "Peak_GPPsat" = "white",
"EOS10" = "#d73027", "EOS25" = "#fc8d59", "EOS50" = "#fee08b", "SNW" = "#762a83")
colors <- colors[order(factor(names(colors), levels = c("ECW", "SOS10", "SOS25", "SOS50", "Peak_GPPsat", "EOS50", "EOS25", "EOS10", "SNW")))]
critdat$CritThreshold <- factor(critdat$CritThreshold, levels = c("ECW", "SOS10", "SOS25", "SOS50", "Peak_GPPsat", "EOS50", "EOS25", "EOS10", "SNW"))
plot_CritDate_Zscores <- ggplot(critdat, aes(x = Z, color = CritThreshold)) +
facet_wrap(. ~ CritThreshold, ncol = 4) +
geom_histogram() +
scale_y_continuous(name= "Count") +
scale_x_continuous(name= "Z-score", limits = c(-max(abs(critdat$Z), na.rm = TRUE), max(abs(critdat$Z), na.rm = TRUE))) +
scale_color_manual(name = "Critical Date", values = colors,
breaks = c("ECW", "SOS10", "SOS25", "SOS50", "Peak_GPPsat", "EOS50", "EOS25", "EOS10", "SNW"),
labels = c("ECW", expression(SOS[10]), expression(SOS[25]), expression(SOS[50]),
expression(maxGPP["sat"]), expression(EOS[50]), expression(EOS[25]), expression(EOS[10]), "SNW" )) +
ggtitle(paste0("Z-score distribution by site")) +
theme_time() +
annotate("segment", x=-Inf, xend=Inf, y=-Inf, yend=-Inf, size=1.5, color = "black") +
annotate("segment", x=-Inf, xend=-Inf, y=-Inf, yend=Inf, size=1.5, color = "black") +
theme(plot.title = element_text(color="black", hjust = 0.5, size=14, face="bold"),
plot.subtitle = element_text(color="black", hjust = 0.5, size=12),
strip.background = element_blank(),
strip.text = element_text(size = 12, face = "bold"),
axis.line = element_blank(),
legend.position = "none",
legend.title = element_blank(),
panel.grid.major = element_line(linetype = "dotted", color = "gray")) +
guides(color = guide_legend(nrow = 1))
return(plot_CritDate_Zscores)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.