R/gg_dotplot.R

#' Dotplot
#'
#' @param x Data à utiliser pour création du graphe.
#' @param cvs CVS de référence.
#' @param cvslabel CVS de référence à partir duquel on identifie les outliers.
#' @param max.ratio Valeur maximale de l'axe indiquant les thetaj.
#'
#' @import dplyr
#' @import data.table
#' @import ggplot2
#' @import latex2exp
#' @export
ggplot_dot <- function(x,
                       cvs, cvslabel = max(cvs),
                       max.ratio = 3){
  
  ### Test
  ArgCheck()
  if(!is.data.frame(x)) addError("'x' doit être de type data.frame.", argcheck)
  if(!is.numeric(cvs)) addError("'cvs' doit être de type numeric.", argcheck)
  if(!cvslabel %in% cvs) addError("'cvslabel' doit être une valeur existante de 'cvs'.", argcheck)
  if(!is.numeric(max.ratio)) addError("'max.ratio' doit être de type numeric.", argcheck)
  finishArgCheck(argcheck)
  
  ### Code
  x <- x %>%  # sélection des colonnes
    select(an, code, descriptif, region, CVS, thetaj, starts_with("liminf_cvs"), starts_with("limsup_cvs")) %>%
    as.data.table()
  x <- x[thetaj <= max.ratio]
  setorder(x, thetaj)  # tri croissant par thetaj
  limits <- limref(x)
  x <- limlabel(x, limits, cvslabel)
  p <- dotplot1(x, limits, cvs, cvslabel, max.ratio)
  x <- gg_built(x, p)
  p <- dotplot2(x, limits, cvs, cvslabel, max.ratio)
  return(p)
  
}
INESSSQC/variation documentation built on July 3, 2019, 11:33 a.m.