Commit 2bbd5f0c authored by Gael's avatar Gael
Browse files

scatter_examples done, fun_gg_scatter() debugged, fun_check() also

parent 143d46e4
......@@ -26,25 +26,47 @@ fun_gg_boxplot(data1 = obs1[1:20, ], y = "Time", categ = c("Categ1", "Categ2"))
### Changing the order of the boxes
# separate boxes
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1", categ.class.order = list(c("DOG", "CAT")))
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
categ.class.order = list(c("DOG", "CAT"))
)
# grouped boxes
fun_gg_boxplot(data1 = obs1, y = "Time", categ = c("Categ1", "Categ2"), categ.class.order = list(c("DOG", "CAT"), c("D", "C", "B", "A")))
fun_gg_boxplot(data1 = obs1, y = "Time", categ = c("Categ1", "Categ2"),
categ.class.order = list(c("DOG", "CAT"), c("D", "C", "B", "A"))
)
### Box color
# Using a single color value
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1", categ.color = "coral")
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
categ.color = "coral"
)
# Using one color value par class of Categ1
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1", categ.color = c("coral", "lightblue"))
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
categ.color = c("coral", "lightblue")
)
# Using a vector of color values (e.g., data frame column), with respect of the correspondence between Categ1 and box.color columns
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1", categ.color = obs1$Color1)
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
categ.color = obs1$Color1
)
# Using integers instead of color strings
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1", categ.color = 1)
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1", categ.color = 1:2)
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1", categ.color = as.numeric(obs1$Color1))
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
categ.color = 1
)
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
categ.color = 1:2
)
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
categ.color = as.numeric(obs1$Color1)
)
# With grouped boxes, we generate the same effects but for the second category
fun_gg_boxplot(data1 = obs1, y = "Time", categ = c("Categ1", "Categ2"), categ.color = "coral")
fun_gg_boxplot(data1 = obs1, y = "Time", categ = c("Categ1", "Categ2"), categ.color = 1:4)
fun_gg_boxplot(data1 = obs1, y = "Time", categ = c("Categ1", "Categ2"), categ.color = obs1$Color2)
fun_gg_boxplot(data1 = obs1, y = "Time", categ = c("Categ1", "Categ2"),
categ.color = "coral"
)
fun_gg_boxplot(data1 = obs1, y = "Time", categ = c("Categ1", "Categ2"),
categ.color = 1:4
)
fun_gg_boxplot(data1 = obs1, y = "Time", categ = c("Categ1", "Categ2"),
categ.color = obs1$Color2
)
### Other parameters of boxes
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
......@@ -60,23 +82,49 @@ box.whisker.kind = "max",
box.whisker.width = 0.5 # between 0 (no whisker extremities) and 1 (whisker extremities the width of the boxes)
)
### Box removal
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
box.alpha = 0
)
### Dot colors
# Dot removal
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1", dot.color = NULL)
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
dot.color = NULL
)
# Same color as the boxes
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1", dot.color = "same")
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
dot.color = "same"
)
# Single color sting
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1", dot.color = "green") # a single integer also works
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
dot.color = "green" # a single integer also works
)
# Same number of Categ1 classes
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1", dot.color = c("green", "brown")) # test also 1:2 (result is idem as "same")
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
dot.color = c("green", "brown") # test also 1:2 (result is idem as "same")
)
# Using a vector of color values of the same length as the number of rows in data1 (e.g., data frame column). No correspondence with Categ1 classes is required
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1", dot.color = 1:nrow(obs1))
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
dot.color = 1:nrow(obs1)
)
# With grouped boxes, we generate the same effects but for the second category
fun_gg_boxplot(data1 = obs1, y = "Time", categ = c("Categ1", "Categ2"), dot.color = NULL)
fun_gg_boxplot(data1 = obs1, y = "Time", categ = c("Categ1", "Categ2"), dot.color = "same")
fun_gg_boxplot(data1 = obs1, y = "Time", categ = c("Categ1", "Categ2"), dot.color = "green") # a single integer also works
fun_gg_boxplot(data1 = obs1, y = "Time", categ = c("Categ1", "Categ2"), dot.color = c("green", "brown", "red", "blue")) # test also 1:2 (result is idem as "same")
fun_gg_boxplot(data1 = obs1, y = "Time", categ = c("Categ1", "Categ2"), dot.color = 1:nrow(obs1))
fun_gg_boxplot(data1 = obs1, y = "Time", categ = c("Categ1", "Categ2"),
dot.color = NULL
)
fun_gg_boxplot(data1 = obs1, y = "Time", categ = c("Categ1", "Categ2"),
dot.color = "same"
)
fun_gg_boxplot(data1 = obs1, y = "Time", categ = c("Categ1", "Categ2"),
dot.color = "green" # a single integer also works
)
fun_gg_boxplot(data1 = obs1, y = "Time", categ = c("Categ1", "Categ2"),
dot.color = c("green", "brown", "red", "blue") # test also 1:2 (result is idem as "same")
)
fun_gg_boxplot(data1 = obs1, y = "Time", categ = c("Categ1", "Categ2"),
dot.color = 1:nrow(obs1)
)
### Legend for dots
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
......@@ -90,25 +138,33 @@ dot.legend.name = "ANIMAL GROUP"
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
dot.tidy = TRUE,
dot.tidy.bin.nb = 50, # from 0 to Inf. Only if dot.tidy = TRUE
dot.jitter = 0.5 # from 0 to 1. Only if dot.tidy = FALSE
dot.jitter = 0.5, # from 0 to 1. Only if dot.tidy = FALSE
dot.seed = 55 # if the dot shuffling is not satisfying, test another integer.Ssee below an example with dot.seed = NULL
)
### Other parameters of dots
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
dot.categ = "Categ2", # to see the dot legend
dot.color = c("green", "brown", "red", "blue"),
dot.categ = "Categ2", # to see the dot legend
dot.size = 5, # ignored if dot.tidy = TRUE
dot.alpha = 0.3,
dot.border.size = 2,
dot.border.color = "green",
dot.border.color = "green"
)
### X-axis parameter
### Reshuffling of dots
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
x.lab = "ANIMALS"
dot.seed = NULL # rerun several times, and test the same with dot.seed = 1 for instance
)
### Y-axis parameter
### X-axis parameters
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
x.lab = "ANIMALS",
x.angle = 90
)
### Y-axis parameters
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
y.lab = "SIZE",
y.lim = c(1000, 0.1), # order matters
......@@ -125,7 +181,8 @@ fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
stat.disp = "above", # try "top"
stat.disp.mean = FALSE,
stat.size = 4,
stat.dist = 2
stat.dist = 2,
stat.angle = 90
)
### Plot orientation
......@@ -136,8 +193,7 @@ vertical = FALSE # with log2 and log10 scales, horizontal orientation is blocked
### Text management
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
text.size = 20,
x.angle = 90
text.size = 20
)
### Title
......@@ -148,7 +204,7 @@ title.text.size = 20
### Management of the legend area
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
legend.show = FALSE, # remove the legend, not the area of the legend
legend.show = FALSE, # FALSE remove the legend, not the area of the legend
legend.width = 1 # between 0 (no area for the legend) to 1 (half the device width for the legend area). Use NULL for default management
)
......@@ -164,15 +220,15 @@ add = "+ggplot2::theme_classic()"
)
fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
add = "+ggplot2::facet_wrap(facets = 'Categ2', labeller = 'label_both') + ggplot2::theme(strip.background = ggplot2::element_rect(color = 'grey', size = 0.5), strip.text = ggplot2::element_text(size = 10, face = 'bold'), panel.spacing = ggplot2::unit(0.5, 'lines'))" # or ggplot2::vars(Categ2) instead of 'Categ2'. See https://ggplot2.tidyverse.org/reference/labeller.html
)
) # use legend.show = FALSE, legend.width = 0 to remove the legend area
### Other parameters
res <- fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
return = TRUE,
return = TRUE, # output returned (and assigned into res)
return.ggplot = TRUE,
return.gtable = FALSE,
plot = FALSE,
plot = FALSE, # no plot displayed
warn.print = FALSE,
lib.path = NULL
)
......@@ -180,19 +236,22 @@ lib.path = NULL
fun_open(pdf = FALSE)
res$ggplot
# display the output (manipulation of res triggers plotting because of the presence of non NULL $ggplot, which is annoying, as explain in the function description)
# The advantage of $ggplot is that it is easy to update the plot
res$ggplot + ggplot2::annotate(geom = "text", x = 1.5, y = 400, label = "NOT GOOD", size = 20, angle = 45)
# However, manipulation of res triggers plotting because of the presence of non NULL $ggplot, which is annoying, as explain in the function description. Thus, it is preferable to use return.ggplot = FALSE
fun_open(pdf = FALSE)
res
# The advantage of $ggplot is that it is easy to update the plot
### Notes about the gtable output
res2 <- fun_gg_boxplot(data1 = obs1, y = "Time", categ = "Categ1",
return = TRUE,
return.ggplot = FALSE,
return.gtable = TRUE,
plot = TRUE, # plot must be TRUE to have a non NULL $gtable output
return.gtable = TRUE, # return.gtable must be TRUE to have a non NULL $gtable output into res2
plot = TRUE, # plot must be TRUE to have a non NULL $gtable output into res2
warn.print = FALSE,
lib.path = NULL
)
......@@ -203,7 +262,7 @@ res2
# replot
fun_open(pdf = FALSE)
gridExtra::grid.arrange(res2$gtable)
gridExtra::grid.arrange(res2$gtable) # Contrary to $ggplot, $gtable cannot be easily updated (see https://stackoverflow.com/questions/26499608/inverse-of-ggplotgrob)
# plot the first grob
fun_open(pdf = FALSE)
gridExtra::grid.arrange(res2$gtable[1,1])
......
This source diff could not be displayed because it is too large. You can view the blob instead.
No preview for this file type
No preview for this file type
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment