R/plot_validationcurve.R

Defines functions plot_validationcurve

Documented in plot_validationcurve

#' @title Plot validation curve
#' @author Melody Premailon
#'
#' @description Plot validation and succes curve (from validation and train data)
#'
#' @param df_postprobfreq data frame of postprob frequancy (from build_df_postprobfreq function)
#'
#' @return a ggplot object
#' @import ggplot2
#' @export



plot_validationcurve <- function(df_postprobfreq){

  #AUC
  aucs <- calcAUC(df_postprobfreq)

  #Plot
  valgg <- ggplot(df_postprobfreq, aes(count_cum_prct, val_cum_prct)) +
    geom_line(aes(count_cum_prct, trng_cum_prct), color="red", size=1) +
    geom_line(color="darkblue", size=1.2) +
    geom_area(aes(count_cum_prct, val_cum_prct), fill="darkblue", alpha=.1) +
    theme_light() +
    theme(
      plot.title.position = "plot",
      plot.title = element_text(color="black"),
    )  +
    labs(title = "Courbes de succès et validation") +
    scale_x_continuous(name = "Surface de la carte \n(en % cumules)",
                       breaks = seq(0,100, by=25),
                       labels = seq(0,100, by=25)) +
    scale_y_continuous(name = "Nombre de mouvements de terrain \n(en % cumules)",
                       limits=c(0,100)) +
    geom_text(aes(x=100, y = 25, label = paste("courbe de succes, AUC =", aucs$training )),
              color="red", hjust = 1) +
    geom_text(aes(x=100, y = 20, label = paste("courbe de validation, AUC =", aucs$validation )),
              color="darkblue", hjust = 1) +
    coord_fixed(ratio =1)

  return(valgg)
}
MelodyPremaillon/valwoe documentation built on April 16, 2022, 12:46 a.m.