Compare commits

..

No commits in common. "main" and "revamp" have entirely different histories.
main ... revamp

42 changed files with 389 additions and 839 deletions

View file

@ -5,7 +5,6 @@
^\.github$
^\.pre-commit-config\.yaml$
^_pkgdown\.yml$
^codecov\.yml$
^data-raw$
^docs
^docs$
@ -16,4 +15,3 @@
^renv\.lock$
^renv\.lock$
^test-example.R
^test\.R$

1
.github/.gitignore vendored
View file

@ -1 +0,0 @@
*.html

View file

@ -1,32 +0,0 @@
## PR Description
<!-- Please include a summary of the changes and which issue is fixed or what feature is added -->
## Type of change
<!-- Please mark relevant options with [x] -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation update
- [ ] Code refactoring or style updates
## Checklist:
<!-- Please mark relevant options with [x] -->
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
## Notes for reviewers
<!-- Optional: Any notes or context that would be useful for the reviewer -->
## Automated Checks
The following checks will run automatically on this PR:
- R CMD check
- Documentation updates
- Test coverage
- Linting and style checks

View file

@ -1,56 +0,0 @@
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
name: R-CMD-check
jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
strategy:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check
- name: Document
run: |
install.packages("devtools")
devtools::document()
shell: Rscript {0}
if: github.event_name == 'pull_request'
- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true

View file

@ -1,40 +0,0 @@
# Workflow for linting and style checks
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
name: lint
jobs:
lint:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: |
any::lintr
any::styler
needs: lint
- name: Lint
run: |
lintr::lint_package()
shell: Rscript {0}
- name: Style check
run: |
if (!styler::style_pkg(dry = TRUE)) {
message("Some files are not properly styled!")
quit(status = 1)
}
shell: Rscript {0}

View file

@ -1,49 +0,0 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
release:
types: [published]
workflow_dispatch:
name: pkgdown.yaml
permissions: read-all
jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website
- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}
- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.5.0
with:
clean: false
branch: gh-pages
folder: docs

View file

@ -1,55 +0,0 @@
# Run test-coverage for visualizeR package
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
name: test-coverage
jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: |
any::covr
any::remotes
needs: coverage
- name: Install package
run: |
R CMD build .
R CMD INSTALL *.tar.gz
- name: Test coverage
run: |
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
)
shell: Rscript {0}
- name: Show testthat output
if: always()
run: |
## Print out test results details
find . -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash
- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package

View file

@ -16,6 +16,7 @@ Imports:
checkmate,
dplyr,
forcats,
ggalluvial,
ggplot2,
ggrepel,
ggtext,
@ -23,16 +24,18 @@ Imports:
grDevices,
rlang (>= 0.4.11),
scales,
tidyr
stringr,
tidyr,
viridisLite,
waffle
Suggests:
covr,
knitr,
rio,
rmarkdown,
roxygen2,
testthat (>= 3.0.0),
vdiffr,
withr
mockery
VignetteBuilder:
knitr
Config/testthat/edition: 3

116
R/bar.R
View file

