# round a vector of values, if decimal, with the desired number of decimal digits after the decimal leading zeros
# BEWARE
# WARNINGS
# Work well with numbers as character strings, but not always with numerical numbers because of the floating point
# Numeric values are really truncated from a part of their decimal digits, whatever options(digits) settings
# See ?.Machine or https://stackoverflow.com/questions/5173692/how-to-return-number-of-decimal-places-in-r, with the interexting formula: abs(x - round(x)) > .Machine$double.eps^0.5
# ARGUMENTS
# data: a vector of numbers (numeric or character mode)
# dec.nb: number of required decimal digits
...
...
@@ -3112,6 +3114,9 @@ par(ini.par)
######## fun_gg_palette() #### ggplot2 default color palette
# dot.bin.nb: positive integer indicating the number of bins (i.e., nb of separations) of the ylim range. Each dot will then be put in one of the bin, with the size the width of the bin. Not considered if dot.tidy is FALSE
# dot.jitter: numeric value (from 0 to 1) of random dot horizontal dispersion, with 0 meaning no dispersion and 1 meaning a dispersion in the corresponding bar width interval. Not considered if dot.tidy is TRUE
# dot.size: numeric value of dot size. Not considered if dot.tidy is TRUE
# dot.border.size: numeric value of border dot size. Write zero for no stroke
# dot.border.size: numeric value of border dot size. Write zero for no dot border. If dot.tidy is TRUE, value 0 remove the border. Another one leave the border without size control (geom_doplot() feature)
# dot.alpha: numeric value (from 0 to 1) of dot transparency (full transparent to full opaque, respectively)
# ylim: 2 numeric values for y-axis range. If NULL, range of y in data1
# ylog: logical. Log10 scale for the y-axis? Beware: if TRUE, ylim must not contain null or negative values. In addition, will be automatically set to FALSE if vertical argument is set to FALSE, to prevent a bug in ggplot2 (see https://github.com/tidyverse/ggplot2/issues/881)
assign(paste0(tempo.gg.name,tempo.gg.count<-tempo.gg.count+1),ggplot2::geom_point(data=dot.coord.rd3,mapping=ggplot2::aes_string(x="dot.x",y="y",group=categ[length(categ)]),stroke=dot.border.size,size=dot.size,fill=dot.coord.rd3$dot.color,alpha=dot.alpha,pch=21))# group used in aesthetic to do not have it in the legend. Here ggplot2::scale_discrete_manual() cannot be used because of the group easthetic
}
}elseif(dot.tidy==TRUE){
assign(paste0(tempo.gg.name,tempo.gg.count<-tempo.gg.count+1),ggplot2::geom_dotplot(data=dot.coord,mapping=ggplot2::aes_string(x=categ[1],y="y",color=categ[length(categ)]),position=ggplot2::position_dodge(width=bar.width),binaxis="y",stackdir="center",stroke=dot.border.size,alpha=dot.alpha,fill=dot.coord[rev(order(dot.coord[,categ[1]],decreasing=TRUE)),"dot.color"],show.legend=FALSE,binwidth=(ylim[2]-ylim[1])/dot.bin.nb))# very weird behavior of geom_dotplot, because data1 seems reorderer according to x = categ[1] before plotting. Thus, I have to use fill = dot.coord[rev(order(dot.coord[, categ[1]], decreasing = TRUE)), "dot.color"] to have the good corresponding colors
assign(paste0(tempo.gg.name,tempo.gg.count<-tempo.gg.count+1),ggplot2::scale_discrete_manual(aesthetics="color",name=categ.legend.name,values=rep("black",length(categ.color))))# values = rep("black", length(categ.color)) are the values of color (which is the border color of dots), and this modify the border color on the plot. Beware: values = categ.color takes the numbers to make the colors if categ.color is a factor. BEWARE: , guide = ggplot2::guide_legend(override.aes = list(fill = levels(dot.color))) here
assign(paste0(tempo.gg.name,tempo.gg.count<-tempo.gg.count+1),ggplot2::geom_dotplot(data=dot.coord,mapping=ggplot2::aes_string(x=categ[1],y="y",color=categ[length(categ)]),position=ggplot2::position_dodge(width=bar.width),binaxis="y",stackdir="center",alpha=dot.alpha,fill=dot.coord[rev(order(dot.coord[,categ[1]],decreasing=TRUE)),"dot.color"],show.legend=FALSE,binwidth=(ylim[2]-ylim[1])/dot.bin.nb))# very weird behavior of geom_dotplot, because data1 seems reorderer according to x = categ[1] before plotting. Thus, I have to use fill = dot.coord[rev(order(dot.coord[, categ[1]], decreasing = TRUE)), "dot.color"] to have the good corresponding colors
assign(paste0(tempo.gg.name,tempo.gg.count<-tempo.gg.count+1),ggplot2::scale_discrete_manual(aesthetics="color",name=categ.legend.name,values=if(dot.border.size==0){as.character(levels(dot.coord[rev(order(dot.coord[,categ[1]],decreasing=TRUE)),"dot.color"]))}else{rep("black",length(categ.color))}))# values = rep("black", length(categ.color)) are the values of color (which is the border color of dots), and this modify the border color on the plot. Beware: values = categ.color takes the numbers to make the colors if categ.color is a factor. BEWARE: , guide = ggplot2::guide_legend(override.aes = list(fill = levels(dot.color))) here
# coordinates of tidy dots
tempo.coord<-ggplot2::ggplot_build(eval(parse(text=paste(paste0(tempo.gg.name,1:tempo.gg.count),collapse=" + "))))$data# to have the tidy dot coordinates