This commit is contained in:
gnoblet 2025-02-09 17:19:54 +01:00
parent 5beec7fb90
commit 7f56642954
68 changed files with 1380 additions and 953 deletions

View file

@ -1,16 +1,32 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/bar.R
\name{bar}
\name{hbar}
\alias{hbar}
\alias{bar}
\title{Simple bar chart}
\usage{
hbar(
...,
flip = TRUE,
add_text = FALSE,
theme_fun = theme_bar(flip = flip, add_text = add_text)
)
bar(
df,
x,
y,
group = "",
add_color = color("dark_grey"),
flip = TRUE,
facet = "",
order = "none",
x_rm_na = TRUE,
y_rm_na = TRUE,
group_rm_na = TRUE,
facet_rm_na = TRUE,
y_expand = 0.1,
add_color = color("cat_5_main_1"),
add_color_guide = TRUE,
flip = FALSE,
wrap = NULL,
position = "dodge",
alpha = 1,
@ -20,18 +36,28 @@ bar(
title = NULL,
subtitle = NULL,
caption = NULL,
width = 0.5,
add_text = TRUE,
add_text_size = 5,
width = 0.8,
add_text = FALSE,
add_text_size = 4.5,
add_text_color = color("dark_grey"),
add_text_font_face = "plain",
add_text_font_face = "bold",
add_text_threshold_display = 0.05,
add_text_suffix = "\%",
add_text_expand_limit = 1.2,
add_text_round = 1
add_text_round = 1,
theme_fun = theme_bar(flip = flip, add_text = add_text, axis_text_x_angle = 0,
axis_text_x_vjust = 0.5, axis_text_x_hjust = 0.5),
scale_fill_fun = scale_fill_visualizer_discrete(),
scale_color_fun = scale_color_visualizer_discrete()
)
}
\arguments{
\item{flip}{TRUE or FALSE (default). Default to TRUE or horizontal bar plot.}
\item{add_text}{TRUE or FALSE. Add values as text.}
\item{theme_fun}{Whatever theme function. For no custom theme, use theme_fun = NULL.}
\item{df}{A data frame.}
\item{x}{A quoted numeric column.}
@ -40,9 +66,23 @@ bar(
\item{group}{Some quoted grouping categorical column, e.g. administrative areas or population groups.}
\item{facet}{Some quoted grouping categorical column, e.g. administrative areas or population groups.}
\item{order}{Should bars be ordered? "none" if no, "y" if yes based on y, "grouped" if yes based on y and group.}
\item{x_rm_na}{Remove NAs in x?}
\item{y_rm_na}{Remove NAs in y?}
\item{group_rm_na}{Remove NAs in group?}
\item{facet_rm_na}{Remove NAs in facet?}
\item{y_expand}{Multiplier to expand the y axis.}
\item{add_color}{Add a color to bars (if no grouping).}
\item{flip}{TRUE or FALSE. Default to TRUE or horizontal bar plot.}
\item{add_color_guide}{Should a legend be added?}
\item{wrap}{Should x-labels be wrapped? Number of characters.}
@ -64,8 +104,6 @@ bar(
\item{width}{Bar width.}
\item{add_text}{TRUE or FALSE. Add values as text.}
\item{add_text_size}{Text size.}
\item{add_text_color}{Text color.}
@ -76,14 +114,10 @@ bar(
\item{add_text_suffix}{If percent is FALSE, should we add a suffix to the text label?}
\item{add_text_expand_limit}{Default to adding 10% on top of the bar.}
\item{add_text_expand_limit}{Default to adding 10\% on top of the bar.}
\item{add_text_round}{Round the text label.}
\item{theme_fun}{Whatever theme function. For no custom theme, use theme_fun = NULL.}
\item{scale_impact}{Use the package custom scales for fill and color.}
}
\description{
Simple bar chart
`bar()` is a simple bar chart with some customization allowed, in particular the `theme_fun` argument for theming. `hbar()` uses `bar()` with sane defaults for a horizontal bar chart.
}

85
man/dumbbell.Rd Normal file
View file

@ -0,0 +1,85 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/dumbbell.R
\name{dumbbell}
\alias{dumbbell}
\title{Make dumbbell chart.}
\usage{
dumbbell(
df,
col,
group_x,
group_y,
point_size = 5,
point_alpha = 1,
segment_size = 2.5,
segment_color = cols_reach("main_lt_grey"),
group_x_title = NULL,
group_y_title = NULL,
x_title = NULL,
title = NULL,
subtitle = NULL,
caption = NULL,
line_to_y_axis = TRUE,
line_to_y_axis_type = 3,
line_to_y_axis_width = 0.5,
line_to_y_axis_color = cols_reach("main_grey"),
add_text = TRUE,
add_text_vjust = 2,
add_text_size = 3.5,
add_text_color = cols_reach("main_grey"),
theme = theme_reach(palette = "primary")
)
}
\arguments{
\item{df}{A data frame.}
\item{col}{A numeric column.}
\item{group_x}{The grouping column on the x-axis; only two groups.}
\item{group_y}{The grouping column on the y-axis.}
\item{point_size}{Point size.}
\item{point_alpha}{Point alpha.}
\item{segment_size}{Segment size.}
\item{segment_color}{Segment color.}
\item{group_x_title}{X-group and legend title.}
\item{group_y_title}{Y-axis and group title.}
\item{x_title}{X-axis title.}
\item{title}{Title.}
\item{subtitle}{Subtitle.}
\item{caption}{Caption.}
\item{line_to_y_axis}{TRUE or FALSE; add a line connected points and Y-axis.}
\item{line_to_y_axis_type}{Line to Y-axis type.}
\item{line_to_y_axis_width}{Line to Y-axis width.}
\item{line_to_y_axis_color}{Line to Y-axis color.}
\item{add_text}{TRUE or FALSE; add text at the points.}
\item{add_text_vjust}{Vertical adjustment.}
\item{add_text_size}{Text size.}
\item{add_text_color}{Text color.}
\item{theme}{A ggplot2 theme, default to `theme_reach()`}
}
\value{
A dumbbell chart.
}
\description{
Make dumbbell chart.
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 70 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 67 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 73 KiB

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 KiB

After

Width:  |  Height:  |  Size: 177 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 318 KiB

After

Width:  |  Height:  |  Size: 357 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 166 KiB

After

Width:  |  Height:  |  Size: 191 KiB

Before After
Before After

View file

@ -2,14 +2,21 @@
% Please edit documentation in R/point.R
\name{point}
\alias{point}
\title{Simple point chart}
\title{Simple scatterplot}
\usage{
point(
df,
x,
y,
group = "",
add_color = color("branding_reach_red"),
facet = "",
facet_scales = "free",
x_rm_na = TRUE,
y_rm_na = TRUE,
group_rm_na = TRUE,
facet_rm_na = TRUE,
add_color = color("cat_5_main_1"),
add_color_guide = TRUE,
flip = TRUE,
alpha = 1,
size = 2,
@ -19,25 +26,37 @@ point(
title = NULL,
subtitle = NULL,
caption = NULL,
theme_fun = theme_reach(grid_major_y = TRUE),
palette = "cat_5_ibm",
scale_impact = TRUE,
direction = 1,
reverse_guide = TRUE
theme_fun = theme_point(),
scale_fill_fun = scale_fill_visualizer_discrete(),
scale_color_fun = scale_color_visualizer_discrete()
)
}
\arguments{
\item{df}{A data frame.}
\item{x}{A numeric column.}
\item{x}{A quoted numeric column.}
\item{y}{Another numeric column.}
\item{y}{A quoted numeric column.}
\item{group}{Some grouping categorical column, e.g. administrative areas or population groups.}
\item{group}{Some quoted grouping categorical column, e.g. administrative areas or population groups.}
\item{add_color}{Add a color to bars (if no grouping).}
\item{facet}{Some quoted grouping categorical column.}
\item{flip}{TRUE or FALSE. Default to TRUE or horizontal bar plot.}
\item{facet_scales}{Character. Either "free" (default) or "fixed" for facet scales.}
\item{x_rm_na}{Remove NAs in x?}
\item{y_rm_na}{Remove NAs in y?}
\item{group_rm_na}{Remove NAs in group?}
\item{facet_rm_na}{Remove NAs in facet?}
\item{add_color}{Add a color to points (if no grouping).}
\item{add_color_guide}{Should a legend be added?}
\item{flip}{TRUE or FALSE.}
\item{alpha}{Fill transparency.}
@ -55,10 +74,8 @@ point(
\item{caption}{Plot caption. Default to NULL.}
\item{theme_fun}{Whatever theme. Default to theme_reach(). NULL if no theming needed.}
\item{scale_impact}{Use the package custom scales for fill and color.}
\item{theme_fun}{Whatever theme. Default to theme_point(). NULL if no theming needed.}
}
\description{
Simple point chart
Simple scatterplot
}

42
man/reorder_by.Rd Normal file
View file

@ -0,0 +1,42 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/reorder_by.R
\name{reorder_by}
\alias{reorder_by}
\title{Reorder a Data Frame}
\usage{
reorder_by(df, x, y, group = "", order = "y", dir_order = 1)
}
\arguments{
\item{df}{A data frame to be reordered.}
\item{x}{A character scalar specifying the column to be reordered.}
\item{y}{A character scalar specifying the column to order by if ordering by values.}
\item{group}{A character scalar specifying the grouping column (optional).}
\item{order}{A character scalar specifying the order type (one of "none", "y", "grouped"). See details.}
\item{dir_order}{A logical scalar specifying whether to flip the order.}
}
\value{
The reordered data frame.
}
\description{
Reorder a Data Frame
}
\details{
Ordering takes the following possible values:
* "none": No reordering.
* "y": Order by values of y.
* "grouped_y": Order by values of y and group.
* "x": Order alphabetically by x.
* "grouped_x": Order alphabetically by x and group.
}
\examples{
# Example usage
df <- data.frame(col1 = c("b", "a", "c"), col2 = c(10, 25, 3))
reorder_by(df, "col1", "col2")
}

View file

@ -11,6 +11,7 @@ scale_color_visualizer_discrete(
palette = "cat_5_main",
direction = 1,
reverse_guide = TRUE,
title_position = NULL,
...
)
@ -18,6 +19,7 @@ scale_fill_visualizer_discrete(
palette = "cat_5_main",
direction = 1,
reverse_guide = TRUE,
title_position = NULL,
...
)
@ -25,6 +27,7 @@ scale_fill_visualizer_continuous(
palette = "seq_5_main",
direction = 1,
reverse_guide = TRUE,
title_position = NULL,
...
)
@ -32,6 +35,7 @@ scale_color_visualizer_continuous(
palette = "seq_5_main",
direction = 1,
reverse_guide = TRUE,
title_position = NULL,
...
)
}

View file

@ -1,25 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/scale.R
\name{scale_visualizer_discrete}
\alias{scale_visualizer_discrete}
\title{One scale for all}
\usage{
scale_visualizer_discrete(
palette = "cat_5_main",
direction = 1,
reverse_guide = TRUE,
...
)
}
\arguments{
\item{palette}{Palette name from [palette()].}
\item{direction}{1 or -1; should the order of colors be reversed?}
\item{reverse_guide}{Boolean indicating whether the guide should be reversed.}
\item{...}{Additional arguments passed to [ggplot2::discrete_scale()] if discrete or [ggplot2::scale_fill_gradient()] if continuous.}
}
\description{
This function is based on [palette()]. If palette is NULL, the used palette will be magma from gpplot2's viridis scale constructors.
}

20
man/theme_bar.Rd Normal file
View file

@ -0,0 +1,20 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/theme_bar.R
\name{theme_bar}
\alias{theme_bar}
\title{Custom Theme for Bar Charts}
\usage{
theme_bar(
flip = TRUE,
add_text = FALSE,
axis_text_x_angle = 0,
axis_text_x_vjust = 0.5,
axis_text_x_hjust = 0.5
)
}
\value{
A custom theme object.
}
\description{
Custom Theme for Bar Charts
}

View file

@ -1,14 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/theme_bar.R
\name{theme_custom}
\alias{theme_custom}
\title{Custom Theme}
\usage{
theme_custom()
}
\value{
A custom theme object.
}
\description{
Create a custom theme for ggplot2.
}

View file

@ -1,21 +1,23 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/theme.R
\name{theme_visualizer_default}
\alias{theme_visualizer_default}
% Please edit documentation in R/theme_default.R
\name{theme_default}
\alias{theme_default}
\title{ggplot2 theme wrapper with fonts and colors}
\usage{
theme_visualizer_default(
font_family = "Carlito",
title_size = 14,
theme_default(
title_font_family = "Carlito",
title_size = 16,
title_color = color("dark_grey"),
title_font_face = "bold",
title_hjust = NULL,
title_position_to_plot = TRUE,
title_font_family = "Carlito",
subtitle_size = 13,
subtitle_font_face = "plain",
subtitle_font_family = "Carlito",
text_size = 12,
subtitle_size = 15,
subtitle_color = color("dark_grey"),
subtitle_font_face = "plain",
subtitle_hjust = NULL,
text_font_family = "Carlito",
text_size = 13,
text_color = color("dark_grey"),
text_font_face = "plain",
panel_background_color = "#FFFFFF",
@ -25,21 +27,29 @@ theme_visualizer_default(
legend_direction = "horizontal",
legend_justification = "center",
legend_reverse = TRUE,
legend_title_size = 12,
legend_title_size = 13,
legend_title_color = color("dark_grey"),
legend_title_font_face = "plain",
legend_text_size = 12,
legend_title_font_family = "Carlito",
legend_text_size = 13,
legend_text_color = color("dark_grey"),
legend_text_font_face = "plain",
legend_text_font_family = "Carlito",
facet_size = 14,
facet_color = color("dark_grey"),
facet_font_face = "bold",
facet_font_family = "Carlito",
facet_bg_color = color("lighter_grey"),
axis_x = TRUE,
axis_y = TRUE,
axis_text_x = TRUE,
axis_line_x = TRUE,
axis_ticks_x = TRUE,
axis_line_x = FALSE,
axis_ticks_x = FALSE,
axis_text_y = TRUE,
axis_line_y = TRUE,
axis_ticks_y = TRUE,
axis_text_size = 12,
axis_text_font_family = "Carlito",
axis_text_size = 13,
axis_text_color = color("dark_grey"),
axis_text_font_face = "plain",
axis_title_size = 15,
@ -53,19 +63,21 @@ theme_visualizer_default(
grid_major_color = color("dark_grey"),
grid_major_x_size = 0.1,
grid_major_y_size = 0.1,
grid_minor_x = FALSE,
grid_minor_x = TRUE,
grid_minor_y = FALSE,
grid_minor_color = color("dark_grey"),
grid_minor_x_size = 0.05,
grid_minor_y_size = 0.05,
caption_font_family = "Carlito",
caption_font_face = "plain",
caption_position_to_plot = TRUE,
caption_text_size = 10,
caption_text_color = color("dark_grey"),
caption_size = 11,
caption_color = color("dark_grey"),
...
)
}
\arguments{
\item{font_family}{The font family for all plot's texts. Default to "Segoe UI".}
\item{title_font_family}{Title font family. Default to "Roboto Condensed".}
\item{title_size}{The size of the legend title. Defaults to 11.}
@ -77,8 +89,6 @@ theme_visualizer_default(
\item{title_position_to_plot}{TRUE or FALSE. Positioning to plot or to panel?}
\item{title_font_family}{Title font family. Default to "Roboto Condensed".}
\item{text_size}{The size of all text other than the title, subtitle and caption. Defaults to 10.}
\item{text_color}{Text color.}
@ -169,7 +179,7 @@ theme_visualizer_default(
\item{...}{Additional arguments passed to [ggplot2::theme()].}
\item{p}{A ggplot2 object.}
\item{font_family}{The font family for all plot's texts. Default to "Segoe UI".}
}
\description{
Give some reach colors and fonts to a ggplot.

23
man/theme_point.Rd Normal file
View file

@ -0,0 +1,23 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/theme_point.R
\name{theme_point}
\alias{theme_point}
\title{Custom Theme for Point Charts}
\usage{
theme_point()
}
\arguments{
\item{flip}{Logical. Whether the plot is flipped (horizonal).}
\item{axis_text_x_angle}{Angle for x-axis text.}
\item{axis_text_x_vjust}{Vertical justification for x-axis text.}
\item{axis_text_x_hjust}{Horizontal justification for x-axis text.}
}
\value{
A custom theme object.
}
\description{
Custom Theme for Point Charts
}

View file

@ -1,16 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/theme_visualizer_bar.R
\docType{data}
\name{ThemeVisualizerBar}
\alias{ThemeVisualizerBar}
\title{ggplot2 theme for bar charts with sane defaults}
\format{
An object of class \code{ThemeVisualizerBar} (inherits from \code{ggproto}, \code{gg}) of length 1.
}
\usage{
ThemeVisualizerBar
}
\description{
ggplot2 theme for bar charts with sane defaults
}
\keyword{datasets}

View file

@ -1,33 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/theme_visualizer_bar.R
\name{theme_visualizer_bar}
\alias{theme_visualizer_bar}
\title{Dynamic Theme for ggplot2}
\usage{
theme_visualizer_bar()
}
\value{
A ggproto object that applies a dynamic theme to a ggplot2 plot.
}
\description{
A dynamic theme that adjusts axis text styles based on whether the plot is flipped.
}
\details{
This function dynamically applies different axis text styles depending on
the coordinate system of the plot. If the plot is flipped (e.g., using
`coord_flip()`), the x-axis and y-axis text styles are adjusted accordingly.
}
\examples{
library(ggplot2)
# Example with a regular plot
p <- ggplot(mpg, aes(displ, hwy)) +
geom_col()
# Add the dynamic theme
p + theme_visualizer_bar()
# Add the dynamic theme with a flipped coordinate system
p + theme_visualizer_bar() + coord_flip()
}

25
man/visualizeR-package.Rd Normal file
View file

@ -0,0 +1,25 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/visualizeR-package.R
\docType{package}
\name{visualizeR-package}
\alias{visualizeR}
\alias{visualizeR-package}
\title{visualizeR: What a color! What a viz!}
\description{
\if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}}
It basically provides colors as hex codes, color palettes, and some viz functions (graphs and maps).
}
\seealso{
Useful links:
\itemize{
\item \url{https://github.com/gnoblet/visualizeR}
\item \url{https://gnoblet.github.io/visualizeR/}
}
}
\author{
\strong{Maintainer}: Noblet Guillaume \email{gnoblet@zaclys.net}
}
\keyword{internal}