@ -2,14 +2,13 @@
#'
#' @inheritParams bar
#'
#' @param ... Additional arguments passed to `bar()`
#'
#' @export
hbar <- function(
...,
flip = TRUE,
add_text = FALSE,
theme_fun = theme_bar(flip = flip, add_text = add_text)) {
...,
flip = TRUE,
add_text = FALSE,
theme_fun = theme_bar(flip = flip, add_text = add_text)
) {
bar(flip = flip, add_text = add_text, theme_fun = theme_fun, ...)
}
@ -49,8 +48,6 @@ hbar <- function(
#' @param add_text_expand_limit Default to adding 10\% on top of the bar.
#' @param add_text_round Round the text label.
#' @param theme_fun Whatever theme function. For no custom theme, use theme_fun = NULL.
#' @param scale_fill_fun Scale fill function. Default to scale_fill_visualizer_discrete().
#' @param scale_color_fun Scale color function. Default to scale_color_visualizer_discrete().
#'
#' @inheritParams reorder_by
#'
@ -58,47 +55,48 @@ hbar <- function(
#'
#' @export
bar <- function(
df,
x,
y,
group = "",
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,
x_title = NULL,
y_title = NULL,
group_title = NULL,
title = NULL,
subtitle = NULL,
caption = NULL,
width = 0.8,
add_text = FALSE,
add_text_size = 4.5,
add_text_color = color("dark_grey"),
add_text_font_face = "bold",
add_text_threshold_display = 0.05,
add_text_suffix = "%",
add_text_expand_limit = 1.2,
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()) {
df,
x,
y,
group = "",
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,
x_title = NULL,
y_title = NULL,
group_title = NULL,
title = NULL,
subtitle = NULL,
caption = NULL,
width = 0.8,
add_text = FALSE,
add_text_size = 4.5,
add_text_color = color("dark_grey"),
add_text_font_face = "bold",
add_text_threshold_display = 0.05,
add_text_suffix = "%",
add_text_expand_limit = 1.2,
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()
) {
#------ Checks
# df is a data frame
@ -351,7 +349,7 @@ bar <- function(
vjust_flip <- -0.5
}
# function for interactio
# function for interaction
interaction_f <- function(group, facet, data) {
if (group == "" && facet == "") {
return(NULL)
@ -368,7 +366,14 @@ bar <- function(
# add text labels
if (add_text & position == "dodge") {
df$y_threshold <- ifelse(df[[y]] >= add_text_threshold_display, df[[y]], NA)
df <- dplyr::mutate(
df,
"y_threshold" := ifelse(
!!rlang::sym(y) >= add_text_threshold_display,
!!rlang::sym(y),
NA
)
)
# expand limits
g <- g +
@ -402,7 +407,14 @@ bar <- function(
position = ggplot2::position_dodge2(width = dodge_width)
)
} else if (add_text & position == "stack") {
df$y_threshold <- ifelse(df[[y]] >= add_text_threshold_display, df[[y]], NA)
df <- dplyr::mutate(
df,
"y_threshold" := ifelse(
!!rlang::sym(y) >= add_text_threshold_display,
!!rlang::sym(y),
NA
)
)
g <- g +
ggplot2::geom_text(

View file

@ -1,25 +1,15 @@
# not in
#' Not In Operator
#'
#' A negation of the `%in%` operator that tests if elements of `a` are not in `b`.
#'
#' @param a Vector or value to test
#' @param b Vector to test against
#'
#' @return Logical vector with TRUE for elements of `a` that are not in `b`
`%notin%` <- function(a, b) {
!(a %in% b)
}
# not all in
#' Not All In Operator
#'
#' Tests if not all elements of `a` are contained in `b`.
#'
#' @param a Vector to test
#' @param b Vector to test against
#'
#' @return TRUE if at least one element of `a` is not in `b`, otherwise FALSE
`%notallin%` <- function(a, b) {
!(all(a %in% b))
}
# infix for null replacement
#' @importFrom rlang `%||%`
`%ifnullrep%` <- function(a, b) {
a %||% b
}

View file

@ -1,7 +1,6 @@
#' @rdname lollipop
#'
#' @inheritParams lollipop
#' @param ... Additional arguments passed to `lollipop()`
#'
#' @export
hlollipop <- function(
@ -13,7 +12,6 @@ hlollipop <- function(
#' Simple lollipop chart
#'
#' @description
#' `lollipop()` is a simple lollipop chart (dots connected to the baseline by a segment) with some customization allowed.
#' `hlollipop()` uses `lollipop()` with sane defaults for a horizontal lollipop chart.
#'
@ -43,24 +41,14 @@ hlollipop <- function(
#' @param line_color The color of the line connecting dots to the baseline.
#' @param dodge_width Width for position dodge when using groups (controls space between grouped lollipops).
#' @param theme_fun Whatever theme function. For no custom theme, use theme_fun = NULL.
#' @param scale_fill_fun Scale fill function. Default to scale_fill_visualizer_discrete().
#' @param scale_color_fun Scale color function. Default to scale_color_visualizer_discrete().
#'
#' @param scale_fill_fun Scale fill function.
#' @param scale_color_fun Scale color function.
#'
#' @inheritParams reorder_by
#'
#' @importFrom rlang `:=`
#'
#' @return A ggplot object
#' @export
#' @examples
#' \dontrun{
#' df <- data.frame(x = letters[1:5], y = c(10, 5, 7, 12, 8))
#' # Vertical lollipop
#' lollipop(df, "x", "y")
#' # Horizontal lollipop
#' hlollipop(df, "x", "y")
#' }
lollipop <- function(
df,
x,

View file

@ -22,35 +22,36 @@
#' @param subtitle Plot subtitle. Default to NULL.
#' @param caption Plot caption. Default to NULL.
#' @param theme_fun Whatever theme. Default to theme_point(). NULL if no theming needed.
#' @param scale_fill_fun Scale fill function. Default to scale_fill_visualizer_discrete().
#' @param scale_color_fun Scale color function. Default to scale_color_visualizer_discrete().
#'
#' @inheritParams scale_color_visualizer_discrete
#'
#' @export
point <- function(
df,
x,
y,
group = "",
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,
x_title = NULL,
y_title = NULL,
group_title = NULL,
title = NULL,
subtitle = NULL,
caption = NULL,
theme_fun = theme_point(),
scale_fill_fun = scale_fill_visualizer_discrete(),
scale_color_fun = scale_color_visualizer_discrete()) {
df,
x,
y,
group = "",
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,
x_title = NULL,
y_title = NULL,
group_title = NULL,
title = NULL,
subtitle = NULL,
caption = NULL,
theme_fun = theme_point(),
scale_fill_fun = scale_fill_visualizer_discrete(),
scale_color_fun = scale_color_visualizer_discrete()
) {
#------ Checks
# df is a data frame

View file

@ -5,16 +5,16 @@
#' @inheritParams palette_gen
#'
#' @param reverse_guide Boolean indicating whether the guide should be reversed.
#' @param title_position Position of the title. See [ggplot2::guide_legend()]'s title.position argument.
#' @param ... Additional arguments passed to [ggplot2::discrete_scale()] if discrete or [ggplot2::scale_fill_gradient()] if continuous.
#'
#' @export
scale_color_visualizer_discrete <- function(
palette = "cat_5_main",
direction = 1,
reverse_guide = TRUE,
title_position = NULL,
...) {
palette = "cat_5_main",
direction = 1,
reverse_guide = TRUE,
title_position = NULL,
...
) {
if (!(is.null(palette))) {
ggplot2::discrete_scale(
"color",
@ -47,11 +47,12 @@ scale_color_visualizer_discrete <- function(
#'
#' @export
scale_fill_visualizer_discrete <- function(
palette = "cat_5_main",
direction = 1,
reverse_guide = TRUE,
title_position = NULL,
...) {
palette = "cat_5_main",
direction = 1,
reverse_guide = TRUE,
title_position = NULL,
...
) {
if (!(is.null(palette))) {
ggplot2::discrete_scale(
"fill",
@ -84,11 +85,12 @@ scale_fill_visualizer_discrete <- function(
#'
#' @export
scale_fill_visualizer_continuous <- function(
palette = "seq_5_main",
direction = 1,
reverse_guide = TRUE,
title_position = NULL,
...) {
palette = "seq_5_main",
direction = 1,
reverse_guide = TRUE,
title_position = NULL,
...
) {
if (!(is.null(palette))) {
pal <- palette_gen(palette, "continuous", direction)
@ -122,11 +124,12 @@ scale_fill_visualizer_continuous <- function(
#'
#' @export
scale_color_visualizer_continuous <- function(
palette = "seq_5_main",
direction = 1,
reverse_guide = TRUE,
title_position = NULL,
...) {
palette = "seq_5_main",
direction = 1,
reverse_guide = TRUE,
title_position = NULL,
...
) {
if (!(is.null(palette))) {
pal <- palette_gen(palette, "continuous", direction)
@ -151,7 +154,7 @@ scale_color_visualizer_continuous <- function(
# ticks.colour = "#F1F3F5",
reverse = reverse_guide
),
...
....
)
}
}

View file

@ -2,18 +2,16 @@
#'
#' @return A custom theme object.
#'
#'
#' @rdname theme_default
#'
#' @inheritParams bar
#'
#' @export
theme_bar <- function(
flip = TRUE,
add_text = FALSE,
axis_text_x_angle = 0,
axis_text_x_vjust = 0.5,
axis_text_x_hjust = 0.5) {
flip = TRUE,
add_text = FALSE,
axis_text_x_angle = 0,
axis_text_x_vjust = 0.5,
axis_text_x_hjust = 0.5
) {
# If add_text is TRUE, flip is FALSE
if (!flip && !add_text) {
par_axis_text_font_face <- "plain"

View file

@ -1,17 +1,11 @@
#' ggplot2 theme wrapper with fonts and colors
#'
#' @param font_family The font family for all plot's texts. Default to "Segoe UI".
#' @param title_size The size of the title. Defaults to 12.
#' @param title_color Title color.
#' @param title_font_face Title font face. Default to "bold". Font face ("plain", "italic", "bold", "bold.italic").
#' @param title_hjust Title horizontal justification. Default to NULL. Use 0.5 to center the title.
#' @param title_font_family Title font family. Default to "Carlito".
#' @param title_position_to_plot TRUE or FALSE. Positioning to plot or to panel?
#' @param subtitle_font_family Subtitle font family. Default to "Carlito".
#' @param subtitle_size The size of the subtitle. Defaults to 10.
#' @param subtitle_color Subtitle color.
#' @param subtitle_font_face Subtitle font face. Default to "plain". Font face ("plain", "italic", "bold", "bold.italic").
#' @param subtitle_hjust Subtitle horizontal justification. Default to NULL. Use 0.5 to center the subtitle.
#' @param text_font_family Text font family. Default to "Carlito".
#' @param title_font_family Title font family. Default to "Roboto Condensed".
#' @param text_size The size of all text other than the title, subtitle and caption. Defaults to 10.
#' @param text_color Text color.
#' @param text_font_face Text font face. Default to "bold". Font face ("plain", "italic", "bold", "bold.italic").
@ -24,21 +18,16 @@
#' @param legend_title_size Legend title size.
#' @param legend_title_color Legend title color.
#' @param legend_title_font_face Legend title font face. Default to "plain". Font face ("plain", "italic", "bold", "bold.italic").
#' @param legend_title_font_family Legend title font family. Default to "Carlito".
#' @param legend_text_size Legend text size.
#' @param legend_text_color Legend text color.
#' @param legend_text_font_face Legend text font face. Default to "plain". Font face ("plain", "italic", "bold", "bold.italic").
#' @param legend_text_font_family Legend text font family. Default to "Carlito".
#'
#' @param legend_reverse Reverse the color in the guide? Default to TRUE.
#' @param facet_size Facet font size.
#' @param facet_color Facet font color.
#' @param facet_font_face Facet font face. Default to "plain". Font face ("plain", "italic", "bold", "bold.italic").
#' @param facet_font_family Facet font family. Default to "Carlito".
#' @param facet_bg_color Facet background color.
#' @param title_size The size of the legend title. Defaults to 11.
#' @param title_color Legend title color.
#' @param title_font_face Legend title font face. Default to "plain". Font face ("plain", "italic", "bold", "bold.italic").
#' @param title_position_to_plot TRUE or FALSE. Positioning to plot or to panel?
#' @param axis_x Boolean. Do you need x-axis?
#' @param axis_y Boolean. Do you need y-axis?
#' @param axis_text_font_family Axis text font family. Default to "Carlito".
#' @param axis_text_size Axis text size.
#' @param axis_text_color Axis text color.
#' @param axis_text_font_face Axis text font face. Default to "plain". Font face ("plain", "italic", "bold", "bold.italic").
@ -64,11 +53,7 @@
#' @param grid_minor_x_size Minor X line size.
#' @param grid_minor_y_size Minor Y line size.
#' @param grid_minor_color Minor grid lines color.
#' @param caption_font_family Caption font family. Default to "Carlito".
#' @param caption_font_face Caption font face. Default to "plain". Font face ("plain", "italic", "bold", "bold.italic").
#' @param caption_position_to_plot TRUE or FALSE. Positioning to plot or to panel?
#' @param caption_size The size of the caption. Defaults to 10.
#' @param caption_color Caption color.
#' @param ... Additional arguments passed to [ggplot2::theme()].
#'
#'
@ -76,75 +61,76 @@
#'
#' @export
theme_default <- function(
title_font_family = "Carlito",
title_size = 20,
title_color = color("dark_grey"),
title_font_face = "bold",
title_hjust = NULL,
title_position_to_plot = TRUE,
subtitle_font_family = "Carlito",
subtitle_size = 16,
subtitle_color = color("dark_grey"),
subtitle_font_face = "plain",
subtitle_hjust = NULL,
text_font_family = "Carlito",
text_size = 14,
text_color = color("dark_grey"),
text_font_face = "plain",
panel_background_color = "#FFFFFF",
panel_border = FALSE,
panel_border_color = color("dark_grey"),
legend_position = "top",
legend_direction = "horizontal",
legend_justification = "center",
legend_reverse = TRUE,
legend_title_size = 14,
legend_title_color = color("dark_grey"),
legend_title_font_face = "plain",
legend_title_font_family = "Carlito",
legend_text_size = 14,
legend_text_color = color("dark_grey"),
legend_text_font_face = "plain",
legend_text_font_family = "Carlito",
facet_size = 15,
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 = FALSE,
axis_ticks_x = FALSE,
axis_text_y = TRUE,
axis_line_y = TRUE,
axis_ticks_y = TRUE,
axis_text_font_family = "Carlito",
axis_text_size = 14,
axis_text_color = color("dark_grey"),
axis_text_font_face = "plain",
axis_title_size = 15,
axis_title_color = color("dark_grey"),
axis_title_font_face = "plain",
axis_text_x_angle = 0,
axis_text_x_vjust = 0.5,
axis_text_x_hjust = 0.5,
grid_major_x = TRUE,
grid_major_y = FALSE,
grid_major_color = color("dark_grey"),
grid_major_x_size = 0.1,
grid_major_y_size = 0.1,
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_size = 12,
caption_color = color("dark_grey"),
...) {
title_font_family = "Carlito",
title_size = 20,
title_color = color("dark_grey"),
title_font_face = "bold",
title_hjust = NULL,
title_position_to_plot = TRUE,
subtitle_font_family = "Carlito",
subtitle_size = 16,
subtitle_color = color("dark_grey"),
subtitle_font_face = "plain",
subtitle_hjust = NULL,
text_font_family = "Carlito",
text_size = 14,
text_color = color("dark_grey"),
text_font_face = "plain",
panel_background_color = "#FFFFFF",
panel_border = FALSE,
panel_border_color = color("dark_grey"),
legend_position = "top",
legend_direction = "horizontal",
legend_justification = "center",
legend_reverse = TRUE,
legend_title_size = 14,
legend_title_color = color("dark_grey"),
legend_title_font_face = "plain",
legend_title_font_family = "Carlito",
legend_text_size = 14,
legend_text_color = color("dark_grey"),
legend_text_font_face = "plain",
legend_text_font_family = "Carlito",
facet_size = 15,
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 = FALSE,
axis_ticks_x = FALSE,
axis_text_y = TRUE,
axis_line_y = TRUE,
axis_ticks_y = TRUE,
axis_text_font_family = "Carlito",
axis_text_size = 14,
axis_text_color = color("dark_grey"),
axis_text_font_face = "plain",
axis_title_size = 15,
axis_title_color = color("dark_grey"),
axis_title_font_face = "plain",
axis_text_x_angle = 0,
axis_text_x_vjust = 0.5,
axis_text_x_hjust = 0.5,
grid_major_x = TRUE,
grid_major_y = FALSE,
grid_major_color = color("dark_grey"),
grid_major_x_size = 0.1,
grid_major_y_size = 0.1,
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_size = 12,
caption_color = color("dark_grey"),
...
) {
# Basic simple theme
theme <- ggplot2::theme_minimal()

View file

@ -6,5 +6,8 @@
#'
#' @export
theme_dumbbell <- function() {
theme_default()
theme_default(
axis_line_x = TRUE,
grid_
)
}

View file

@ -1,27 +1,10 @@
#' Custom Theme for Lollipop Charts
#'
#' @description
#' A custom theme specifically designed for lollipop charts with appropriate grid lines and axis styling
#' based on whether the chart is flipped (horizontal) or not.
#'
#' @param flip Logical indicating whether the lollipop chart is flipped (horizontal). Default is TRUE.
#' @param axis_text_x_angle Angle for x-axis text labels. Default is 0.
#' @param axis_text_x_vjust Vertical justification for x-axis text labels. Default is 0.5.
#' @param axis_text_x_hjust Horizontal justification for x-axis text labels. Default is 0.5.
#'
#' @return A ggplot2 theme object
#' @return A custom theme object.
#'
#' @rdname theme_default
#' @export
#'
#' @examples
#' \dontrun{
#' library(ggplot2)
#' df <- data.frame(x = letters[1:5], y = c(10, 5, 7, 12, 8))
#' ggplot(df, aes(x, y)) +
#' geom_point() +
#' theme_lollipop()
#' }
#' @export
theme_lollipop <- function(
flip = TRUE,
axis_text_x_angle = 0,

View file

@ -22,14 +22,9 @@ desc <- setNames(as.list(desc), colnames(desc))
# `r desc$Package` <img src="man/figures/logo.png" align="right" width="120"/>
<!-- badges: start -->
[![R-CMD-check](https://github.com/gnoblet/visualizeR/actions/workflows/R-CMD-check.yml/badge.svg)](https://github.com/gnoblet/visualizeR/actions/workflows/R-CMD-check.yml)
[![Codecov test coverage](https://codecov.io/gh/gnoblet/visualizeR/branch/main/graph/badge.svg)](https://app.codecov.io/gh/gnoblet/visualizeR?branch=main)
<!-- badges: end -->
> `r desc$Title`
`visualizeR` proposes some utils to sane colors, ready-to-go color palettes, and a few visualization functions. The package is thoroughly tested with comprehensive code coverage.
`visualizeR` proposes some utils to sane colors, ready-to-go color palettes, and a few visualization functions.
## Installation
@ -45,23 +40,16 @@ devtools::install_github("gnoblet/visualizeR", build_vignettes = TRUE)
Roadmap is as follows:
- [ ] Full revamp of core functions (colors, pattern, incl. adding test and pre-commit structures)
- [x] Add test coverage reporting via codecov
- [ ] Maintain >80% test coverage across all functions
- [ ] Add other types of plots:
- [ ] Dumbell
- [ ] Waffle
- [ ] Donut
- [ ] Alluvial
- [ ] Option for tag with css code + for titles/subtitles/captions
## Request
Please, do not hesitate to pull request any new viz or colors or color palettes, or to email request any change ([gnoblet\@zaclys.net](mailto:gnoblet@zaclys.net){.email}).
## Code Coverage
`visualizeR` uses [codecov](https://codecov.io/) for test coverage reporting. You can see the current coverage status by clicking on the codecov badge at the top of this README. We aim to maintain high test coverage to ensure code reliability and stability.
## Colors
Functions to access colors and palettes are `color()` or `palette()`. Feel free to pull request new colors.
@ -267,6 +255,7 @@ lollipop(
y = "stat",
group = "group",
order = "grouped_y",
dodge_width = 0.8, # Control spacing between grouped lollipops
dot_size = 3.5,
line_size = 0.8,
y_title = "Value",
@ -280,6 +269,7 @@ hlollipop(
x = "admin1",
y = "stat",
group = "group",
dodge_width = 0.7, # Narrower spacing for horizontal orientation
dot_size = 3.5,
line_size = 0.8,
y_title = "Category",
@ -287,3 +277,15 @@ hlollipop(
title = "Horizontal side-by-side grouped lollipop chart"
)
```
## Lollipop Chart Features
Lollipop charts offer several advantages:
- Clean visualization of point data with connecting lines to a baseline
- True side-by-side grouped display for easy comparison between categories
- Each lollipop maintains its position from dot to baseline
- Customizable appearance with parameters for dot size, line width, and colors
- The `dodge_width` parameter controls spacing between grouped lollipops
The side-by-side positioning for grouped lollipops makes them visually distinct from dumbbell plots, which typically connect related points on the same line.

View file

@ -3,18 +3,10 @@
# visualizeR <img src="man/figures/logo.png" align="right" width="120"/>
<!-- badges: start -->
[![R-CMD-check](https://github.com/gnoblet/visualizeR/actions/workflows/R-CMD-check.yml/badge.svg)](https://github.com/gnoblet/visualizeR/actions/workflows/R-CMD-check.yml)
[![Codecov test
coverage](https://codecov.io/gh/gnoblet/visualizeR/branch/main/graph/badge.svg)](https://app.codecov.io/gh/gnoblet/visualizeR?branch=main)
<!-- badges: end -->
> What a color! What a viz!
`visualizeR` proposes some utils to sane colors, ready-to-go color
palettes, and a few visualization functions. The package is thoroughly
tested with comprehensive code coverage.
palettes, and a few visualization functions.
## Installation
@ -23,7 +15,7 @@ You can install the last version of visualizeR from
``` r
# install.packages("devtools")
devtools::install_github("gnoblet/visualizeR", build_vignettes = TRUE)
devtools::install_github('gnoblet/visualizeR', build_vignettes = TRUE)
```
## Roadmap
@ -32,27 +24,17 @@ Roadmap is as follows:
- [ ] Full revamp of core functions (colors, pattern, incl. adding test
and pre-commit structures)
- [x] Add test coverage reporting via codecov
- [ ] Maintain \>80% test coverage across all functions
- [ ] Add other types of plots:
- [ ] Dumbell
- [ ] Waffle
- [ ] Donut
- [ ] Alluvial
- [ ] Option for tag with css code + for titles/subtitles/captions
## Request
Please, do not hesitate to pull request any new viz or colors or color
palettes, or to email request any change (<gnoblet@zaclys.net>).
## Code Coverage
`visualizeR` uses [codecov](https://codecov.io/) for test coverage
reporting. You can see the current coverage status by clicking on the
codecov badge at the top of this README. We aim to maintain high test
coverage to ensure code reliability and stability.
## Colors
Functions to access colors and palettes are `color()` or `palette()`.
@ -69,7 +51,7 @@ color(unname = F)[1:10]
#> "#71716F" "#000000" "#ffc20a" "#0c7bdc" "#fefe62"
# Extract a color palette as hexadecimal codes and reversed
palette(palette = "cat_5_main", reversed = TRUE, color_ramp_palette = FALSE)
palette(palette = 'cat_5_main', reversed = TRUE, color_ramp_palette = FALSE)
#> [1] "#083d77" "#4ecdc4" "#f4c095" "#b47eb3" "#ffd5ff"
# Get all color palettes names
@ -109,7 +91,7 @@ df_island <- penguins |>
ungroup()
# Simple bar chart by group with some alpha transparency
bar(df, "island", "mean_bl", "species", x_title = "Mean of bill length", title = "Mean of bill length by island and species")
bar(df, 'island', 'mean_bl', 'species', x_title = 'Mean of bill length', title = 'Mean of bill length by island and species')
```
<img src="man/figures/README-example-bar-chart-1.png" width="65%" />
@ -117,7 +99,7 @@ bar(df, "island", "mean_bl", "species", x_title = "Mean of bill length", title =
``` r
# Flipped / Horizontal
hbar(df, "island", "mean_bl", "species", x_title = "Mean of bill length", title = "Mean of bill length by island and species")
hbar(df, 'island', 'mean_bl', 'species', x_title = 'Mean of bill length', title = 'Mean of bill length by island and species')
```
<img src="man/figures/README-example-bar-chart-2.png" width="65%" />
@ -125,7 +107,7 @@ hbar(df, "island", "mean_bl", "species", x_title = "Mean of bill length", title
``` r
# Facetted
bar(df, "island", "mean_bl", facet = "species", x_title = "Mean of bill length", title = "Mean of bill length by island and species", add_color_guide = FALSE)
bar(df, 'island', 'mean_bl', facet = 'species', x_title = 'Mean of bill length', title = 'Mean of bill length by island and species', add_color_guide = FALSE)
```
<img src="man/figures/README-example-bar-chart-3.png" width="65%" />
@ -133,7 +115,7 @@ bar(df, "island", "mean_bl", facet = "species", x_title = "Mean of bill length",
``` r
# Flipped, with text, smaller width, and caption
hbar(df = df_island, x = "island", y = "mean_bl", title = "Mean of bill length by island", add_text = T, width = 0.6, add_text_suffix = "mm", add_text_expand_limit = 1.3, add_color_guide = FALSE, caption = "Data: palmerpenguins package.")
hbar(df = df_island, x = 'island', y = 'mean_bl', title = 'Mean of bill length by island', add_text = T, width = 0.6, add_text_suffix = 'mm', add_text_expand_limit = 1.3, add_color_guide = FALSE, caption = "Data: palmerpenguins package.")
```
<img src="man/figures/README-example-bar-chart-4.png" width="65%" />
@ -142,7 +124,7 @@ hbar(df = df_island, x = "island", y = "mean_bl", title = "Mean of bill length b
``` r
# Simple scatterplot
point(penguins, "bill_length_mm", "flipper_length_mm")
point(penguins, 'bill_length_mm', 'flipper_length_mm')
```
<img src="man/figures/README-example-point-chart-1.png" width="65%" />
@ -150,7 +132,7 @@ point(penguins, "bill_length_mm", "flipper_length_mm")
``` r
# Scatterplot with grouping colors, greater dot size, some transparency
point(penguins, "bill_length_mm", "flipper_length_mm", "island", group_title = "Island", alpha = 0.6, size = 3, title = "Bill vs. flipper length", , add_color_guide = FALSE)
point(penguins, 'bill_length_mm', 'flipper_length_mm', 'island', group_title = 'Island', alpha = 0.6, size = 3, title = 'Bill vs. flipper length', , add_color_guide = FALSE)
```
<img src="man/figures/README-example-point-chart-2.png" width="65%" />
@ -158,7 +140,7 @@ point(penguins, "bill_length_mm", "flipper_length_mm", "island", group_title = "
``` r
# Facetted scatterplot by island
point(penguins, "bill_length_mm", "flipper_length_mm", "species", "island", "fixed", group_title = "Species", title = "Bill vs. flipper length by species and island", add_color_guide = FALSE)
point(penguins, 'bill_length_mm', 'flipper_length_mm', 'species', 'island', 'fixed', group_title = 'Species', title = 'Bill vs. flipper length by species and island', add_color_guide = FALSE)
```
<img src="man/figures/README-example-point-chart-3.png" width="65%" />
@ -173,7 +155,7 @@ values.
# Prepare long data
df <- tibble::tibble(
admin1 = rep(letters[1:8], 2),
setting = c(rep(c("Rural", "Urban"), 4), rep(c("Urban", "Rural"), 4)),
setting = c(rep(c('Rural', 'Urban'), 4), rep(c('Urban', 'Rural'), 4)),
stat = rnorm(16, mean = 50, sd = 18)
) |>
dplyr::mutate(stat = round(stat, 0))
@ -197,7 +179,7 @@ df <- tibble::tibble(
``` r
# Some summarized data: % of HHs by displacement status
df <- tibble::tibble(
status = c("Displaced", "Non displaced", "Returnee", "Don't know/Prefer not to say"),
status = c('Displaced', 'Non displaced', 'Returnee', 'Don\'t know/Prefer not to say'),
percentage = c(18, 65, 12, 3)
)
@ -227,12 +209,12 @@ df <- tibble::tibble(
# Some summarized data: % of HHs by self-reported status of displacement in 2021 and in 2022
df <- tibble::tibble(
status_from = c(
rep("Displaced", 4),
rep("Non displaced", 4),
rep("Returnee", 4),
rep("Dnk/Pnts", 4)
rep('Displaced', 4),
rep('Non displaced', 4),
rep('Returnee', 4),
rep('Dnk/Pnts', 4)
),
status_to = c("Displaced", "Non displaced", "Returnee", "Dnk/Pnts", "Displaced", "Non displaced", "Returnee", "Dnk/Pnts", "Displaced", "Non displaced", "Returnee", "Dnk/Pnts", "Displaced", "Non displaced", "Returnee", "Dnk/Pnts"),
status_to = c('Displaced', 'Non displaced', 'Returnee', 'Dnk/Pnts', 'Displaced', 'Non displaced', 'Returnee', 'Dnk/Pnts', 'Displaced', 'Non displaced', 'Returnee', 'Dnk/Pnts', 'Displaced', 'Non displaced', 'Returnee', 'Dnk/Pnts'),
percentage = c(20, 8, 18, 1, 12, 21, 0, 2, 0, 3, 12, 1, 0, 0, 1, 1)
)
@ -312,7 +294,7 @@ lollipop(
x = "admin1",
y = "stat",
group = "group",
order = "grouped_y",
dodge_width = 0.8, # Control spacing between grouped lollipops
dot_size = 3.5,
line_size = 0.8,
y_title = "Value",
@ -331,6 +313,7 @@ hlollipop(
x = "admin1",
y = "stat",
group = "group",
dodge_width = 0.7, # Narrower spacing for horizontal orientation
dot_size = 3.5,
line_size = 0.8,
y_title = "Category",
@ -340,3 +323,19 @@ hlollipop(
```
<img src="man/figures/README-example-lollipop-chart-4.png" width="65%" />
## Lollipop Chart Features
Lollipop charts offer several advantages:
- Clean visualization of point data with connecting lines to a baseline
- True side-by-side grouped display for easy comparison between
categories
- Each lollipop maintains its position from dot to baseline
- Customizable appearance with parameters for dot size, line width, and
colors
- The `dodge_width` parameter controls spacing between grouped lollipops
The side-by-side positioning for grouped lollipops makes them visually
distinct from dumbbell plots, which typically connect related points on
the same line.

View file

@ -1,14 +0,0 @@
comment: false
coverage:
status:
project:
default:
target: auto
threshold: 1%
informational: true
patch:
default:
target: auto
threshold: 1%
informational: true

View file

@ -1,13 +1,7 @@
aut
Carlito
CMD
codecov
Codecov
coercible
Config
covr
cre
css
Customizable
donut
Donut
@ -20,11 +14,9 @@ ggrepel
ggtext
github
gnoblet
gpplot
grDevices
grey
Guillaume
hbar
hlollipop
horizonal
https
@ -34,7 +26,6 @@ knitr
LazyData
Noblet
pre
README
rio
rlang
rmarkdown
@ -45,13 +36,10 @@ RoxygenNote
Segoe
stringr
testthat
theming
tidyr
UI
vdiffr
VignetteBuilder
viridis
viridisLite
visualizeR
withr
zaclys

View file

@ -52,8 +52,6 @@ bar(
)
}
\arguments{
\item{...}{Additional arguments passed to `bar()`}
\item{flip}{TRUE or FALSE (default). Default to TRUE or horizontal bar plot.}
\item{add_text}{TRUE or FALSE. Add values as text.}
@ -119,10 +117,6 @@ bar(
\item{add_text_expand_limit}{Default to adding 10\% on top of the bar.}
\item{add_text_round}{Round the text label.}
\item{scale_fill_fun}{Scale fill function. Default to scale_fill_visualizer_discrete().}
\item{scale_color_fun}{Scale color function. Default to scale_color_visualizer_discrete().}
}
\description{
`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.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 190 KiB

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 180 KiB

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 193 KiB

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 146 KiB

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 249 KiB

After

Width:  |  Height:  |  Size: 149 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 336 KiB

After

Width:  |  Height:  |  Size: 177 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 182 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 183 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 402 KiB

After

Width:  |  Height:  |  Size: 177 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 856 KiB

After

Width:  |  Height:  |  Size: 357 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 447 KiB

After

Width:  |  Height:  |  Size: 191 KiB

View file

@ -1,19 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/internals.R
\name{\%notallin\%}
\alias{\%notallin\%}
\title{Not All In Operator}
\usage{
a \%notallin\% b
}
\arguments{
\item{a}{Vector to test}
\item{b}{Vector to test against}
}
\value{
TRUE if at least one element of `a` is not in `b`, otherwise FALSE
}
\description{
Tests if not all elements of `a` are contained in `b`.
}

View file

@ -1,19 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/internals.R
\name{\%notin\%}
\alias{\%notin\%}
\title{Not In Operator}
\usage{
a \%notin\% b
}
\arguments{
\item{a}{Vector or value to test}
\item{b}{Vector to test against}
}
\value{
Logical vector with TRUE for elements of `a` that are not in `b`
}
\description{
A negation of the `%in%` operator that tests if elements of `a` are not in `b`.
}

View file

@ -1,119 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lollipop.R
\name{hlollipop}
\alias{hlollipop}
\alias{lollipop}
\title{Simple lollipop chart}
\usage{
hlollipop(..., flip = TRUE, theme_fun = theme_lollipop(flip = flip))
lollipop(
df,
x,
y,
group = "",
facet = "",
order = "y",
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,
alpha = 1,
x_title = NULL,
y_title = NULL,
group_title = NULL,
title = NULL,
subtitle = NULL,
caption = NULL,
dot_size = 4,
line_size = 0.8,
line_color = color("dark_grey"),
dodge_width = 0.9,
theme_fun = theme_lollipop(flip = flip, 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{...}{Additional arguments passed to `lollipop()`}
\item{flip}{TRUE or FALSE (default). Default to TRUE or horizontal lollipop plot.}
\item{theme_fun}{Whatever theme function. For no custom theme, use theme_fun = NULL.}
\item{df}{A data frame.}
\item{x}{A quoted character column or coercible as a character column.}
\item{y}{A quoted numeric column.}
\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}{A character scalar specifying the order type (one of "none", "y", "grouped"). See details.}
\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 dots (if no grouping).}
\item{add_color_guide}{Should a legend be added?}
\item{wrap}{Should x-labels be wrapped? Number of characters.}
\item{alpha}{Fill transparency for dots.}
\item{x_title}{The x scale title. Default to NULL.}
\item{y_title}{The y scale title. Default to NULL.}
\item{group_title}{The group legend title. Default to NULL.}
\item{title}{Plot title. Default to NULL.}
\item{subtitle}{Plot subtitle. Default to NULL.}
\item{caption}{Plot caption. Default to NULL.}
\item{dot_size}{The size of the dots.}
\item{line_size}{The size/width of the line connecting dots to the baseline.}
\item{line_color}{The color of the line connecting dots to the baseline.}
\item{dodge_width}{Width for position dodge when using groups (controls space between grouped lollipops).}
\item{scale_fill_fun}{Scale fill function. Default to scale_fill_visualizer_discrete().}
\item{scale_color_fun}{Scale color function. Default to scale_color_visualizer_discrete().}
}
\value{
A ggplot object
}
\description{
`lollipop()` is a simple lollipop chart (dots connected to the baseline by a segment) with some customization allowed.
`hlollipop()` uses `lollipop()` with sane defaults for a horizontal lollipop chart.
}
\examples{
\dontrun{
df <- data.frame(x = letters[1:5], y = c(10, 5, 7, 12, 8))
# Vertical lollipop
lollipop(df, "x", "y")
# Horizontal lollipop
hlollipop(df, "x", "y")
}
}

View file

@ -75,10 +75,6 @@ point(
\item{caption}{Plot caption. Default to NULL.}
\item{theme_fun}{Whatever theme. Default to theme_point(). NULL if no theming needed.}
\item{scale_fill_fun}{Scale fill function. Default to scale_fill_visualizer_discrete().}
\item{scale_color_fun}{Scale color function. Default to scale_color_visualizer_discrete().}
}
\description{
Simple scatterplot

View file

@ -46,8 +46,6 @@ scale_color_visualizer_continuous(
\item{reverse_guide}{Boolean indicating whether the guide should be reversed.}
\item{title_position}{Position of the title. See [ggplot2::guide_legend()]'s title.position argument.}
\item{...}{Additional arguments passed to [ggplot2::discrete_scale()] if discrete or [ggplot2::scale_fill_gradient()] if continuous.}
}
\description{

View file

@ -1,11 +1,10 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/theme_bar.R, R/theme_default.R,
% R/theme_dumbbell.R, R/theme_lollipop.R, R/theme_point.R
% R/theme_dumbbell.R, R/theme_point.R
\name{theme_bar}
\alias{theme_bar}
\alias{theme_default}
\alias{theme_dumbbell}
\alias{theme_lollipop}
\alias{theme_point}
\title{Custom Theme for Bar Charts}
\usage{
@ -19,18 +18,18 @@ theme_bar(
theme_default(
title_font_family = "Carlito",
title_size = 20,
title_size = 16,
title_color = color("dark_grey"),
title_font_face = "bold",
title_hjust = NULL,
title_position_to_plot = TRUE,
subtitle_font_family = "Carlito",
subtitle_size = 16,
subtitle_size = 15,
subtitle_color = color("dark_grey"),
subtitle_font_face = "plain",
subtitle_hjust = NULL,
text_font_family = "Carlito",
text_size = 14,
text_size = 13,
text_color = color("dark_grey"),
text_font_face = "plain",
panel_background_color = "#FFFFFF",
@ -40,15 +39,15 @@ theme_default(
legend_direction = "horizontal",
legend_justification = "center",
legend_reverse = TRUE,
legend_title_size = 14,
legend_title_size = 13,
legend_title_color = color("dark_grey"),
legend_title_font_face = "plain",
legend_title_font_family = "Carlito",
legend_text_size = 14,
legend_text_size = 13,
legend_text_color = color("dark_grey"),
legend_text_font_face = "plain",
legend_text_font_family = "Carlito",
facet_size = 15,
facet_size = 14,
facet_color = color("dark_grey"),
facet_font_face = "bold",
facet_font_family = "Carlito",
@ -62,7 +61,7 @@ theme_default(
axis_line_y = TRUE,
axis_ticks_y = TRUE,
axis_text_font_family = "Carlito",
axis_text_size = 14,
axis_text_size = 13,
axis_text_color = color("dark_grey"),
axis_text_font_face = "plain",
axis_title_size = 15,
@ -84,26 +83,17 @@ theme_default(
caption_font_family = "Carlito",
caption_font_face = "plain",
caption_position_to_plot = TRUE,
caption_size = 12,
caption_size = 11,
caption_color = color("dark_grey"),
...
)
theme_dumbbell()
theme_lollipop(
flip = TRUE,
axis_text_x_angle = 0,
axis_text_x_vjust = 0.5,
axis_text_x_hjust = 0.5
)
theme_point()
}
\arguments{
\item{flip}{Logical. Whether the plot is flipped (horizontal).}
\item{add_text}{TRUE or FALSE. Add values as text.}
\item{flip}{Logical. Whether the plot is flipped (horizonal).}
\item{axis_text_x_angle}{Angle for x-axis text.}
@ -111,30 +101,18 @@ theme_point()
\item{axis_text_x_hjust}{Horizontal justification for x-axis text.}
\item{title_font_family}{Title font family. Default to "Carlito".}
\item{title_font_family}{Title font family. Default to "Roboto Condensed".}
\item{title_size}{The size of the title. Defaults to 12.}
\item{title_size}{The size of the legend title. Defaults to 11.}
\item{title_color}{Title color.}
\item{title_color}{Legend title color.}
\item{title_font_face}{Title font face. Default to "bold". Font face ("plain", "italic", "bold", "bold.italic").}
\item{title_font_face}{Legend title font face. Default to "plain". Font face ("plain", "italic", "bold", "bold.italic").}
\item{title_hjust}{Title horizontal justification. Default to NULL. Use 0.5 to center the title.}
\item{title_position_to_plot}{TRUE or FALSE. Positioning to plot or to panel?}
\item{subtitle_font_family}{Subtitle font family. Default to "Carlito".}
\item{subtitle_size}{The size of the subtitle. Defaults to 10.}
\item{subtitle_color}{Subtitle color.}
\item{subtitle_font_face}{Subtitle font face. Default to "plain". Font face ("plain", "italic", "bold", "bold.italic").}
\item{subtitle_hjust}{Subtitle horizontal justification. Default to NULL. Use 0.5 to center the subtitle.}
\item{text_font_family}{Text font family. Default to "Carlito".}
\item{text_size}{The size of all text other than the title, subtitle and caption. Defaults to 10.}
\item{text_color}{Text color.}
@ -161,26 +139,12 @@ theme_point()
\item{legend_title_font_face}{Legend title font face. Default to "plain". Font face ("plain", "italic", "bold", "bold.italic").}
\item{legend_title_font_family}{Legend title font family. Default to "Carlito".}
\item{legend_text_size}{Legend text size.}
\item{legend_text_color}{Legend text color.}
\item{legend_text_font_face}{Legend text font face. Default to "plain". Font face ("plain", "italic", "bold", "bold.italic").}
\item{legend_text_font_family}{Legend text font family. Default to "Carlito".}
\item{facet_size}{Facet font size.}
\item{facet_color}{Facet font color.}
\item{facet_font_face}{Facet font face. Default to "plain". Font face ("plain", "italic", "bold", "bold.italic").}
\item{facet_font_family}{Facet font family. Default to "Carlito".}
\item{facet_bg_color}{Facet background color.}
\item{axis_x}{Boolean. Do you need x-axis?}
\item{axis_y}{Boolean. Do you need y-axis?}
@ -197,8 +161,6 @@ theme_point()
\item{axis_ticks_y}{Boolean. Do you need the line for the y-axis?}
\item{axis_text_font_family}{Axis text font family. Default to "Carlito".}
\item{axis_text_size}{Axis text size.}
\item{axis_text_color}{Axis text color.}
@ -231,39 +193,19 @@ theme_point()
\item{grid_minor_y_size}{Minor Y line size.}
\item{caption_font_family}{Caption font family. Default to "Carlito".}
\item{caption_font_face}{Caption font face. Default to "plain". Font face ("plain", "italic", "bold", "bold.italic").}
\item{caption_position_to_plot}{TRUE or FALSE. Positioning to plot or to panel?}
\item{caption_size}{The size of the caption. Defaults to 10.}
\item{caption_color}{Caption color.}
\item{...}{Additional arguments passed to [ggplot2::theme()].}
\item{font_family}{The font family for all plot's texts. Default to "Segoe UI".}
}
\value{
A custom theme object.
A ggplot2 theme object
A custom theme object.
}
\description{
Give some reach colors and fonts to a ggplot.
Theme for dumbbell charts based on theme_default.
A custom theme specifically designed for lollipop charts with appropriate grid lines and axis styling
based on whether the chart is flipped (horizontal) or not.
}
\examples{
\dontrun{
library(ggplot2)
df <- data.frame(x = letters[1:5], y = c(10, 5, 7, 12, 8))
ggplot(df, aes(x, y)) +
geom_point() +
theme_lollipop()
}
}

View file

@ -1,12 +1,12 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html
# # This file is part of the standard setup for testthat.
# # It is recommended that you do not modify it.
# #
# # Where should you do additional test configuration?
# # Learn more about the roles of various files in:
# # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# # * https://testthat.r-lib.org/articles/special-files.html
library(testthat)
library(visualizeR)
# library(testthat)
# library(visualizeR)
test_check("visualizeR")
# test_check("visualizeR")

View file

@ -47,28 +47,41 @@ test_that("palette_gen returns appropriate function types", {
expect_true(is.function(div_fn))
})
test_that("palette_gen dispatches to correct function types", {
# Test for categorical type
cat_result <- palette_gen("cat_5_main", "categorical", direction = -1)
expect_true(is.function(cat_result))
test_that("palette_gen forwards arguments to appropriate function", {
# Skip the test if mockery is not available
skip_if_not_installed("mockery")
skip_if_not(exists("with_mocked_bindings"))
# Verify it behaves like a categorical palette function
expect_equal(length(cat_result(3)), 3)
expect_type(cat_result(3), "character")
# Create a mock for palette_gen_categorical
mockery::with_mocked_bindings(
palette_gen_categorical = function(palette, direction) {
return(list(
palette = palette,
direction = direction,
type = "categorical"
))
},
palette_gen_sequential = function(palette, direction, ...) {
return(list(
palette = palette,
direction = direction,
type = "sequential"
))
},
code = {
# Test categorical forwarding
result <- palette_gen("cat_palette", "categorical", direction = -1)
expect_equal(result$palette, "cat_palette")
expect_equal(result$direction, -1)
expect_equal(result$type, "categorical")
# Test for sequential type
seq_result <- palette_gen("cat_5_main", "sequential", direction = -1)
expect_true(is.function(seq_result))
# Verify it behaves like a sequential palette function
expect_equal(length(seq_result(5)), 5)
expect_type(seq_result(5), "character")
# Test for divergent type - should work like sequential
div_result <- palette_gen("div_5_orange_blue", "divergent", direction = -1)
expect_true(is.function(div_result))
expect_equal(length(div_result(7)), 7)
expect_type(div_result(7), "character")
# Test sequential forwarding
result <- palette_gen("seq_palette", "sequential", direction = -1)
expect_equal(result$palette, "seq_palette")
expect_equal(result$direction, -1)
expect_equal(result$type, "sequential")
}
)
})
test_that("palette_gen_categorical validates parameters", {

57
vignettes/bar_charts.Rmd Normal file
View file

@ -0,0 +1,57 @@
---
title: "Bar charts"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Bar charts}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
Let's start by importing some data and running some data wrangling:
```{r data-import}
library(rio)
library(data.table)
dat <- import("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/11_SevCatOneNumNestedOneObsPerGroup.csv", data.table = TRUE)
setDT(dat)
# in all character columns, tranform empty string to NA
vars_chr <- colnames(dat)[sapply(dat, is.character)]
dat[, (vars_chr) := lapply(.SD, function(x) fifelse(x == "", NA_character_, x)), .SDcols = vars_chr]
# in value, if -1 replace with NA
dat[, value := fifelse(value == -1, NA_real_, value)]
# remove lines where value is NA (in place)
dat <- dat[!is.na(value), ]
# kepp only top 20 values and divide data to get million units
df <- dat[
!is.na(value), ][
order(value, decreasing = TRUE), ][
1:20, ][
, value := value/1000000, ][
, key := ifelse(key == "Democratic Republic of the Congo", "DRC", key)]
```
Now, let's see the defaults for a horizontal bar diagram without any grouping and ordering values from highest to smallest:
```{r hbar}
library(visualizeR)
hbar(
df,
x = "key",
y = "value",
facet = "region",
order = "y",
title = "Top 20 countries by population (in Million)"
)
```
Moving on to a vertical bar chart, with country facets and groups