R/table_freq_weighted_plot.R

Defines functions table.freq.weighted.plot

Documented in table.freq.weighted.plot

#' Cette fonction permet de visualiser les tris à plats
#'
#' @param lst output tris croisés
#' @param path for save plots
#' @export
#' @examples 
#' lapply(seq_along(lst), function(x) table.freq.weighted.plot(x))

table.freq.weighted.plot = function(lst, x, path){
  data = lst[[x]] %>% 
    mutate_at(vars(modality), ~ as.factor(as.character(.x)))
  
  pl = data %>% 
    ggplot(aes(reorder(modality,weighted_percentage), weighted_percentage)) + 
    geom_bar(stat = "identity", fill = "#A7D7FD", width = .5) +
    geom_text(aes(label=paste0(round(weighted_percentage), "%")), hjust=-0.1, vjust=0.3, size = 3) + 
    labs(x=NULL,y=NULL) + 
    coord_flip() + 
    theme_minimal() +
    theme(axis.text.x = element_blank(),
          panel.grid.major = element_blank(), 
          panel.grid.minor = element_blank(),
          axis.text.y = element_text(margin = margin(t = 0, r = -15, b = 0, l = 0)))
  
  ggsave(plot = pl, paste0(path, names(lst[x]), ".png"), device = "png", units = "cm", width = 22, height = 12)
}
AlexisMayer/toolbox documentation built on Aug. 25, 2020, 3:56 p.m.