diff --git a/DESCRIPTION b/DESCRIPTION index f0d7892..3578f79 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Type: Package Package: visualizeR Title: What a color! What a viz! Version: 1.0 -Authors@R: +Authors@R: person("Noblet", "Guillaume", , "gnoblet@zaclys.net", role = c("aut", "cre")) Maintainer: Guillaume Noblet Description: It basically provides colors as hex codes, color palettes, @@ -10,9 +10,9 @@ Description: It basically provides colors as hex codes, color palettes, License: GPL (>= 3) URL: https://github.com/gnoblet/visualizeR, https://gnoblet.github.io/visualizeR/ -Depends: +Depends: R (>= 4.1.0) -Imports: +Imports: checkmate, dplyr, forcats, @@ -28,7 +28,8 @@ Imports: tidyr, viridisLite, waffle -Suggests: +Suggests: + covr, knitr, rio, rmarkdown, @@ -36,7 +37,7 @@ Suggests: testthat (>= 3.0.0), vdiffr, mockery -VignetteBuilder: +VignetteBuilder: knitr Config/testthat/edition: 3 Encoding: UTF-8 diff --git a/README.Rmd b/README.Rmd index 53a26d5..04696df 100644 --- a/README.Rmd +++ b/README.Rmd @@ -22,9 +22,14 @@ desc <- setNames(as.list(desc), colnames(desc)) # `r desc$Package` + +[![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) + + > `r desc$Title` -`visualizeR` proposes some utils to sane colors, ready-to-go color palettes, and a few visualization functions. +`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. ## Installation @@ -40,6 +45,8 @@ 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 @@ -50,6 +57,10 @@ Roadmap is as follows: 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. diff --git a/README.md b/README.md index 5e043eb..24a0d5f 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,39 @@ +--- +output: github_document +--- + + # visualizeR + +[![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) + + > What a color! What a viz! -`visualizeR` proposes some utils to sane colors, ready-to-go color -palettes, and a few visualization functions. +`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. ## Installation -You can install the last version of visualizeR from -[GitHub](https://github.com/) with: +You can install the last version of visualizeR from [GitHub](https://github.com/) with: + ``` r # install.packages("devtools") -devtools::install_github('gnoblet/visualizeR', build_vignettes = TRUE) +devtools::install_github("gnoblet/visualizeR", build_vignettes = TRUE) ``` ## Roadmap Roadmap is as follows: -- [ ] Full revamp of core functions (colors, pattern, incl. adding test - and pre-commit structures) +- [ ] 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 @@ -32,13 +42,16 @@ Roadmap is as follows: ## Request -Please, do not hesitate to pull request any new viz or colors or color -palettes, or to email request any change (). +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. +Functions to access colors and palettes are `color()` or `palette()`. Feel free to pull request new colors. + ``` r library(visualizeR) @@ -51,7 +64,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 @@ -70,6 +83,7 @@ palette(show_palettes = TRUE) ### Example 1: Bar chart + ``` r library(palmerpenguins) library(dplyr) @@ -91,71 +105,92 @@ 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") ``` - +
+plot of chunk example-bar-chart +

plot of chunk example-bar-chart

+
``` 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") ``` - +
+plot of chunk example-bar-chart +

plot of chunk example-bar-chart

+
``` 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) ``` - +
+plot of chunk example-bar-chart +

plot of chunk example-bar-chart

+
``` 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.") ``` - +
+plot of chunk example-bar-chart +

plot of chunk example-bar-chart

+
### Example 2: Scatterplot + ``` r # Simple scatterplot -point(penguins, 'bill_length_mm', 'flipper_length_mm') +point(penguins, "bill_length_mm", "flipper_length_mm") ``` - +
+plot of chunk example-point-chart +

plot of chunk example-point-chart

+
``` 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) ``` - +
+plot of chunk example-point-chart +

plot of chunk example-point-chart

+
``` 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) ``` - +
+plot of chunk example-point-chart +

plot of chunk example-point-chart

+
### Example 3: Dumbbell plot -Remember to ensure that your data are in the long format and you only -have two groups on the x-axis; for instance, IDP and returnee and no NA -values. +Remember to ensure that your data are in the long format and you only have two groups on the x-axis; for instance, IDP and returnee and no NA values. + ``` r # 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)) @@ -176,10 +211,11 @@ df <- tibble::tibble( ### Example 4: donut chart + ``` 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) ) @@ -198,6 +234,7 @@ df <- tibble::tibble( ### Example 5: Waffle chart + ``` r # # waffle(df, status, percentage, x_title = 'A caption', title = 'A title', subtitle = 'A subtitle') @@ -205,16 +242,17 @@ df <- tibble::tibble( ### Example 6: Alluvial chart + ``` r # 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) ) @@ -234,6 +272,7 @@ df <- tibble::tibble( ### Example 7: Lollipop chart + ``` r library(tidyr) # Prepare long data @@ -256,7 +295,10 @@ lollipop( ) ``` - +
+plot of chunk example-lollipop-chart +

