Title: | Graphical Utilities for Visualizing and Exploring Data |
---|---|
Description: | Simplifies the process of creating essential visualizations in R, offering a range of plotting functions for common chart types like violin plots, pie charts, and histograms. With an intuitive interface, users can effortlessly customize colors, labels, and styles, making it an ideal tool for both beginners and experienced data analysts. Whether exploring datasets or producing quick visual summaries, this package provides a streamlined solution for fundamental graphics in R. |
Authors: | Etienne Camenen [aut, cre] |
Maintainer: | Etienne Camenen <[email protected]> |
License: | GPL-3 |
Version: | 0.2.0 |
Built: | 2024-11-16 03:50:10 UTC |
Source: | https://github.com/ecamenen/gimmemyplot |
Display each numerical value separately using a barplot
plot_bar( x = NULL, title = NULL, width_title = 20, colour = c("blue", "gray", "#cd5b45"), color_title = "black", cex = 1, cex_main = cex * 30, digits = 0, n_max = 100, ratio = 5, threshold = 2, hjust_title = 0 )
plot_bar( x = NULL, title = NULL, width_title = 20, colour = c("blue", "gray", "#cd5b45"), color_title = "black", cex = 1, cex_main = cex * 30, digits = 0, n_max = 100, ratio = 5, threshold = 2, hjust_title = 0 )
x |
Vector of numerical values visualized on the plot. |
title |
Character for the title. |
width_title |
Integer for the maximum length of the title. |
colour |
Color or vector of colors for the gradient of the bars. |
color_title |
Color for the title. |
cex |
Double for the magnification factor for the text relative to the default. |
cex_main |
Double for the magnification factor for the subtitles relative to the default. |
digits |
Integer for the number of decimals. |
n_max |
Integer for the maximum number of bars to show (prioritizing those with the largest value) |
ratio |
Double for the width scale |
threshold |
Double for the minimal percentage value before being hidden on the plot. |
hjust_title |
Double for the horizontal justification of the title (in [0, 1]). |
library(magrittr) # Default parameters x <- runif(10, 1, 10) %>% set_names(paste("Sample", LETTERS[seq(10)])) plot_bar(x) # Advanced parameters plot_bar( x = x, title = "Some numerical variable", width_title = 30, colour = c("yellow", "gray", "red"), color_title = "blue", cex = 1.2, digits = 1, n_max = 5, ratio = 15, hjust_title = 1 )
library(magrittr) # Default parameters x <- runif(10, 1, 10) %>% set_names(paste("Sample", LETTERS[seq(10)])) plot_bar(x) # Advanced parameters plot_bar( x = x, title = "Some numerical variable", width_title = 30, colour = c("yellow", "gray", "red"), color_title = "blue", cex = 1.2, digits = 1, n_max = 5, ratio = 15, hjust_title = 1 )
Visualize the proportions of multiple categorical variables using a barplot
plot_bar_mcat( x, sample_size = NULL, title = NULL, width_text = 20, width_title = width_text, colour = c("blue", "gray", "#cd5b45"), color_title = "black", cex = 10, digits = 0, collapse = FALSE, ratio = 5, n_collapse = 5, n_max = Inf, threshold = 1, hjust_title = -0.5, hjust_text = -0.1, vjust_text = 0.5 )
plot_bar_mcat( x, sample_size = NULL, title = NULL, width_text = 20, width_title = width_text, colour = c("blue", "gray", "#cd5b45"), color_title = "black", cex = 10, digits = 0, collapse = FALSE, ratio = 5, n_collapse = 5, n_max = Inf, threshold = 1, hjust_title = -0.5, hjust_text = -0.1, vjust_text = 0.5 )
x |
Data.frame of character values visualized on the plot. |
sample_size |
Integer for the sample size of the dataset to calculate percentages (if different from the length of the variable). |
title |
Character for the title. |
width_text |
Integer for the maximum length of the subtitle(s). |
width_title |
Integer for the maximum length of the title. |
colour |
Color or vector of colors for the violin and boxplot. |
color_title |
Color for the title. |
cex |
Double for the magnification factor for the text relative to the default. |
digits |
Integer for the number of decimals. |
collapse |
Boolean to merge categories with identical proportions. |
ratio |
Double for the width scale |
n_collapse |
Integer for the maximum number of merged categories to show |
n_max |
Integer for the maximum number of bars to show (prioritizing those with the largest value) |
threshold |
Double for the minimal percentage value before being hidden on the plot. |
hjust_title |
Double for the horizontal justification of the title (in [0, 1]). |
hjust_text |
Double for the horizontal justification of the text (in [0, 1]). |
vjust_text |
Double for the vertical justification of the text (in [0, 1]). |
A ggplot object.
library(magrittr) library(RColorBrewer) # Default parameters df <- sapply(seq(10), function(x) runif(10) %>% round()) %>% as.data.frame() colnames(df) <- paste("Level", seq(10)) plot_bar_mcat(df) # Advanced parameters plot_bar_mcat( df, sample_size = 15, title = "Some categorical variable", width_text = 30, width_title = 50, colour = brewer.pal(9, "Reds"), color_title = "red", cex = 8, digits = 1, collapse = TRUE, ratio = 2, n_collapse = 3, n_max = 4, hjust_title = 1 )
library(magrittr) library(RColorBrewer) # Default parameters df <- sapply(seq(10), function(x) runif(10) %>% round()) %>% as.data.frame() colnames(df) <- paste("Level", seq(10)) plot_bar_mcat(df) # Advanced parameters plot_bar_mcat( df, sample_size = 15, title = "Some categorical variable", width_text = 30, width_title = 50, colour = brewer.pal(9, "Reds"), color_title = "red", cex = 8, digits = 1, collapse = TRUE, ratio = 2, n_collapse = 3, n_max = 4, hjust_title = 1 )
Visualize the distribution of single variable using histogram
plot_histogram( x, title = NULL, width_title = 20, color = "red", color_title = color, color_stats = "black", cex = 1, cex_axis = 17 * cex, cex_main = 21 * cex, cex_sub = 15 * cex, digits = 0, subtitle = TRUE, probs = c(0.25, 0.75), binwidth = 1.5 )
plot_histogram( x, title = NULL, width_title = 20, color = "red", color_title = color, color_stats = "black", cex = 1, cex_axis = 17 * cex, cex_main = 21 * cex, cex_sub = 15 * cex, digits = 0, subtitle = TRUE, probs = c(0.25, 0.75), binwidth = 1.5 )
x |
Vector of numerical values visualized on the plot |
title |
Character for the title. |
width_title |
Integer for the maximum length of the title. |
color |
Color for the plot |
color_title |
Color for the title. |
color_stats |
Color for the median and quantile lines |
cex |
Double for the magnification factor for the text relative to the default. |
cex_axis |
Double for the magnification factor for the axis labels relative to the default. |
cex_main |
Double for the magnification factor for the subtitles relative to the default. |
cex_sub |
Double for the magnification factor for the main title relative to the default. |
digits |
Integer for the number of decimals. |
subtitle |
Boolean to display the subtitle. |
probs |
Double vector for the probabilities (in [0, 1]). |
binwidth |
Double for the number of bins |
A ggplot object.
# Default parameters x <- rnorm(100) plot_histogram(x) # Advanced parameters plot_histogram( x, title = "Some numerical variable", width_title = 15, color = "blue", color_title = "orange", color_stats = "orange", cex = 1.2, digits = 1, binwidth = 0.5 )
# Default parameters x <- rnorm(100) plot_histogram(x) # Advanced parameters plot_histogram( x, title = "Some numerical variable", width_title = 15, color = "blue", color_title = "orange", color_stats = "orange", cex = 1.2, digits = 1, binwidth = 0.5 )
Visualize the proportions of a categorical variable using a piechart
plot_pie( x, title = NULL, width_text = 5, width_title = 20, colour = get_colors(), digits = 0.1, cex = 15, cex_main = cex * 1.5, hsize = 1.2, legend = TRUE, sample_size = NULL, collapse = FALSE, threshold = 5, t = -0.5, l = -1, r = -1, b = -1 )
plot_pie( x, title = NULL, width_text = 5, width_title = 20, colour = get_colors(), digits = 0.1, cex = 15, cex_main = cex * 1.5, hsize = 1.2, legend = TRUE, sample_size = NULL, collapse = FALSE, threshold = 5, t = -0.5, l = -1, r = -1, b = -1 )
x |
Vector of character values visualized on the plot. |
title |
Character for the title. |
width_text |
Integer for the maximum length of the subtitle(s). |
width_title |
Integer for the maximum length of the title. |
colour |
Color or vector of colors for the categories. |
digits |
Integer for the number of decimals. |
cex |
Double for the magnification factor for the text relative to the default. |
cex_main |
Double for the magnification factor for the subtitles relative to the default. |
hsize |
Double for the size of the central hole in the pie chart (in [1, 2]). |
legend |
Boolean to toggle the display of the legend. |
sample_size |
Integer for the sample size of the dataset to calculate percentages (if different from the length of the variable). |
collapse |
Boolean to merge categories with identical proportions. |
threshold |
Double for the minimal percentage value before being hidden on the plot. |
t , r , b , l
|
Dimensions of each margin. (To remember order, think trouble). |
A ggplot object.
library(magrittr) library(RColorBrewer) # Default parameters x <- c(rep("A", 5), rep("B", 4)) plot_pie(x) # Advanced parameters k <- 10 n <- runif(k, 1, 10) %>% round() x <- paste("Level", seq(k)) %>% mapply(function(x, y) rep(x, y), ., n) %>% unlist() plot_pie( x, title = "Some categorical variable", width_text = 5, width_title = 20, colour = brewer.pal(9, "Reds"), cex = 20, digits = 1, hsize = 1.5, collapse = TRUE, b = 3 )
library(magrittr) library(RColorBrewer) # Default parameters x <- c(rep("A", 5), rep("B", 4)) plot_pie(x) # Advanced parameters k <- 10 n <- runif(k, 1, 10) %>% round() x <- paste("Level", seq(k)) %>% mapply(function(x, y) rep(x, y), ., n) %>% unlist() plot_pie( x, title = "Some categorical variable", width_text = 5, width_title = 20, colour = brewer.pal(9, "Reds"), cex = 20, digits = 1, hsize = 1.5, collapse = TRUE, b = 3 )
Visualize the distribution of single or multiple variables using violin plots, boxplots, and sina plots
plot_violin( x, method = "anova", method_adjust = "BH", title = NULL, width_text = 20, width_title = 20, colour = "red", color_title = colour, pch_alpha = 1, pch_colour = "gray50", pch_size = cex, cex = 1, cex_axis = 17 * cex, cex_main = 21 * cex, cex_sub = 15 * cex, stats = TRUE, digits = 0, alpha = 0.3, coef = 1.5, hjust = 0.5, lwd = 1, probs = c(0.25, 0.75), subtitle = FALSE, ylab = NULL )
plot_violin( x, method = "anova", method_adjust = "BH", title = NULL, width_text = 20, width_title = 20, colour = "red", color_title = colour, pch_alpha = 1, pch_colour = "gray50", pch_size = cex, cex = 1, cex_axis = 17 * cex, cex_main = 21 * cex, cex_sub = 15 * cex, stats = TRUE, digits = 0, alpha = 0.3, coef = 1.5, hjust = 0.5, lwd = 1, probs = c(0.25, 0.75), subtitle = FALSE, ylab = NULL )
x |
Vector or data.frame of numerical values visualized on the plot. |
method |
Character for the test method ('anova', 'kruskal', or 'wilcox'). |
method_adjust |
Character for the multiple correction test among 'BH', 'BY', 'bonferroni', 'fdr', 'hochberg', 'holm', 'hommel', 'none' |
title |
Character for the title. |
width_text |
Integer for the maximum length of the subtitle(s). |
width_title |
Integer for the maximum length of the title. |
colour |
Color or vector of colors for the violin and boxplot. |
color_title |
Color for the title. |
pch_alpha |
Double for the transparency of the points (ranging from 0 to 1 for maximum opacity). |
pch_colour |
Color for the sina points. |
pch_size |
Double for the magnification factor for the points relative to the default. |
cex |
Double for the magnification factor for the text relative to the default. |
cex_axis |
Double for the magnification factor for the axis labels relative to the default. |
cex_main |
Double for the magnification factor for the subtitles relative to the default. |
cex_sub |
Double for the magnification factor for the main title relative to the default. |
stats |
Boolean to display the results of statistical tests. |
digits |
Integer for the number of decimals. |
alpha |
Double for the transparency of the violin plot (ranging from 0 to 1 for maximum opacity). |
coef |
Double to multiply the quantiles by. |
hjust |
Double for the horizontal justification (in [0, 1]). |
lwd |
Double for the line width. |
probs |
Double vector for the probabilities (in [0, 1]). |
subtitle |
Boolean to display the subtitle. |
ylab |
Character for the title of the Y-axis. |
A ggplot object.
library(RColorBrewer) # Default parameters x <- runif(10) plot_violin(x) # Advanced parameters df <- lapply(seq(2), function(x) runif(10)) df <- as.data.frame(df) df[, 3] <- runif(10, 1, 2) colnames(df) <- paste0("X", seq(3)) plot_violin( df, title = "Some numerical variables", color_title = brewer.pal(9, "Set1")[5], ylab = "Y-values", colour = brewer.pal(9, "Set1")[seq(3)], method = "kruskal", method_adjust = "none", cex = 1.2, pch_size = 3, width_text = 5, pch_colour = "gray30", pch_alpha = 0.5, width_title = 30, lwd = 1.25, digits = 2 )
library(RColorBrewer) # Default parameters x <- runif(10) plot_violin(x) # Advanced parameters df <- lapply(seq(2), function(x) runif(10)) df <- as.data.frame(df) df[, 3] <- runif(10, 1, 2) colnames(df) <- paste0("X", seq(3)) plot_violin( df, title = "Some numerical variables", color_title = brewer.pal(9, "Set1")[5], ylab = "Y-values", colour = brewer.pal(9, "Set1")[seq(3)], method = "kruskal", method_adjust = "none", cex = 1.2, pch_size = 3, width_text = 5, pch_colour = "gray30", pch_alpha = 0.5, width_title = 30, lwd = 1.25, digits = 2 )