R/dotplot1.R

#' dotplot1
#'
#' Dotplot sans affichage de texte/information/identification des points
#'
#' @param x data.
#' @param limref tableau indiquant les limites de références.
#' @param cvs CVS d'analyse.
#' @param cvslabel valeur du CVS à partir duquel on identifie les outliers.
#' @param max.ratio valeur max de l'axe des thetaj.
#'
#' @return ggplot
#' @import ggplot2
#' @keywords internal
#' @export
dotplot1 <- function(x, limref, cvs, cvslabel = max(cvs), max.ratio){

  # variables
  yr <- paste0("\n(",unique(x$an)," - ",unique(x$an)+length(an.analyse),")")  # indication de l'année
  ptitle <- ifelse(unique(x$descriptif) == "",  # titre selon descriptif
                   paste(unique(x$code), yr),
                   paste(unique(x$code), "-", unique(x$descriptif), yr))
  psubtitle <- paste("CVS =", format(round(unique(x$CVS), 1), nsmall = 1, decimal.mark = ",")) # soustitre
  cvslinetype <- c("twodash", "longdash", "solid")
  cvslinetype <- cvslinetype[seq(1, length(cvs))]

  # Graphe
  p <- ggplot(x, aes(thetaj, fill = Outlier)) +
    geom_dotplot(stackdir = "center",  # centrer
                 color = "white",  # couleur contour points
                 alpha = 0.8) +  # opacité des points
    scale_fill_manual(values = c("#5792CC", "#5792CC")) +  # couleurs (pas outlier, outlier)
    # lignes verticales (horizontales sur graphe)
    geom_vline(xintercept = 1,  # affichage de la moyenne
               linetype = "dotted",
               color = "black") +
    geom_vline(aes(xintercept = valeur,  # affichage limites de référence selon CVSréf
                   linetype = factor(cvs)),
               data = limref,
               color = "#5792CC") +
    scale_linetype_manual(values = cvslinetype) +  # type de lignes
    # visuel du graphe
    labs(title = ptitle,  # titre
         subtitle = psubtitle,  # sous-titre
         x = TeX("$\\hat{\\theta}_{j}$")) +  # titre xaxis (inversé)
    scale_x_continuous(limits = c(0, max.ratio),  # limites de l'axe
                       breaks = seq(0, max.ratio, 0.1),
                       labels = insert_minor(format(seq(0, max.ratio, 0.5),
                                                    nsmall = 1,  # afficher tjrs une décimale
                                                    decimal.mark = ","), 4)) +
    theme(plot.title = element_text(hjust = 0.5, size = 12),  # titre
          plot.subtitle = element_text(hjust = 0.5, size = 12, color = "red"),  # sous-Titre
          panel.background = element_blank(),  # fond blanc
          legend.position = c(0.9, 0.9),  # droite + haut
          axis.ticks.x = element_blank(),  # supprimer ticks
          axis.title.x = element_blank(),  # supprimer titre
          axis.text.x = element_blank(),  # supprimer valeurs ticks
          axis.line.y = element_line(size = 0.75),  # taille de la ligne yaxis
          axis.ticks.y = element_line(size = 0.75),  # taille des ticks yaxis
          axis.title.y = element_text(size = 15)  # taille titre yaxis
    ) +
    coord_flip() +  # inverser les axes
    # Afficher légendes
    guides(fill = FALSE,  # couleur des points
           linetype = FALSE)  # type de ligne

  return(p)
}
INESSSQC/variation documentation built on July 3, 2019, 11:33 a.m.