plot of chunk example-lollipop-chart

+
``` r @@ -275,7 +317,10 @@ hlollipop( ) ``` - +
+plot of chunk example-lollipop-chart +

plot of chunk example-lollipop-chart

+
``` r @@ -294,7 +339,8 @@ lollipop( x = "admin1", y = "stat", group = "group", - dodge_width = 0.8, # Control spacing between grouped lollipops + order = "grouped_y", + dodge_width = 0.8, # Control spacing between grouped lollipops dot_size = 3.5, line_size = 0.8, y_title = "Value", @@ -303,7 +349,10 @@ lollipop( ) ``` - +
+plot of chunk example-lollipop-chart +

plot of chunk example-lollipop-chart

+
``` r @@ -313,7 +362,7 @@ hlollipop( x = "admin1", y = "stat", group = "group", - dodge_width = 0.7, # Narrower spacing for horizontal orientation + dodge_width = 0.7, # Narrower spacing for horizontal orientation dot_size = 3.5, line_size = 0.8, y_title = "Category", @@ -322,20 +371,19 @@ hlollipop( ) ``` - +
+plot of chunk example-lollipop-chart +

plot of chunk example-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 +- 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 +- 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. +The side-by-side positioning for grouped lollipops makes them visually distinct from dumbbell plots, which typically connect related points on the same line. diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..04c5585 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,14 @@ +comment: false + +coverage: + status: + project: + default: + target: auto + threshold: 1% + informational: true + patch: + default: + target: auto + threshold: 1% + informational: true diff --git a/inst/WORDLIST b/inst/WORDLIST index 1fc78c6..8c051b2 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,7 +1,10 @@ aut CMD +codecov +Codecov coercible Config +covr cre Customizable donut @@ -27,6 +30,7 @@ knitr LazyData Noblet pre +README rio rlang rmarkdown diff --git a/man/figures/README-example-bar-chart-1.png b/man/figures/README-example-bar-chart-1.png index 9d1abb0..1cfaee3 100644 Binary files a/man/figures/README-example-bar-chart-1.png and b/man/figures/README-example-bar-chart-1.png differ diff --git a/man/figures/README-example-bar-chart-2.png b/man/figures/README-example-bar-chart-2.png index 08e0c94..a8f9c56 100644 Binary files a/man/figures/README-example-bar-chart-2.png and b/man/figures/README-example-bar-chart-2.png differ diff --git a/man/figures/README-example-bar-chart-3.png b/man/figures/README-example-bar-chart-3.png index 950a898..e69de29 100644 Binary files a/man/figures/README-example-bar-chart-3.png and b/man/figures/README-example-bar-chart-3.png differ diff --git a/man/figures/README-example-bar-chart-4.png b/man/figures/README-example-bar-chart-4.png index 87958f9..e35112d 100644 Binary files a/man/figures/README-example-bar-chart-4.png and b/man/figures/README-example-bar-chart-4.png differ diff --git a/man/figures/README-example-lollipop-chart-1.png b/man/figures/README-example-lollipop-chart-1.png index 0decaf1..402b3d5 100644 Binary files a/man/figures/README-example-lollipop-chart-1.png and b/man/figures/README-example-lollipop-chart-1.png differ diff --git a/man/figures/README-example-lollipop-chart-2.png b/man/figures/README-example-lollipop-chart-2.png index 0897e8e..e69de29 100644 Binary files a/man/figures/README-example-lollipop-chart-2.png and b/man/figures/README-example-lollipop-chart-2.png differ diff --git a/man/figures/README-example-lollipop-chart-3.png b/man/figures/README-example-lollipop-chart-3.png new file mode 100644 index 0000000..a7e1056 Binary files /dev/null and b/man/figures/README-example-lollipop-chart-3.png differ diff --git a/man/figures/README-example-lollipop-chart-4.png b/man/figures/README-example-lollipop-chart-4.png new file mode 100644 index 0000000..4410aa6 Binary files /dev/null and b/man/figures/README-example-lollipop-chart-4.png differ diff --git a/man/figures/README-example-point-chart-1.png b/man/figures/README-example-point-chart-1.png index f92acd7..58e2416 100644 Binary files a/man/figures/README-example-point-chart-1.png and b/man/figures/README-example-point-chart-1.png differ diff --git a/man/figures/README-example-point-chart-2.png b/man/figures/README-example-point-chart-2.png index df4c459..e69de29 100644 Binary files a/man/figures/README-example-point-chart-2.png and b/man/figures/README-example-point-chart-2.png differ diff --git a/man/figures/README-example-point-chart-3.png b/man/figures/README-example-point-chart-3.png index 218e708..e69de29 100644 Binary files a/man/figures/README-example-point-chart-3.png and b/man/figures/README-example-point-chart-3.png differ diff --git a/tests/testthat.R b/tests/testthat.R index fc6a44f..ffac804 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -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")