R/PlotPercentAgent.R

#' @title Plots a barplot of relative AGENTCD dominance
#' @description
#' TODO this
#'
#' @export
PlotPercentAgent <- function(mort_df = NULL) {
  # Prep:
  ylb <- 'Fraction of plots affected by mortality agent'
  if (is.null(mort_df)) {
    mort_df <- FIA_mortality_with_explanatory
  }
  ctbl <- aggregate(mort_df$percent_AGENTCD,
                    by = list(mort_df$dominant_AGENTCD),
                    FUN = mean)
  colnames(ctbl) <- c('Agent', 'Mean_Perc')
  ctbl2 <- aggregate(mort_df$percent_AGENTCD,
                     by = list(mort_df$dominant_AGENTCD),
                     FUN = sd)
  colnames(ctbl2) <- c('Agent', 'SD_Perc')
  ctbl <- dplyr::left_join(ctbl, ctbl2, by = 'Agent')
  ctbl <- ctbl[-which(ctbl$Agent == 'No Mortality'), ]
  ctbl[, c(2, 3)] <- round(ctbl[, c(2, 3)] / 100, 2)

  # Plot:
  p0 <- PlotBarPlot(df = ctbl, ylab = ylb)
  print(p0)
}
bmcnellis/RSFIA documentation built on June 1, 2019, 7:40 a.m.