#' @title Plots 'multiple' mort category's original AGENTCD
#' @description
#'
#' Input data is optional - defaults to package mortality dataset
#'
#' @param mort_df Mortality dataset, defaults to package dataset
#' @param tree_df Tree dataset, defaults to package dataset
#' @param clear_prev_plots Logical, clear plotting environment before plotting?
#'
#' @export
#' @examples PlotPolarWithMultipleMort()
PlotPolarWithMultipleMort <- function(mort_df = NULL, tree_df = NULL,
clear_prev_plots = F) {
#fia_dir <- 'C:/Users/Brandon/Documents/docs/PHD/FIA/data'
if(length(mort_df) == 0) {
mort_df <- PrepPlotEnvir(ret = 'plots', clear = clear_prev_plots)
} else {
PrepPlotEnvir(ret = NULL, clear = clear_prev_plots)
}
if (length(tree_df) == 0) {
tree_df <- FIA_mortality_TREE_level
}
mort_df <- mort_df[which(mort_df$dominant_AGENTCD == 'Multiple'), ]
tree_df <- tree_df[which(tree_df$PLT_CN %in% mort_df$PLT_CN), ]
AGENT_tbl <- table(tree_df$AGENTCD)
names(AGENT_tbl) <- KeyAgentCode(7.2)(as.numeric(names(AGENT_tbl)))
AGENT_tbl <- as.data.frame(round(AGENT_tbl / sum(AGENT_tbl), 3), stringsAsFactors = F)
AGENT_tbl <- AGENT_tbl[order(AGENT_tbl$Var1), ]
llab <- 'Comorbid\nMortality\nAgents'
p_lab <- as.character(AGENT_tbl$Freq)[order(AGENT_tbl$Var1)]
polar_bar <- ggplot(data = AGENT_tbl) + theme_bw() +
geom_bar(aes(x = Var1,
y = Freq,
fill = Var1),
stat = 'identity') +
guides(fill = guide_legend(title = llab)) +
scale_fill_manual(values = brewer.pal(name = 'Paired', n = 9)[c(1:5, 7:9)]) +
scale_x_discrete(labels = p_lab) +
xlab('') + ylab('Fraction of total dead trees') +
coord_polar()
print(polar_bar)
invisible()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.