Commit b94c40e9 authored by Gael  MILLOT's avatar Gael MILLOT
Browse files

tempo saving

parent 7984216c
#### DESCRIPTION
Cute Little R Functions contains 34 functions for R/RStudio that facilitate basic procedures in 1) object analysis, 2) object modification, 3) graphic handling and 4) log file management.
Cute Little R Functions contains 40 functions for R/RStudio that facilitate basic procedures in 1) object analysis, 2) object modification, 3) graphic handling and 4) log file management.
The function names are:
## Object analysis
fun_param_check() #### checking class, type, length, etc. of objects
fun_object_info() #### recovering object information
fun_param_check() #### check class, type, length, etc., of objects
fun_object_info() #### recover object information
fun_1D_comp() #### comparison of two 1D datasets (vectors, factors, 1D tables)
fun_2D_comp() #### comparison of two 2D datasets (row & col names, dimensions, etc.)
fun_2D_head() #### head of the left or right of big 2D objects
......@@ -18,12 +18,12 @@ fun_list_comp() #### comparison of two lists
## Object modification
fun_name_change() #### check a vector of character strings and modify any string if present in another vector
fun_dataframe_remodeling() #### remodeling a data frame to have column name as a qualitative column and vice-versa
fun_dataframe_remodeling() #### remodeling a data frame to have column name as a qualitative values and vice-versa
fun_refactorization() #### remove classes that are not anymore present in factors or factor columns in data frames
fun_round() #### Rounding number if decimal present
fun_round() #### rounding number if decimal present
fun_90clock_matrix_rot() #### 90° clockwise matrix rotation
fun_num2color_mat() #### Conversion of a numeric matrix into hexadecimal color matrix
fun_by_case_matrix_op() #### assembling of several matrices with operation
fun_num2color_mat() #### convert a numeric matrix into hexadecimal color matrix
fun_by_case_matrix_op() #### assemble several matrices with operation
fun_mat_inv() #### return the inverse of a square matrix
fun_mat_fill() #### fill the empty half part of a symmetric square matrix
fun_consec_pos_perm() #### progressively breaks a vector order
......@@ -33,9 +33,10 @@ fun_consec_pos_perm() #### progressively breaks a vector order
fun_window_width_resizing() #### window width depending on classes to plot
fun_open_window() #### open a GUI or pdf graphic window
fun_prior_plot() #### graph param before plotting
fun_post_plot() #### graph param after plotting
fun_close_specif_window() #### closing specific graphic windows
fun_prior_plot() #### set graph param before plotting
fun_scale() #### select nice numbers when setting breaks on an axis
fun_post_plot() #### set graph param after plotting
fun_close_specif_window() #### close specific graphic windows
## Standard graphics
......@@ -49,6 +50,11 @@ fun_gg_palette() #### ggplot2 default color palette
fun_gg_just() #### ggplot2 justification of the axis labeling, depending on angle
fun_gg_scatter() #### ggplot2 scatterplot + lines (up to 6 overlays totally)
fun_gg_bar_mean() #### ggplot2 mean barplot + overlaid dots if required
fun_gg_boxplot() #### ggplot2 boxplot + background dots if required
fun_gg_bar_prop() #### ggplot2 proportion barplot
fun_gg_strip() #### ggplot2 stripchart + mean/median
fun_gg_violin() #### ggplot2 violins
fun_gg_line() #### ggplot2 lines + background dots and error bars
fun_gg_heatmap() #### ggplot2 heatmap + overlaid mask if required
fun_gg_empty_graph() #### text to display for empty graphs
......@@ -71,6 +77,7 @@ fun_export_data() #### print string or data object into output file
#### LICENCE
This package of scripts can be redistributed and/or modified under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
......@@ -78,11 +85,15 @@ Distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; withou
See the GNU General Public License for more details at https://www.gnu.org/licenses.
#### CREDITS
Gael A. Millot, Hub-C3BI, Institut Pasteur, USR 3756 IP CNRS, Paris, France
#### HOW TO USE IT
Download the desired Tagged version, never the current master.
......@@ -96,6 +107,8 @@ Description of the functions is at the beginning of the function body. To obtain
Or in the R/RStudio console, type the name of the function without brackets. Example : fun_object_info.
#### FILE DESCRIPTIONS
cute_little_R_functions.R file that has to be sourced
......@@ -103,11 +116,15 @@ cute_little_R_functions.docx just for easier code reading
examples_alone.txt compile all the examples of the functions into a single file
#### WEB LOCATION
Check for updated versions (most recent tags) at https://gitlab.pasteur.fr/gmillot/cute_little_functions/tags
#### WHAT'S NEW IN
......
......@@ -20,8 +20,8 @@
 
 
################ Object analysis 2
######## fun_param_check() #### Checking class, type, length, etc. of objects 2
######## fun_object_info() #### Recovering object information 8
######## fun_param_check() #### check class, type, length, etc., of objects 2
######## fun_object_info() #### recover object information 8
######## fun_1D_comp() #### comparison of two 1D datasets (vectors, factors, 1D tables) 9
######## fun_2D_comp() #### comparison of two 2D datasets (row & col names, dimensions, etc.) 13
######## fun_2D_head() #### head of the left or right of big 2D objects 20
......@@ -31,42 +31,42 @@
######## fun_name_change() #### check a vector of character strings and modify any string if present in another vector 24
######## fun_dataframe_remodeling() #### remodeling a data frame to have column name as a qualitative values and vice-versa 26
######## fun_refactorization() #### remove classes that are not anymore present in factors or factor columns in data frames 29
######## fun_round() #### Rounding number if decimal present 31
######## fun_round() #### rounding number if decimal present 31
######## fun_90clock_matrix_rot() #### 90 clockwise matrix rotation 32
######## fun_num2color_mat() #### Conversion of a numeric matrix into hexadecimal color matrix 33
######## fun_by_case_matrix_op() #### assembling of several matrices with operation 36
######## fun_num2color_mat() #### convert a numeric matrix into hexadecimal color matrix 33
######## fun_by_case_matrix_op() #### assemble several matrices with operation 36
######## fun_mat_inv() #### return the inverse of a square matrix 38
######## fun_mat_fill() #### fill the empty half part of a symmetric square matrix 40
######## fun_consec_pos_perm() #### progressively breaks a vector order 43
################ Graphics management 48
######## fun_window_width_resizing() #### window width depending on classes to plot 48
######## fun_open_window() #### Open a GUI or pdf graphic window 49
######## fun_prior_plot() #### Graph param before plotting 53
######## fun_scale() #### Rescale axes 57
######## fun_post_plot() #### Graph param after plotting 58
######## fun_close_specif_window() #### Closing specific graphic windows 69
######## fun_open_window() #### open a GUI or pdf graphic window 49
######## fun_prior_plot() #### set graph param before plotting 53
######## fun_scale() #### select nice numbers when setting breaks on an axis 57
######## fun_post_plot() #### set graph param after plotting 59
######## fun_close_specif_window() #### close specific graphic windows 70
################ Standard graphics 71
######## fun_empty_graph() #### text to display for empty graphs 71
################ gg graphics 72
######## fun_gg_palette() #### ggplot2 default color palette 72
######## fun_gg_just() #### ggplot2 justification of the axis labeling, depending on angle 73
######## fun_gg_just() #### ggplot2 justification of the axis labeling, depending on angle 74
######## fun_gg_scatter() #### ggplot2 scatterplot + lines (up to 6 overlays totally) 76
######## fun_gg_bar_mean() #### ggplot2 mean barplot + overlaid dots if required 97
######## fun_gg_boxplot() #### ggplot2 boxplot + background dots if required 125
######## fun_gg_bar_prop() #### ggplot2 proportion barplot 130
######## fun_gg_boxplot() #### ggplot2 boxplot + background dots if required 126
######## fun_gg_bar_prop() #### ggplot2 proportion barplot 131
######## fun_gg_strip() #### ggplot2 stripchart + mean/median 131
######## fun_gg_violin() #### ggplot2 violins 131
######## fun_gg_line() #### ggplot2 lines + background dots and error bars 131
######## fun_gg_heatmap() #### ggplot2 heatmap + overlaid mask if required 131
######## fun_gg_empty_graph() #### text to display for empty graphs 136
################ Graphic extraction 137
######## fun_var_trim_display() #### Display values from a quantitative variable and trim according to defined cut-offs 137
######## fun_segmentation() #### Segment a dot cloud on a scatterplot and define the dots from another cloud outside the segmentation 146
################ Import 176
######## fun_pack_import() #### Check if R packages are present and import into the working environment 176
######## fun_python_pack_import() #### Check if python packages are present 177
################ Exporting results (text & tables) 179
######## fun_export_data() #### Print string or data object into output file 179
######## fun_gg_heatmap() #### ggplot2 heatmap + overlaid mask if required 159
######## fun_gg_empty_graph() #### text to display for empty graphs 164
################ Graphic extraction 166
######## fun_var_trim_display() #### display values from a quantitative variable and trim according to defined cut-offs 166
######## fun_segmentation() #### segment a dot cloud on a scatterplot and define the dots from another cloud outside the segmentation 174
################ Import 204
######## fun_pack_import() #### check if R packages are present and import into the working environment 204
######## fun_python_pack_import() #### check if python packages are present 206
################ Exporting results (text & tables) 207
######## fun_export_data() #### print string or data object into output file 207
 
 
################################ FUNCTIONS ################################
......@@ -75,7 +75,7 @@
################ Object analysis
 
 
######## fun_param_check() #### Checking class, type, length, etc. of objects
######## fun_param_check() #### check class, type, length, etc., of objects
 
 
# Check OK: clear to go Apollo
......@@ -328,7 +328,7 @@ return(output)
}
 
 
######## fun_object_info() #### Recovering object information
######## fun_object_info() #### recover object information
 
 
# Check OK: clear to go Apollo
......@@ -1488,7 +1488,7 @@ return(output)
}
 
 
######## fun_round() #### Rounding number if decimal present
######## fun_round() #### rounding number if decimal present
 
 
# Check OK: clear to go Apollo
......@@ -1616,7 +1616,7 @@ return(data)
}
 
 
######## fun_num2color_mat() #### Conversion of a numeric matrix into hexadecimal color matrix
######## fun_num2color_mat() #### convert a numeric matrix into hexadecimal color matrix
 
 
# Check OK: clear to go Apollo
......@@ -1743,7 +1743,7 @@ return(output)
}
 
 
######## fun_by_case_matrix_op() #### assembling of several matrices with operation
######## fun_by_case_matrix_op() #### assemble several matrices with operation
 
 
# Check OK: clear to go Apollo
......@@ -2325,7 +2325,7 @@ return(window.width)
}
 
 
######## fun_open_window() #### Open a GUI or pdf graphic window
######## fun_open_window() #### open a GUI or pdf graphic window
 
 
# Check OK: clear to go Apollo
......@@ -2469,7 +2469,7 @@ return(output)
}
 
 
######## fun_prior_plot() #### Graph param before plotting
######## fun_prior_plot() #### set graph param before plotting
 
 
# Check OK: clear to go Apollo
......@@ -2633,18 +2633,21 @@ return(tempo.par)
# Check OK: clear to go Apollo
fun_scale <- function(lim, n){
# AIM
# select nice numbers when setting n breaks on a lim axis range
# select nice numbers when setting n breaks on a lim axis range
# WARNINGS
# increase n if the generate scale if not satisfying
# ARGUMENTS
# lim: vector of 2 numbers indicating the limit range of the axis
# n: desired number of breaks on the axis
# n: desired number of breaks on the axis (integer more than 0)
# REQUIRED FUNCTIONS FROM CUTE_LITTLE_R_FUNCTION
# fun_param_check()
# RETURN
# a vector of numbers
# EXAMPLES
# scale <- fun_scale(lim = c(8, 20), n = 4) ; scale ; par(yaxt = "n", yaxs = "i") ; plot(8:20, 8:20) ; axis(side = 2, at = scale)
# ymin = 2; ymax = 3.101; n = 10; scale <- fun_scale(lim = c(ymin, ymax), n = n) ; scale ; par(yaxt = "n", yaxs = "i", las = 1) ; plot(ymin:ymax, ymin:ymax, xlab = "DEFAULT SCALE", ylab = "NEW SCALE") ; par(yaxt = "s") ; axis(side = 2, at = scale)
# DEBUGGING
# lim = c(20, 9) ; n = 4 # for function debugging
# lim = c(2, 3.366081) ; n = 4 # for function debugging
# lim = c(2, 3.101) ; n = 9 # for function debugging
# function name
function.name <- paste0(as.list(match.call(expand.dots=FALSE))[[1]], "()")
# end function name
......@@ -2660,6 +2663,10 @@ checked.arg.names <- NULL # for function debbuging: used by r_debugging_tools
ee <- expression(arg.check <- c(arg.check, tempo$problem) , checked.arg.names <- c(checked.arg.names, tempo$param.name))
tempo <- fun_param_check(data = lim, class = "vector", mode = "numeric", length = 2, fun.name = function.name) ; eval(ee)
tempo <- fun_param_check(data = n, class = "vector", typeof = "integer", length = 1, double.as.integer.allowed = TRUE, neg.values = FALSE, fun.name = function.name) ; eval(ee)
if(tempo$problem == FALSE & n == 0){
tempo.cat <- paste0("\n\n================\n\nERROR IN ", function.name, ": n ARGUMENT MUST BE A NON NULL AND POSITIVE INTEGER\n\n================\n\n")
stop(tempo.cat) #
}
if(any(arg.check) == TRUE){
stop() # nothing else because print = TRUE by default in fun_param_check()
}
......@@ -2670,12 +2677,16 @@ stop() # nothing else because print = TRUE by default in fun_param_check()
tempo.range <- diff(sort(lim))
tempo.max <- max(lim)
tempo.min <- min(lim)
mid <- tempo.min + (tempo.range/2) # middle of axis
tempo.inter <- tempo.range / (n + 1) # current interval between two ticks, between 0 and Inf
# if tempo.inter = zero -> error
if(tempo.inter == 0){
tempo.cat <- (paste0("\n\n============\n\nERROR IN ", function.name, ": THE INTERVAL BETWEEN TWO TICKS OF THE SCALE IS NULL. MODIFY THE lim OR n ARGUMENT\n\n============\n\n"))
stop(tempo.cat)
}
log10.abs.lim <- 200
log10.range <- (-log10.abs.lim):log10.abs.lim
log10.vec <- 10^log10.range
round.vec <- c(5, 2.5, 2, 1.25, 1)
round.vec <- c(5, 4, 3, 2.5, 2, 1.25, 1)
dec.table <- outer(log10.vec, round.vec) # table containing the scale units (row: power of ten from -201 to +199, column: the 5, 2.5, 2, 1.25, 1 notches
 
......@@ -2688,30 +2699,77 @@ power10.exp <- as.integer(substring(text = tempo.inter, first = (regexpr(pattern
mantisse <- as.numeric(substr(x = tempo.inter, start = 1, stop = (regexpr(pattern = "\\+", text = tempo.inter) - 2))) # recover the mantisse. Example recover 1.22 from 1.22e+08
 
}else if(any(grepl(pattern = "\\-", x = tempo.inter))){ # tempo.inter < 1
power10.exp <- as.integer(substring(text = tempo.inter, first = (regexpr(pattern = "\\-", text = tempo.inter) + 1))) # recover the power of 10. Example recover 08 from 1e+08
power10.exp <- as.integer(substring(text = tempo.inter, first = (regexpr(pattern = "\\-", text = tempo.inter)))) # recover the power of 10. Example recover 08 from 1e+08
mantisse <- as.numeric(substr(x = tempo.inter, start = 1, stop = (regexpr(pattern = "\\-", text = tempo.inter) - 2))) # recover the mantisse. Example recover 1.22 from 1.22e+08
}else{
# code incons
tempo.cat <- (paste0("\n\n============\n\nERROR IN ", function.name, ": CODE INCONSISTENCY 1\n\n============\n\n"))
stop(tempo.cat)
}
tempo.scale <- dec.table[log10.range == power10.exp, ]
select <- NULL
# new interval
inter.select <- NULL
for(i1 in 1:length(tempo.scale)){
tempo.first.tick <- ceiling(tempo.min) + round.vec[i1] * 10^power10.exp
if((tempo.first.tick >= tempo.min) & tempo.first.tick + (trunc(tempo.inter) + (round.vec[i1] * 10^power10.exp)) * (n - 1) <= tempo.max){
select <- round.vec[i1]
tempo.first.tick <- trunc((tempo.min + tempo.scale[i1]) / tempo.scale[i1]) * (tempo.scale[i1]) # this would be use to have a number not multiple of tempo.scale[i1]: ceiling(tempo.min) + tempo.scale[i1] * 10^power10.exp
tempo.last.tick <- tempo.first.tick + tempo.scale[i1] * (n - 1)
if((tempo.first.tick >= tempo.min) & (tempo.last.tick <= tempo.max)){
inter.select <- tempo.scale[i1]
break()
}
}
if(is.null(select)){
# code incons
if(is.null(inter.select)){
tempo.cat <- (paste0("\n\n============\n\nERROR IN ", function.name, ": CODE INCONSISTENCY 2\n\n============\n\n"))
stop(tempo.cat)
}
options(scipen = ini.scipen) # restore the initial scientific penalty
# end new interval
# centering the new scale
tempo.mid <- trunc((mid + (-1:1) * inter.select) / inter.select) * inter.select # tempo middle tick closest to the middle axis
mid.tick <- tempo.mid[which.min(abs(tempo.mid - mid))]
if(n == 1){
output <- mid.tick
}else if(n == 2){
tempo.min.dist <- mid.tick - inter.select - tempo.min
tempo.max.dist <- tempo.max - mid.tick + inter.select
if(tempo.min.dist <= tempo.max.dist){ # distance between lowest tick and bottom axis <= distance between highest tick and top axis. If yes, extra tick but at the top, otherwise at the bottom
output <- c(mid.tick, mid.tick + inter.select)
}else{
output <- c(mid.tick - inter.select, mid.tick)
}
}else if((n / 2 - trunc(n / 2)) > 0.1){ # > 0.1 to avoid floating point. Because result can only be 0 or 0.5. Thus, > 0.1 means odd number
output <- c(mid.tick - (trunc(n / 2):1) * inter.select, mid.tick, mid.tick + (1:trunc(n / 2)) * inter.select)
}else if((n / 2 - trunc(n / 2)) < 0.1){ # < 0.1 to avoid floating point. Because result can only be 0 or 0.5. Thus, < 0.1 means even number
tempo.min.dist <- mid.tick - trunc(n / 2) * inter.select - tempo.min
tempo.max.dist <- tempo.max - mid.tick + trunc(n / 2) * inter.select
if(tempo.min.dist <= tempo.max.dist){ # distance between lowest tick and bottom axis <= distance between highest tick and top axis. If yes, extra tick but at the bottom, otherwise at the top
output <- c(mid.tick - ((trunc(n / 2) - 1):1) * inter.select, mid.tick, mid.tick + (1:trunc(n / 2)) * inter.select)
}else{
output <- c(mid.tick - (trunc(n / 2):1) * inter.select, mid.tick, mid.tick + (1:(trunc(n / 2) - 1)) * inter.select)
}
}else{
tempo.cat <- (paste0("\n\n============\n\nERROR IN ", function.name, ": CODE INCONSISTENCY 3\n\n============\n\n"))
stop(tempo.cat)
}
# end centering the new scale
# last check
if(min(output) < tempo.min){
output <- c(output[-1], max(output) + inter.select) # remove the lowest tick and add a tick at the top
}else if( max(output) > tempo.max){
output <- c(min(output) - inter.select, output[-length(output)])
}
if(min(output) < tempo.min | max(output) > tempo.max){
tempo.cat <- (paste0("\n\n============\n\nERROR IN ", function.name, ": CODE INCONSISTENCY 4\n\n============\n\n"))
stop(tempo.cat)
}
if(any(is.na(output))){
tempo.cat <- (paste0("\n\n============\n\nERROR IN ", function.name, ": CODE INCONSISTENCY 5 (NA GENERATION)\n\n============\n\n"))
stop(tempo.cat)
}
options(scipen = ini.scipen)
output <- ceiling(tempo.min) + (trunc(tempo.inter) + (round.vec[i1] * 10^power10.exp)) * (0:(n - 1))
# end last check
return(output)
}
 
 
######## fun_post_plot() #### Graph param after plotting
######## fun_post_plot() #### set graph param after plotting
 
 
# Check OK: clear to go Apollo
......@@ -3065,7 +3123,7 @@ return(output)
}
 
 
######## fun_close_specif_window() #### Closing specific graphic windows
######## fun_close_specif_window() #### close specific graphic windows
 
 
# Check OK: clear to go Apollo
......@@ -4062,7 +4120,7 @@ fun_gg_bar_mean <- function(data1, y, categ, categ.class.order = NULL, categ.leg
# 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)
# y.break.nb: number of desired values on the y-axis
# y.break.nb: number of desired values on the y-axis (n argument of the the fun_scale() function)
# y.include.zero: logical. Does ylim range include 0? Beware: if ylog = TRUE, will be automately set to FALSE with a warning message
# y.top.extra.margin: single proportion (between 0 and 1) indicating if extra margins must be added to ylim. If different from 0, add the range of the axis * y.top.extra.margin (e.g., abs(ylim[2] - ylim[1]) * y.top.extra.margin) to the top of y-axis. Beware with ylog = TRUE, the range result must not overlap zero or negative values
# y.bottom.extra.margin: idem as y.top.extra.margin but to the bottom of y-axis
......@@ -4082,20 +4140,22 @@ fun_gg_bar_mean <- function(data1, y, categ, categ.class.order = NULL, categ.leg
# REQUIRED PACKAGES
# ggplot2
# REQUIRED FUNCTIONS FROM CUTE_LITTLE_R_FUNCTION
# fun_param_check()
# fun_pack_import()
# fun_gg_palette()
# fun_gg_just()
# fun_round()
# fun_2D_comp()
# fun_gg_just()
# fun_gg_palette()
# fun_name_change()
# fun_pack_import()
# fun_param_check()
# fun_round()
# fun_scale()
# RETURN
# a barplot
# a list of the graph info if return argument is TRUE:
# $stat: the graphic statistics
# $removed.row.nb: which rows have been removed due to NA detection in y and categ columns (NULL if no row removed)
# $removed.rows: removed rows containing NA (NULL if no row removed)
# $data: the graphic info coordinates
# $data: the graphic bar and dot coordinates
# $ylim: the y-axis limits
# $warnings: the warning messages. Use cat() for proper display. NULL if no warning
# EXAMPLES
# nice representation (1)
......@@ -4190,28 +4250,36 @@ fun_gg_bar_mean <- function(data1, y, categ, categ.class.order = NULL, categ.leg
function.name <- paste0(as.list(match.call(expand.dots=FALSE))[[1]], "()")
# end function name
# required function checking
if(length(find("fun_param_check", mode = "function")) == 0){
tempo.cat <- paste0("\n\n================\n\nERROR IN ", function.name, ": REQUIRED fun_param_check() FUNCTION IS MISSING IN THE R ENVIRONMENT\n\n================\n\n")
if(length(find("fun_2D_comp", mode = "function")) == 0){
tempo.cat <- paste0("\n\n================\n\nERROR IN ", function.name, ": REQUIRED fun_2D_comp() FUNCTION IS MISSING IN THE R ENVIRONMENT\n\n================\n\n")
stop(tempo.cat)
}
if(length(find("fun_pack_import", mode = "function")) == 0){
tempo.cat <- paste0("\n\n================\n\nERROR IN ", function.name, ": REQUIRED fun_pack_import() FUNCTION IS MISSING IN THE R ENVIRONMENT\n\n================\n\n")
if(length(find("fun_gg_just", mode = "function")) == 0){
tempo.cat <- paste0("\n\n================\n\nERROR IN ", function.name, ": REQUIRED fun_gg_just() FUNCTION IS MISSING IN THE R ENVIRONMENT\n\n================\n\n")
stop(tempo.cat)
}
if(length(find("fun_gg_palette", mode = "function")) == 0){
tempo.cat <- paste0("\n\n================\n\nERROR IN ", function.name, ": REQUIRED fun_gg_palette() FUNCTION IS MISSING IN THE R ENVIRONMENT\n\n================\n\n")
stop(tempo.cat)
}
if(length(find("fun_round", mode = "function")) == 0){
tempo.cat <- paste0("\n\n================\n\nERROR IN ", function.name, ": REQUIRED fun_round() FUNCTION IS MISSING IN THE R ENVIRONMENT\n\n================\n\n")
if(length(find("fun_name_change", mode = "function")) == 0){
tempo.cat <- paste0("\n\n================\n\nERROR IN ", function.name, ": REQUIRED fun_name_change() FUNCTION IS MISSING IN THE R ENVIRONMENT\n\n================\n\n")
stop(tempo.cat)
}
if(length(find("fun_2D_comp", mode = "function")) == 0){
tempo.cat <- paste0("\n\n================\n\nERROR IN ", function.name, ": REQUIRED fun_2D_comp() FUNCTION IS MISSING IN THE R ENVIRONMENT\n\n================\n\n")
if(length(find("fun_pack_import", mode = "function")) == 0){
tempo.cat <- paste0("\n\n================\n\nERROR IN ", function.name, ": REQUIRED fun_pack_import() FUNCTION IS MISSING IN THE R ENVIRONMENT\n\n================\n\n")
stop(tempo.cat)
}
if(length(find("fun_2D_comp", mode = "function")) == 0){
tempo.cat <- paste0("\n\n================\n\nERROR IN ", function.name, ": REQUIRED fun_name_change() FUNCTION IS MISSING IN THE R ENVIRONMENT\n\n================\n\n")
if(length(find("fun_param_check", mode = "function")) == 0){
tempo.cat <- paste0("\n\n================\n\nERROR IN ", function.name, ": REQUIRED fun_param_check() FUNCTION IS MISSING IN THE R ENVIRONMENT\n\n================\n\n")
stop(tempo.cat)
}
if(length(find("fun_round", mode = "function")) == 0){
tempo.cat <- paste0("\n\n================\n\nERROR IN ", function.name, ": REQUIRED fun_round() FUNCTION IS MISSING IN THE R ENVIRONMENT\n\n================\n\n")
stop(tempo.cat)
}
if(length(find("fun_scale", mode = "function")) == 0){
tempo.cat <- paste0("\n\n================\n\nERROR IN ", function.name, ": REQUIRED fun_scale() FUNCTION IS MISSING IN THE R ENVIRONMENT\n\n================\n\n")
stop(tempo.cat)
}
# end required function checking
......@@ -4893,12 +4961,12 @@ stop(tempo.cat)
if(ylog == TRUE){
assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::annotation_logticks(sides = "l")) # string containing any of "trbl", for top, right, bottom, and left
if( ! is.null(y.break.nb)){
assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::scale_y_continuous(breaks = fun_round(seq(ylim[1], ylim[2], length.out = y.break.nb), dec.nb = 2, after.lead.zero = TRUE)))
assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::scale_y_continuous(breaks = fun_scale(lim = ylim, n = y.break.nb)))
}
}else{
if( ! is.null(y.break.nb)){
assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::scale_y_continuous(
breaks = fun_round(seq(ylim[1], ylim[2], length.out = y.break.nb), dec.nb = 2, after.lead.zero = TRUE),
breaks = fun_scale(lim = ylim, n = y.break.nb),
expand = c(0, 0),
limits = NA
))
......@@ -4919,7 +4987,7 @@ suppressWarnings(print(eval(parse(text = paste(paste0(tempo.gg.name, 1:tempo.gg.
# end barplot
if(return == TRUE){
output <- ggplot2::ggplot_build(eval(parse(text = paste(paste0(tempo.gg.name, 1:tempo.gg.count), collapse = " + "))))
output <- list(stat = stat, removed.row.nb = removed.row.nb, removed.rows = removed.rows, data = output$data, warnings = paste0("\n", warning, "\n\n"))
output <- list(stat = stat, removed.row.nb = removed.row.nb, removed.rows = removed.rows, data = output$data, ylim = ylim, warnings = paste0("\n", warning, "\n\n"))
return(output)
}
}
......@@ -5038,6 +5106,902 @@ fun_gg_boxplot <- function(data1, y, categ, class.order = NULL, legend.name = NU
######## fun_gg_line() #### ggplot2 lines + background dots and error bars
 
 
# DO NOT ERASE. COMPARE WITH BAR MEAN BEFORE AND RECOVER WHAT HAS BEEN MODIFIED
fun_gg_line <- function(data1, y, categ, categ.class.order = NULL, categ.legend.name = NULL, categ.color = NULL, line.size = 1, error.disp = NULL, error.whisker.width = 0.5, dot.color = "same", dot.tidy = FALSE, dot.bin.nb = 30, dot.jitter = 0.25, dot.size = 3, dot.border.size = 0.5, dot.alpha = 0.5, ylim = NULL, ylog = FALSE, y.break.nb = NULL, y.include.zero = FALSE, y.top.extra.margin = 0.05, y.bottom.extra.margin = 0, stat.disp = NULL, stat.size = 4, stat.dist = 2, xlab = NULL, ylab = NULL, vertical = TRUE, title = "", text.size = 12, text.angle = 0, classic = FALSE, grid = FALSE, return = FALSE, path.lib = NULL){
# AIM
# ggplot2 vertical barplot representing mean values with the possibility to add error bars and to overlay dots
# for ggplot2 specifications, see: https://ggplot2.tidyverse.org/articles/ggplot2-specs.html
# WARNINGS
# rows containing NA in data1[, c(y, categ)] will be removed before processing, with a warning (see below)
# if ever bars disappear, see the end of https://github.com/tidyverse/ggplot2/issues/2887
# to have a single bar, create a factor column with a single class and specify the name of this column in categ argument as unique element (no categ2 in categ argument). For a single set of grouped bars, create a factor column with a single class and specify this column in categ argument as first element (categ1). See categ below
# with several single bars (categ argument with only one element), bar.width argument (i.e., width argument of ggplot2::geom_bar()) defines each bar width. The bar.width argument also defines the space between bars by using (1 - bar.width). In addition, xmin and xmax of the fun_gg_bar_mean() output report the bar boundaries (around x-axis unit 1, 2, 3, etc., for each bar)
# with several sets of grouped bars (categ argument with two elements), bar.width argument defines each set of grouped bar width. The bar.width argument also defines the space between set of grouped bars by using (1 - bar.width). In addition, xmin and xmax of the fun_gg_bar_mean() output report the bar boundaries (around x-axis unit 1, 2, 3, etc., for each set of grouped bar)
# to manually change the 0 base bar into this code, see https://stackoverflow.com/questions/35324892/ggplot2-setting-geom-bar-baseline-to-1-instead-of-zero
# ARGUMENTS
# data1: a dataframe containing one column of values (see y argument below) and one or two columns of categories (see categ argument below). Duplicated column names not allowed
# y: character string of the data1 column name for y-axis (containing numeric values). Numeric values will be averaged by categ to generate the bars and will also be used to plot the dots
# categ: vector of character strings of the data1 column name for categories (column of characters or factor). Must either be one or two column names. If a single column name (further refered to as categ1), then one bar per class of categ1. If two column names (further refered to as categ1 and categ2), then one bar per class of categ2, which form a group of bars in each class of categ1. Beware, categ1 (and categ2 if it exists) must have a single value of y per class of categ1 (and categ2). To have a single bar, create a factor column with a single class and specify the name of this column in categ argument as unique element (no categ2 in categ argument). For a single set of grouped bars, create a factor column with a single class and specify this column in categ argument as first element (categ1)
# categ.class.order: list indicating the order of the classes of categ1 and categ2 represented on the barplot (the first compartment for categ1 and and the second for categ2). If categ.class.order = NULL, classes are represented according to the alphabetical order. Some compartment can be NULL and other not
# categ.legend.name: character string of the legend title for categ2. If categ.legend.name = NULL, then categ.legend.name <- categ1 if only categ1 is present and categ.legend.name <- categ2 if categ1 and categ2 are present. Write "" if no legend required
# categ.color: vector of character color string for bar filling. If categ.color = NULL, default colors of ggplot2, whatever categ1 and categ2. If categ.color is non null and only categ1 in categ argument, categ.color can be either: (1) a single color string (all the bars will have this color, whatever the classes of categ1), (2) a vector of string colors, one for each class of categ1 (each color will be associated according to categ.class.order of categ1), (3) a vector or factor of string colors, like if it was one of the column of data1 data frame (beware: a single color per class of categ1 and a single class of categ1 per color must be respected). Integers are also accepted instead of character strings, as long as above rules about length are respected. Integers will be processed by fun_gg_palette() using the max integer value among all the integers in categ.color. If categ.color is non null and categ1 and categ2 specified, all the rules described above will apply to categ2 instead of categ1 (colors will be determined for bars inside a group of bars)
# bar.width: numeric value (from 0 to 1) of the bar or set of grouped bar width (see warnings above)
# error.disp: either "SD", "SD.TOP", "SEM" or "SEM.TOP". If NULL, no error bars added
# error.whisker.width: numeric value (from 0 to 1) of the whisker (error bar extremities) width, with 0 meaning no whiskers and 1 meaning a width equal to the corresponding bar width
# dot.color: vector of character string. Idem as categ.color but for dots, except that in the possibility (3), the rule "a single color per class of categ1 and a single class of categ1", cannot be respected (each dot can have a different color). If NULL, no dots plotted
# dot.tidy: logical. Nice dot spreading? If TRUE, use the geom_dotplot() function for a nice representation. If FALSE, dots are randomly spread, using the dot.jitter argument (see below)
# 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 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)
# y.break.nb: number of desired values on the y-axis
# y.include.zero: logical. Does ylim range include 0? Beware: if ylog = TRUE, will be automately set to FALSE with a warning message
# y.top.extra.margin: single proportion (between 0 and 1) indicating if extra margins must be added to ylim. If different from 0, add the range of the axis * y.top.extra.margin (e.g., abs(ylim[2] - ylim[1]) * y.top.extra.margin) to the top of y-axis. Beware with ylog = TRUE, the range result must not overlap zero or negative values
# y.bottom.extra.margin: idem as y.top.extra.margin but to the bottom of y-axis
# stat.disp: add the mean number above the corresponding bar. Either NULL (no number shown), "top" (at the top of the figure region) or "above" (above each bar)
# stat.size: numeric value of the stat size (in points). Increase the value to increase text size
# stat.dist: numeric value of the stat distance. Increase the value to increase the distance
# xlab: a character string for x-axis legend. If NULL, character string of categ1
# ylab: a character string y-axis legend. If NULL, character string of the y argument
# vertical: logical. Vertical bars? BEWARE: cannot have horizontal bars with a log axis, i.e., ylog = TRUE & vertical = FALSE (see ylog above)
# title: character string of the graph title
# text.size: numeric value of the text size (in points)
# text.angle: integer value of the text angle for the x-axis labels. Positive values for counterclockwise rotation: 0 for horizontal, 90 for vertical, 180 for upside down etc. Negative values for clockwise rotation: 0 for horizontal, -90 for vertical, -180 for upside down etc.
# classic: logical. Use the classic theme (article like)?
# grid: logical. draw horizontal lines in the background to better read the bar values? Not considered if classic = FALSE
# return: logical. Return the graph parameters?
# path.lib: absolute path of the required packages, if not in the default folders
# REQUIRED PACKAGES
# ggplot2
# REQUIRED FUNCTIONS FROM CUTE_LITTLE_R_FUNCTION
# fun_param_check()
# fun_pack_import()
# fun_gg_palette()
# fun_gg_just()
# fun_round()
# fun_2D_comp()
# fun_name_change()
# RETURN
# a barplot
# a list of the graph info if return argument is TRUE:
# $stat: the graphic statistics
# $removed.row.nb: which rows have been removed due to NA detection in y and categ columns (NULL if no row removed)
# $removed.rows: removed rows containing NA (NULL if no row removed)
# $data: the graphic info coordinates
# $warnings: the warning messages. Use cat() for proper display. NULL if no warning
# EXAMPLES
# nice representation (1)
# obs1 <- data.frame(Time = 1:20, Group1 = rep(c("G", "H"), times = 10), Group2 = rep(c("A", "B"), each = 10)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), categ.class.order = list(NULL, c("B", "A")), categ.legend.name = "LEGEND", categ.color = NULL, bar.width = 0.3, error.disp = "SD.TOP", error.whisker.width = 0.8, dot.color = "same", dot.jitter = 0.5, dot.size = 3.5, dot.border.size = 0.2, dot.alpha = 0.5, ylim = c(10, 25), y.include.zero = TRUE, stat.disp = "above", stat.size = 4, xlab = "GROUP", ylab = "MEAN", title = "GRAPH1", text.size = 20, text.angle = 0, classic = TRUE, grid = TRUE, return = TRUE)
# nice representation (2)
# set.seed(1) ; obs1 <- data.frame(Time = c(rnorm(24, 0), rnorm(24, -10), rnorm(24, 10), rnorm(24, 20)), Group1 = rep(c("CAT", "DOG"), times = 48), Group2 = rep(c("A", "B", "C", "D"), each = 24)) ; set.seed(NULL) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), categ.class.order = list(NULL, c("B", "A", "D", "C")), categ.legend.name = "LEGEND", categ.color = NULL, bar.width = 0.8, dot.color = "same", dot.tidy = TRUE, dot.bin.nb = 60, dot.size = 3.5, dot.border.size = 0.2, dot.alpha = 1, ylim= c(-20, 25), stat.disp = "above", stat.size = 4, stat.dist = 1, xlab = "GROUP", ylab = "MEAN", vertical = FALSE, title = "GRAPH1", text.size = 20, text.angle = 45, classic = FALSE, return = TRUE)
# simple example
# obs1 <- data.frame(Time = 1:20, Group1 = rep(c("G", "H"), times = 10), Group2 = rep(c("A", "B"), each = 10)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = "Group1")
# separate bars: example (1) of modification of bar color using a single value
# obs1 <- data.frame(Time = 1:20, Group1 = rep(c("G", "H"), times = 10)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = "Group1", categ.color = "white")
# separate bars: example (2) of modification of bar color using one value par class of categ2
# obs1 <- data.frame(Time = 1:20, Group1 = rep(c("G", "H"), times = 10)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = "Group1", categ.color = c("coral", "lightblue"))
# separate bars: example (3) of modification of bar color using the bar.color data frame column, with respect of the correspondence between categ2 and bar.color columns
# obs1 <- data.frame(Time = 1:20, Group1 = rep(c("G", "H"), times = 10), bar.color = rep(c("coral", "lightblue"), time = 10)) ; obs1 ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = "Group1", categ.color = obs1$bar.color)
# separate bars: example (1) of modification of dot color, using the same dot color as the corresponding bar
# obs1 <- data.frame(Time = 1:20, Group1 = rep(c("G", "H"), times = 10)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = "Group1", dot.color = "same")
# separate bars: example (2) of modification of dot color, using a single color for all the dots
# obs1 <- data.frame(Time = 1:20, Group1 = rep(c("G", "H"), times = 10)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = "Group1", dot.color = "green")
# separate bars: example (3) of modification of dot color, using one value par class of categ2
# obs1 <- data.frame(Time = 1:20, Group1 = rep(c("G", "H"), times = 10)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = "Group1", dot.color = c("green", "brown"))
# separate bars: example (4) of modification of dot color, using different colors for each dot
# obs1 <- data.frame(Time = 1:10, Group1 = rep(c("G", "H"), times = 5)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = "Group1", dot.color = hsv(h = (1:nrow(obs1)) / nrow(obs1)))
# grouped bars: simple example
# obs1 <- data.frame(Time = 1:20, Group1 = rep(c("G", "H"), times = 10), Group2 = rep(c("A", "B"), each = 10)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"))
# grouped bars: more grouped bars
# obs1 <- data.frame(Time = 1:24, Group1 = rep(c("G", "H"), times = 12), Group2 = rep(c("A", "B", "C", "D"), each = 6)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"))
# grouped bars: example (1) of modification of bar color (1), using a single value
# obs1 <- data.frame(Time = 1:20, Group1 = rep(c("G", "H"), times = 10), Group2 = rep(c("A", "B"), each = 10)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), categ.color = "white")
# grouped bars: example (2) of modification of bar color (2), using one value par class of categ2
# obs1 <- data.frame(Time = 1:20, Group1 = rep(c("G", "H"), times = 10), Group2 = rep(c("A", "B"), each = 10)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), categ.color = c("coral", "lightblue"))
# grouped bars: example (3) of modification of bar color (3), using one value per line of obs1, with respect of the correspondence between categ2 and bar.color columns
# obs1 <- data.frame(Time = 1:20, Group1 = rep(c("G", "H"), times = 10), Group2 = rep(c("A", "B"), each = 10), bar.color = rep(c("coral", "lightblue"), each = 10)) ; obs1 ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), categ.color = obs1$bar.color)
# grouped bars: example (1) of modification of dot color, using the same dot color as the corresponding bar
# obs1 <- data.frame(Time = 1:20, Group1 = rep(c("G", "H"), times = 10), Group2 = rep(c("A", "B"), each = 10)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), dot.color = "same")
# grouped bars: example (2) of modification of dot color, using a single color for all the dots
# obs1 <- data.frame(Time = 1:20, Group1 = rep(c("G", "H"), times = 10), Group2 = rep(c("A", "B"), each = 10)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), dot.color = "green")
# grouped bars: example (3) of modification of dot color, using one value par class of categ2
# obs1 <- data.frame(Time = 1:20, Group1 = rep(c("G", "H"), times = 10), Group2 = rep(c("A", "B"), each = 10)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), dot.color = c("green", "brown"))
# grouped bars: example (4) of modification of dot color, using different colors for each dot
# obs1 <- data.frame(Time = 1:10, Group1 = rep(c("G", "H"), times = 5), Group2 = rep(c("A", "B"), each = 5)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), dot.color = hsv(h = (1:nrow(obs1)) / nrow(obs1)))
# no dots (y.include.zero set to TRUE to see the lowest bar):
# obs1 <- data.frame(Time = 1:20, Group1 = rep(c("G", "H"), times = 10), Group2 = rep(c("A", "B"), each = 10)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), dot.color = NULL, y.include.zero = TRUE)
# bar width: example (1) with bar.width = 0.25 -> three times more space between single bars than the bar width (y.include.zero set to TRUE to see the lowest bar)
# obs1 <- data.frame(Time = 1:1000, Group1 = rep(c("G", "H"), each = 500)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = "Group1", dot.color = NULL, y.include.zero = TRUE, bar.width = 0.25)
# bar width: example (2) with bar.width = 1, no space between single bars
# obs1 <- data.frame(Time = 1:1000, Group1 = rep(c("G", "H"), each = 500)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = "Group1", dot.color = NULL, y.include.zero = TRUE, bar.width = 1)
# bar width: example (3) with bar.width = 0.25 -> three times more space between sets of grouped bars than the set width
# obs1 <- data.frame(Time = 1:1000, Group1 = rep(c("G", "H"), times = 500), Group2 = rep(LETTERS[1:5], each = 200)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), dot.color = NULL, y.include.zero = TRUE, bar.width = 0.25)
# bar width: example (4) with bar.width = 0 -> no space between sets of grouped bars
# obs1 <- data.frame(Time = 1:1000, Group1 = rep(c("G", "H"), times = 500), Group2 = rep(LETTERS[1:5], each = 200)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), dot.color = NULL, y.include.zero = TRUE, bar.width = 1)
# whisker width: example (1) with error.whisker.width = 1 -> whiskers have the width of the corresponding bar
# obs1 <- data.frame(Time = 1:1000, Group1 = rep(c("G", "H"), times = 500), Group2 = rep(LETTERS[1:5], each = 200)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), dot.color = NULL, error.disp = "SD", error.whisker.width = 1)
# whisker width: example (2) error bars with no whiskers
# obs1 <- data.frame(Time = 1:1000, Group1 = rep(c("G", "H"), times = 500), Group2 = rep(LETTERS[1:5], each = 200)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), dot.color = NULL, error.disp = "SD", error.whisker.width = 0)
# dot jitter: example (1) with dot.jitter = 1 -> dispersion around the corresponding bar width
# obs1 <- data.frame(Time = 1:1000, Group1 = rep(c("G", "H"), times = 500), Group2 = rep(LETTERS[1:5], each = 200)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), dot.color = "grey", dot.size = 3, dot.alpha = 1, dot.jitter = 1)
# dot jitter: example (2) with no dispersion
# obs1 <- data.frame(Time = 1:100, Group1 = rep(c("G", "H"), times = 50), Group2 = rep(LETTERS[1:5], each = 20)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), dot.color = "grey", dot.size = 3, dot.alpha = 1, dot.jitter = 0)
# dot size, dot border size and dot transparency:
# obs1 <- data.frame(Time = 1:100, Group1 = rep(c("G", "H"), times = 50), Group2 = rep(LETTERS[1:5], each = 20)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), dot.color = "grey", dot.size = 4, dot.border.size = 0, dot.alpha = 0.6)
# tidy dot distribution: example (1)
# obs1 <- data.frame(Time = 1:1000, Group1 = rep(c("G", "H"), times = 500), Group2 = rep(LETTERS[1:5], each = 200)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), dot.color = "same", dot.tidy = TRUE, dot.bin.nb = 100)
# tidy dot distribution: example (2) reducing the dot size with dot.bin.nb
# obs1 <- data.frame(Time = 1:1000, Group1 = rep(c("G", "H"), times = 500), Group2 = rep(LETTERS[1:5], each = 200)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), dot.color = "same", dot.tidy = TRUE, dot.bin.nb = 150)
# tidy dot distribution: comparison with random spreading
# obs1 <- data.frame(Time = 1:1000, Group1 = rep(c("G", "H"), times = 500), Group2 = rep(LETTERS[1:5], each = 200)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), dot.color = "same", dot.tidy = FALSE, dot.jitter = 1, dot.size = 2)
# log scale: beware, y column must be log, otherwise incoherent scale
# obs1 <- data.frame(Time = log10((1:20) * 100), Group1 = rep(c("G", "H"), times = 10), Group2 = rep(c("A", "B"), each = 10)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), ylog = TRUE)
# break number: (make nice)
# obs1 <- data.frame(Time = log10((1:20) * 100), Group1 = rep(c("G", "H"), times = 10), Group2 = rep(c("A", "B"), each = 10)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), y.break.nb = 10)
# extra margins for the plot region: to avoid dot cuts
# obs1 <- data.frame(Time = log10((1:20) * 100), Group1 = rep(c("G", "H"), times = 10), Group2 = rep(c("A", "B"), each = 10)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), y.top.extra.margin = 0.25, y.bottom.extra.margin = 0.25)
# mean diplay: example (1) at the top of the plot region
# obs1 <- data.frame(Time = log10((1:20) * 100), Group1 = rep(c("G", "H"), times = 10), Group2 = rep(c("A", "B"), each = 10)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), stat.disp = "top", stat.size = 4, stat.dist = 2)
# mean diplay: example (2) above bars
# obs1 <- data.frame(Time = log10((1:20) * 100), Group1 = rep(c("G", "H"), times = 10), Group2 = rep(c("A", "B"), each = 10)) ; fun_gg_bar_mean(data1 = obs1, y = "Time", categ = c("Group1", "Group2"), stat.disp = "above", stat.size = 4, stat.dist = 2)