Skip to content
Snippets Groups Projects
Commit 18a00dae authored by Gael  MILLOT's avatar Gael MILLOT
Browse files

release v11.10.0: hole.text argument added in gg_donut()

parent fa223a91
No related branches found
No related tags found
No related merge requests found
...@@ -171,6 +171,11 @@ Gitlab developers ...@@ -171,6 +171,11 @@ Gitlab developers
## WHAT'S NEW IN ## WHAT'S NEW IN
### v11.10.0
1) hole.text argument added in gg_donut()
### v11.9.0 ### v11.9.0
1) Argument inf.values added in the check() function 1) Argument inf.values added in the check() function
......
...@@ -9147,6 +9147,7 @@ fun_gg_donut <- function( ...@@ -9147,6 +9147,7 @@ fun_gg_donut <- function(
fill.palette = NULL, fill.palette = NULL,
fill.color = NULL, fill.color = NULL,
hole.size = 0.5, hole.size = 0.5,
hole.text = TRUE,
hole.text.size = 14, hole.text.size = 14,
border.color = "gray50", border.color = "gray50",
border.size = 0.2, border.size = 0.2,
...@@ -9183,7 +9184,8 @@ fun_gg_donut <- function( ...@@ -9183,7 +9184,8 @@ fun_gg_donut <- function(
# fill.palette: single character string of a palette name (see ?ggplot2::scale_fill_brewer() for the list).Ignored if fill.color is not NULL # fill.palette: single character string of a palette name (see ?ggplot2::scale_fill_brewer() for the list).Ignored if fill.color is not NULL
# fill.color: either (1) NULL, or (2) a vector of character strings or integers of same length as the number of classes in categ. Colors can be color names (see ?colors() in R), hexadecimal color codes, or integers (according to the ggplot2 palette). The order of the elements will be used according to the frequency values, from highest to lowest. An easy way to use this argument is to sort data1 according to the frequencies values, add a color column with the corresponding desired colors and use the content of this column as values of fill.color. If color is NULL and fill.palette is NULL, default colors of ggplot2 are used. If color is not NULL, it overrides fill.palette # fill.color: either (1) NULL, or (2) a vector of character strings or integers of same length as the number of classes in categ. Colors can be color names (see ?colors() in R), hexadecimal color codes, or integers (according to the ggplot2 palette). The order of the elements will be used according to the frequency values, from highest to lowest. An easy way to use this argument is to sort data1 according to the frequencies values, add a color column with the corresponding desired colors and use the content of this column as values of fill.color. If color is NULL and fill.palette is NULL, default colors of ggplot2 are used. If color is not NULL, it overrides fill.palette
# hole.size: single positive proportion of donut central hole, 0 meaning no hole and 1 no donut # hole.size: single positive proportion of donut central hole, 0 meaning no hole and 1 no donut
# hole.text.size: single positive numeric value of the title font size in mm # hole.text: logical (either TRUE or FALSE). Display the sum of frequencies (column of data1 indicated in the freq argument) ?
# hole.text.size: single positive numeric value of the title font size in mm. Ignored if hole.text is FALSE
# border.color: a single character string or integer. Colors can be color names (see ?colors() in R), hexadecimal color codes, or integers (according to the ggplot2 palette) # border.color: a single character string or integer. Colors can be color names (see ?colors() in R), hexadecimal color codes, or integers (according to the ggplot2 palette)
# border.size: single numeric value of border tickness in mm. Write zero for no dot border # border.size: single numeric value of border tickness in mm. Write zero for no dot border
# title: single character string of the graph title # title: single character string of the graph title
...@@ -9234,7 +9236,7 @@ fun_gg_donut <- function( ...@@ -9234,7 +9236,7 @@ fun_gg_donut <- function(
# EXAMPLES # EXAMPLES
# obs1 <- data.frame(Km = c(20, 10, 1, 5), Car = c("TUUT", "WIIM", "BIP", "WROUM"), Color1 = 1:4, color2 = c("red", "blue", "green", "black"), Country = c("FR", "UK", "US", NA), stringsAsFactors = TRUE) ; fun_gg_donut(data1 = obs1, freq = "Km", categ = "Car", annotation = "Country") # obs1 <- data.frame(Km = c(20, 10, 1, 5), Car = c("TUUT", "WIIM", "BIP", "WROUM"), Color1 = 1:4, color2 = c("red", "blue", "green", "black"), Country = c("FR", "UK", "US", NA), stringsAsFactors = TRUE) ; fun_gg_donut(data1 = obs1, freq = "Km", categ = "Car", annotation = "Country")
# DEBUGGING # DEBUGGING
# obs1 <- data.frame(Km = c(20, 10, 1, 5), Car = c("TUUT", "WIIM", "BIP", "WROUM"), Color1 = 1:4, color2 = c("red", "blue", "green", "black"), Country = c("FR", "UK", "US", NA), stringsAsFactors = TRUE) ; data1 = obs1 ; freq = "Km" ; categ = "Car" ; fill.palette = NULL ; fill.color = NULL ; hole.size = 0.5 ; hole.text.size = 12 ; border.color = "gray50" ; border.size = 0.1 ; title = "" ; title.text.size = 12 ; annotation = "Country" ; annotation.distance = 0.5 ; annotation.size = 3 ; annotation.force = 1 ; annotation.force.pull = 100 ; legend.show = TRUE ; legend.width = 0.5 ; legend.name = NULL ; legend.limit = NULL ; legend.add.prop = FALSE ; add = NULL ; return = TRUE ; return.ggplot = FALSE ; return.gtable = TRUE ; plot = TRUE ; warn.print = FALSE ; lib.path = NULL # obs1 <- data.frame(Km = c(20, 10, 1, 5), Car = c("TUUT", "WIIM", "BIP", "WROUM"), Color1 = 1:4, color2 = c("red", "blue", "green", "black"), Country = c("FR", "UK", "US", NA), stringsAsFactors = TRUE) ; data1 = obs1 ; freq = "Km" ; categ = "Car" ; fill.palette = NULL ; fill.color = NULL ; hole.size = 0.5 ; hole.text = TRUE ; hole.text.size = 12 ; border.color = "gray50" ; border.size = 0.1 ; title = "" ; title.text.size = 12 ; annotation = "Country" ; annotation.distance = 0.5 ; annotation.size = 3 ; annotation.force = 1 ; annotation.force.pull = 100 ; legend.show = TRUE ; legend.width = 0.5 ; legend.name = NULL ; legend.limit = NULL ; legend.add.prop = FALSE ; add = NULL ; return = TRUE ; return.ggplot = FALSE ; return.gtable = TRUE ; plot = TRUE ; warn.print = FALSE ; lib.path = NULL
# function name # function name
function.name <- paste0(as.list(match.call(expand.dots=FALSE))[[1]], "()") function.name <- paste0(as.list(match.call(expand.dots=FALSE))[[1]], "()")
arg.names <- names(formals(fun = sys.function(sys.parent(n = 2)))) # names of all the arguments arg.names <- names(formals(fun = sys.function(sys.parent(n = 2)))) # names of all the arguments
...@@ -9309,6 +9311,7 @@ fun_gg_donut <- function( ...@@ -9309,6 +9311,7 @@ fun_gg_donut <- function(
} }
} }
tempo <- fun_check(data = hole.size, prop = TRUE, length = 1, fun.name = function.name) ; eval(ee) tempo <- fun_check(data = hole.size, prop = TRUE, length = 1, fun.name = function.name) ; eval(ee)
tempo <- fun_check(data = hole.text, class = "logical", length = 1, fun.name = function.name) ; eval(ee)
tempo <- fun_check(data = hole.text.size, class = "vector", mode = "numeric", neg.values = FALSE, inf.values = FALSE, length = 1, fun.name = function.name) ; eval(ee) tempo <- fun_check(data = hole.text.size, class = "vector", mode = "numeric", neg.values = FALSE, inf.values = FALSE, length = 1, fun.name = function.name) ; eval(ee)
tempo1 <- fun_check(data = border.color, class = "vector", mode = "character", na.contain = FALSE, length = 1, fun.name = function.name) tempo1 <- fun_check(data = border.color, class = "vector", mode = "character", na.contain = FALSE, length = 1, fun.name = function.name)
tempo2 <- fun_check(data = border.color, class = "integer", double.as.integer.allowed = TRUE, neg.values = FALSE, na.contain = FALSE, length = 1, fun.name = function.name) # not need to test inf with integers tempo2 <- fun_check(data = border.color, class = "integer", double.as.integer.allowed = TRUE, neg.values = FALSE, na.contain = FALSE, length = 1, fun.name = function.name) # not need to test inf with integers
...@@ -9396,6 +9399,7 @@ fun_gg_donut <- function( ...@@ -9396,6 +9399,7 @@ fun_gg_donut <- function(
# "fill.palette", # inactivated because can be null # "fill.palette", # inactivated because can be null
# "fill.color", # inactivated because can be null # "fill.color", # inactivated because can be null
"hole.size", "hole.size",
"hole.text",
"hole.text.size", "hole.text.size",
"border.color", "border.color",
"border.size", "border.size",
...@@ -9692,13 +9696,15 @@ fun_gg_donut <- function( ...@@ -9692,13 +9696,15 @@ fun_gg_donut <- function(
limits = c(- bar_width / 2 - (bar_width * hole.size) / (1 - hole.size), max(bar_width / 2, annotation.distance)) limits = c(- bar_width / 2 - (bar_width * hole.size) / (1 - hole.size), max(bar_width / 2, annotation.distance))
)) # must be centered on x = 0 )) # must be centered on x = 0
assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::ylim(c(0, max(cumsum(data1[ , freq]))))) assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::ylim(c(0, max(cumsum(data1[ , freq])))))
assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::annotate( if(hole.text == TRUE){
geom = "text", assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::annotate(
x = - bar_width / 2 - (bar_width * hole.size) / (1 - hole.size), geom = "text",
y = 0, x = - bar_width / 2 - (bar_width * hole.size) / (1 - hole.size),
label = sum(data1[ , freq]), y = 0,
size = hole.text.size label = sum(data1[ , freq]),
)) size = hole.text.size
))
}
assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::coord_polar(theta = "y", direction = -1, start = 0, clip = "on")) assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::coord_polar(theta = "y", direction = -1, start = 0, clip = "on"))
if(is.null(fill.color) & ! is.null(fill.palette)){ if(is.null(fill.color) & ! is.null(fill.palette)){
assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::scale_fill_brewer(palette = fill.palette, name = legend.name)) assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::scale_fill_brewer(palette = fill.palette, name = legend.name))
...@@ -12069,6 +12075,8 @@ fun_gg_boxplot <- function( ...@@ -12069,6 +12075,8 @@ fun_gg_boxplot <- function(
   
   
   
# add density # add density
# rasterise all kind: https://cran.r-project.org/web/packages/ggrastr/vignettes/Raster_geoms.html # rasterise all kind: https://cran.r-project.org/web/packages/ggrastr/vignettes/Raster_geoms.html
   
...@@ -14433,4 +14441,3 @@ if(return == TRUE){ ...@@ -14433,4 +14441,3 @@ if(return == TRUE){
   
   
   
...@@ -7,6 +7,7 @@ fun_gg_donut <- function( ...@@ -7,6 +7,7 @@ fun_gg_donut <- function(
fill.palette = NULL, fill.palette = NULL,
fill.color = NULL, fill.color = NULL,
hole.size = 0.5, hole.size = 0.5,
hole.text = TRUE,
hole.text.size = 14, hole.text.size = 14,
border.color = "gray50", border.color = "gray50",
border.size = 0.2, border.size = 0.2,
...@@ -43,7 +44,8 @@ fun_gg_donut <- function( ...@@ -43,7 +44,8 @@ fun_gg_donut <- function(
# fill.palette: single character string of a palette name (see ?ggplot2::scale_fill_brewer() for the list).Ignored if fill.color is not NULL # fill.palette: single character string of a palette name (see ?ggplot2::scale_fill_brewer() for the list).Ignored if fill.color is not NULL
# fill.color: either (1) NULL, or (2) a vector of character strings or integers of same length as the number of classes in categ. Colors can be color names (see ?colors() in R), hexadecimal color codes, or integers (according to the ggplot2 palette). The order of the elements will be used according to the frequency values, from highest to lowest. An easy way to use this argument is to sort data1 according to the frequencies values, add a color column with the corresponding desired colors and use the content of this column as values of fill.color. If color is NULL and fill.palette is NULL, default colors of ggplot2 are used. If color is not NULL, it overrides fill.palette # fill.color: either (1) NULL, or (2) a vector of character strings or integers of same length as the number of classes in categ. Colors can be color names (see ?colors() in R), hexadecimal color codes, or integers (according to the ggplot2 palette). The order of the elements will be used according to the frequency values, from highest to lowest. An easy way to use this argument is to sort data1 according to the frequencies values, add a color column with the corresponding desired colors and use the content of this column as values of fill.color. If color is NULL and fill.palette is NULL, default colors of ggplot2 are used. If color is not NULL, it overrides fill.palette
# hole.size: single positive proportion of donut central hole, 0 meaning no hole and 1 no donut # hole.size: single positive proportion of donut central hole, 0 meaning no hole and 1 no donut
# hole.text.size: single positive numeric value of the title font size in mm # hole.text: logical (either TRUE or FALSE). Display the sum of frequencies (column of data1 indicated in the freq argument) ?
# hole.text.size: single positive numeric value of the title font size in mm. Ignored if hole.text is FALSE
# border.color: a single character string or integer. Colors can be color names (see ?colors() in R), hexadecimal color codes, or integers (according to the ggplot2 palette) # border.color: a single character string or integer. Colors can be color names (see ?colors() in R), hexadecimal color codes, or integers (according to the ggplot2 palette)
# border.size: single numeric value of border tickness in mm. Write zero for no dot border # border.size: single numeric value of border tickness in mm. Write zero for no dot border
# title: single character string of the graph title # title: single character string of the graph title
...@@ -94,7 +96,7 @@ fun_gg_donut <- function( ...@@ -94,7 +96,7 @@ fun_gg_donut <- function(
# EXAMPLES # EXAMPLES
# obs1 <- data.frame(Km = c(20, 10, 1, 5), Car = c("TUUT", "WIIM", "BIP", "WROUM"), Color1 = 1:4, color2 = c("red", "blue", "green", "black"), Country = c("FR", "UK", "US", NA), stringsAsFactors = TRUE) ; fun_gg_donut(data1 = obs1, freq = "Km", categ = "Car", annotation = "Country") # obs1 <- data.frame(Km = c(20, 10, 1, 5), Car = c("TUUT", "WIIM", "BIP", "WROUM"), Color1 = 1:4, color2 = c("red", "blue", "green", "black"), Country = c("FR", "UK", "US", NA), stringsAsFactors = TRUE) ; fun_gg_donut(data1 = obs1, freq = "Km", categ = "Car", annotation = "Country")
# DEBUGGING # DEBUGGING
# obs1 <- data.frame(Km = c(20, 10, 1, 5), Car = c("TUUT", "WIIM", "BIP", "WROUM"), Color1 = 1:4, color2 = c("red", "blue", "green", "black"), Country = c("FR", "UK", "US", NA), stringsAsFactors = TRUE) ; data1 = obs1 ; freq = "Km" ; categ = "Car" ; fill.palette = NULL ; fill.color = NULL ; hole.size = 0.5 ; hole.text.size = 12 ; border.color = "gray50" ; border.size = 0.1 ; title = "" ; title.text.size = 12 ; annotation = "Country" ; annotation.distance = 0.5 ; annotation.size = 3 ; annotation.force = 1 ; annotation.force.pull = 100 ; legend.show = TRUE ; legend.width = 0.5 ; legend.name = NULL ; legend.limit = NULL ; legend.add.prop = FALSE ; add = NULL ; return = TRUE ; return.ggplot = FALSE ; return.gtable = TRUE ; plot = TRUE ; warn.print = FALSE ; lib.path = NULL # obs1 <- data.frame(Km = c(20, 10, 1, 5), Car = c("TUUT", "WIIM", "BIP", "WROUM"), Color1 = 1:4, color2 = c("red", "blue", "green", "black"), Country = c("FR", "UK", "US", NA), stringsAsFactors = TRUE) ; data1 = obs1 ; freq = "Km" ; categ = "Car" ; fill.palette = NULL ; fill.color = NULL ; hole.size = 0.5 ; hole.text = TRUE ; hole.text.size = 12 ; border.color = "gray50" ; border.size = 0.1 ; title = "" ; title.text.size = 12 ; annotation = "Country" ; annotation.distance = 0.5 ; annotation.size = 3 ; annotation.force = 1 ; annotation.force.pull = 100 ; legend.show = TRUE ; legend.width = 0.5 ; legend.name = NULL ; legend.limit = NULL ; legend.add.prop = FALSE ; add = NULL ; return = TRUE ; return.ggplot = FALSE ; return.gtable = TRUE ; plot = TRUE ; warn.print = FALSE ; lib.path = NULL
# function name # function name
function.name <- paste0(as.list(match.call(expand.dots=FALSE))[[1]], "()") function.name <- paste0(as.list(match.call(expand.dots=FALSE))[[1]], "()")
arg.names <- names(formals(fun = sys.function(sys.parent(n = 2)))) # names of all the arguments arg.names <- names(formals(fun = sys.function(sys.parent(n = 2)))) # names of all the arguments
...@@ -169,6 +171,7 @@ fun_gg_donut <- function( ...@@ -169,6 +171,7 @@ fun_gg_donut <- function(
} }
} }
tempo <- fun_check(data = hole.size, prop = TRUE, length = 1, fun.name = function.name) ; eval(ee) tempo <- fun_check(data = hole.size, prop = TRUE, length = 1, fun.name = function.name) ; eval(ee)
tempo <- fun_check(data = hole.text, class = "logical", length = 1, fun.name = function.name) ; eval(ee)
tempo <- fun_check(data = hole.text.size, class = "vector", mode = "numeric", neg.values = FALSE, inf.values = FALSE, length = 1, fun.name = function.name) ; eval(ee) tempo <- fun_check(data = hole.text.size, class = "vector", mode = "numeric", neg.values = FALSE, inf.values = FALSE, length = 1, fun.name = function.name) ; eval(ee)
tempo1 <- fun_check(data = border.color, class = "vector", mode = "character", na.contain = FALSE, length = 1, fun.name = function.name) tempo1 <- fun_check(data = border.color, class = "vector", mode = "character", na.contain = FALSE, length = 1, fun.name = function.name)
tempo2 <- fun_check(data = border.color, class = "integer", double.as.integer.allowed = TRUE, neg.values = FALSE, na.contain = FALSE, length = 1, fun.name = function.name) # not need to test inf with integers tempo2 <- fun_check(data = border.color, class = "integer", double.as.integer.allowed = TRUE, neg.values = FALSE, na.contain = FALSE, length = 1, fun.name = function.name) # not need to test inf with integers
...@@ -256,6 +259,7 @@ fun_gg_donut <- function( ...@@ -256,6 +259,7 @@ fun_gg_donut <- function(
# "fill.palette", # inactivated because can be null # "fill.palette", # inactivated because can be null
# "fill.color", # inactivated because can be null # "fill.color", # inactivated because can be null
"hole.size", "hole.size",
"hole.text",
"hole.text.size", "hole.text.size",
"border.color", "border.color",
"border.size", "border.size",
...@@ -552,13 +556,15 @@ fun_gg_donut <- function( ...@@ -552,13 +556,15 @@ fun_gg_donut <- function(
limits = c(- bar_width / 2 - (bar_width * hole.size) / (1 - hole.size), max(bar_width / 2, annotation.distance)) limits = c(- bar_width / 2 - (bar_width * hole.size) / (1 - hole.size), max(bar_width / 2, annotation.distance))
)) # must be centered on x = 0 )) # must be centered on x = 0
assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::ylim(c(0, max(cumsum(data1[ , freq]))))) assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::ylim(c(0, max(cumsum(data1[ , freq])))))
assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::annotate( if(hole.text == TRUE){
geom = "text", assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::annotate(
x = - bar_width / 2 - (bar_width * hole.size) / (1 - hole.size), geom = "text",
y = 0, x = - bar_width / 2 - (bar_width * hole.size) / (1 - hole.size),
label = sum(data1[ , freq]), y = 0,
size = hole.text.size label = sum(data1[ , freq]),
)) size = hole.text.size
))
}
assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::coord_polar(theta = "y", direction = -1, start = 0, clip = "on")) assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::coord_polar(theta = "y", direction = -1, start = 0, clip = "on"))
if(is.null(fill.color) & ! is.null(fill.palette)){ if(is.null(fill.color) & ! is.null(fill.palette)){
assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::scale_fill_brewer(palette = fill.palette, name = legend.name)) assign(paste0(tempo.gg.name, tempo.gg.count <- tempo.gg.count + 1), ggplot2::scale_fill_brewer(palette = fill.palette, name = legend.name))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment