diff --git a/DESCRIPTION b/DESCRIPTION index 19b3f61..2fed535 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: visualizeR Type: Package Title: What a color! What a viz! -Version: 0.7.9000 +Version: 0.8.9000 Authors@R: c( person( 'Noblet', 'Guillaume', @@ -20,7 +20,7 @@ LazyData: true RoxygenNote: 7.2.3 Imports: ggplot2, - rlang, + rlang (>= 0.4.11), grDevices, glue, scales, @@ -29,8 +29,11 @@ Imports: tidyr, dplyr, ggalluvial, - viridisLite -Remotes: - github::hrbrmstr/waffle -Suggests: knitr, sf, tmap + viridisLite, + waffle +Suggests: + knitr, + roxygen2, + sf, + tmap VignetteBuilder: knitr diff --git a/NEWS.md b/NEWS.md index fc1aa03..61ad5bf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,13 @@ -# visualizeR 0.6.9000 +# visualizeR 0.8.9000 + +* Add `waffle()`. +* Add a `pal_default()` function as a fallback for scale functions and as an initiative in `theme_reach()`. It uses `viridis::magma()`. +* Update of AGORA palettes. +* Some other small bug fixes. + +--- + +# visualizeR 0.7.9000 * Add `dumbbell()`. * Add `alluvial()` diff --git a/README.md b/README.md index c2e6914..0e24eb5 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # visualizeR -> What a color! What a viz! +> What a color\! What a viz\! `visualizeR` proposes some utils to get REACH and AGORA colors, ready-to-go color palettes, and a few visualization functions @@ -23,16 +23,16 @@ devtools::install_github("gnoblet/visualizeR", build_vignettes = TRUE) Roadmap is as follows: -- [x] Add IMPACT’s colors -- [x] Add all color palettes from the internal documentation -- [ ] There remains to be added more-than-7-color palettes and black + - \[X\] Add IMPACT’s colors + - \[X\] Add all color palettes from the internal documentation + - \[ \] There remains to be added more-than-7-color palettes and black color palettes -- [x] Add new types of visualization (e.g. dumbbell plot, lollipop + - \[X\] Add new types of visualization (e.g. dumbbell plot, lollipop plot, etc.) -- [x] Use examples -- [ ] Add some ease-map functions -- [ ] Add some interactive functions (maps and graphs) -- [ ] Consolidate and make errors transparent + - \[X\] Use examples + - \[ \] Add some ease-map functions + - \[ \] Add some interactive functions (maps and graphs) + - \[ \] Consolidate and make errors transparent ## Request @@ -98,6 +98,7 @@ bar(df, island, mean_bl, species, percent = FALSE, alpha = 0.6, x_title = "Mean ``` r + # Using another color palette through `theme_reach()` and changing scale to percent bar(df, island,mean_bl, species, percent = TRUE, theme = theme_reach(palette = "artichoke_3")) ``` @@ -105,6 +106,7 @@ bar(df, island,mean_bl, species, percent = TRUE, theme = theme_reach(palette = " ``` r + # Not flipped, with text added, group_title, no y-axis and no bold for legend bar(df, island, mean_bl, species, group_title = "Species", flip = FALSE, add_text = TRUE, add_text_suffix = "%", percent = FALSE, theme = theme_reach(text_font_face = "plain", axis_y = FALSE)) ``` @@ -117,6 +119,7 @@ At this stage, `point_reach()` only supports categorical grouping colors with the `group` arg. ``` r + # Simple point chart point(penguins, bill_length_mm, flipper_length_mm) ``` @@ -124,6 +127,7 @@ point(penguins, bill_length_mm, flipper_length_mm) ``` r + # Point chart with grouping colors, greater dot size, some transparency, reversed color palette point(penguins, bill_length_mm, flipper_length_mm, island, alpha = 0.6, size = 3, theme = theme_reach(reverse = TRUE)) ``` @@ -131,6 +135,7 @@ point(penguins, bill_length_mm, flipper_length_mm, island, alpha = 0.6, size = 3 ``` r + # Using another color palettes point(penguins, bill_length_mm, flipper_length_mm, island, size = 1.5, x_title = "Bill", y_title = "Flipper", title = "Length (mm)", theme = theme_reach(palette = "artichoke_3", text_font_face = , grid_major_x = TRUE, title_position_to_plot = FALSE)) ``` @@ -153,6 +158,7 @@ df <- tibble::tibble( dplyr::mutate(stat = round(stat, 0)) # Example, adding a parameter to `theme_reach()` passed on `ggplot2::theme()` to align legend title + dumbbell(df, stat, setting, @@ -175,9 +181,10 @@ dumbbell(df, -### Example 4: donut chart, REACH themed (to used moderately) +### Example 4: donut chart, REACH themed (to used once, not twice) ``` 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"), @@ -199,9 +206,19 @@ donut(df, -### Example 5: alluvial chart, REACH themed +### Example 5: waffle chart ``` r +# +waffle(df, status, percentage, x_title = "A caption", title = "A title", subtitle = "A subtitle") +``` + + + +### Example 6: alluvial chart, REACH themed + +``` 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), @@ -230,7 +247,7 @@ alluvial(df, -### Example 6: lollipop chart +### Example 7: lollipop chart ``` r library(tidyr) @@ -260,6 +277,7 @@ lollipop(df, ``` r + # Horizontal, greater point size, arranged by value, no grid, and text labels added lollipop(df, admin1, @@ -281,6 +299,7 @@ lollipop(df, ## Maps ``` r + # Add indicator layer # - based on "pretty" classes and title "Proportion (%)" # - buffer to add a 10% around the bounding box diff --git a/man/figures/README-example-alluvial-plot-1.png b/man/figures/README-example-alluvial-plot-1.png index f1c9284..33a0499 100644 Binary files a/man/figures/README-example-alluvial-plot-1.png and b/man/figures/README-example-alluvial-plot-1.png differ diff --git a/man/figures/README-example-bar-chart-1.png b/man/figures/README-example-bar-chart-1.png index 246c204..cc3c997 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 f7a82d5..e5cbaad 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 4066025..f4b8b7e 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-donut-plot-1.png b/man/figures/README-example-donut-plot-1.png index 06aaf7a..d30c943 100644 Binary files a/man/figures/README-example-donut-plot-1.png and b/man/figures/README-example-donut-plot-1.png differ diff --git a/man/figures/README-example-dumbbell-plot-1.png b/man/figures/README-example-dumbbell-plot-1.png index 9236eb9..06ead24 100644 Binary files a/man/figures/README-example-dumbbell-plot-1.png and b/man/figures/README-example-dumbbell-plot-1.png differ diff --git a/man/figures/README-example-lollipop-chart-1.png b/man/figures/README-example-lollipop-chart-1.png index 2bc316c..0decaf1 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 d6c4582..0897e8e 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-map.png b/man/figures/README-example-map.png index eb3162e..3e671f9 100644 Binary files a/man/figures/README-example-map.png and b/man/figures/README-example-map.png differ diff --git a/man/figures/README-example-point-chart-1.png b/man/figures/README-example-point-chart-1.png index de23c88..f705a3d 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 9bfbd50..76ef877 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 d802343..b32aa89 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/man/figures/README-example-waffke-plot-1.png b/man/figures/README-example-waffke-plot-1.png new file mode 100644 index 0000000..a750983 Binary files /dev/null and b/man/figures/README-example-waffke-plot-1.png differ diff --git a/man/figures/README-example-waffle-plot-1.png b/man/figures/README-example-waffle-plot-1.png new file mode 100644 index 0000000..0183c5a Binary files /dev/null and b/man/figures/README-example-waffle-plot-1.png differ diff --git a/man/pal_fallback.Rd b/man/pal_fallback.Rd new file mode 100644 index 0000000..6716ae5 --- /dev/null +++ b/man/pal_fallback.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pal_fallback.R +\name{pal_fallback} +\alias{pal_fallback} +\title{Return function to interpolate a fallback palette base on viridis::magma()} +\usage{ +pal_fallback( + reverse = FALSE, + color_ramp_palette = FALSE, + discrete = FALSE, + n = 5, + ... +) +} +\arguments{ +\item{reverse}{Boolean indicating whether the palette should be reversed} + +\item{color_ramp_palette}{Should the output be a `grDevices::colorRampPalette` function or a vector of hex codes? Default to the latter with `FALSE`} + +\item{discrete}{Boolean. Discrete or not? Default to FALSE.} + +\item{n}{Number of colors in the palette. Default to 5. Passe to `viridis::magma()`} + +\item{...}{Other parameters to pass to `grDevices::colorRampPalette()`} +} +\value{ +A color palette +} +\description{ +Return function to interpolate a fallback palette base on viridis::magma() +} diff --git a/man/scale_color.Rd b/man/scale_color.Rd index c05dcf9..ab17204 100644 --- a/man/scale_color.Rd +++ b/man/scale_color.Rd @@ -14,7 +14,7 @@ scale_color( ) } \arguments{ -\item{initiative}{Either "reach" or "agora.} +\item{initiative}{Either "reach" or "agora" or "default".} \item{palette}{Palette name from `pal_reach()` or `pal_agora()`.} diff --git a/man/scale_fill.Rd b/man/scale_fill.Rd index b07d1a8..95d3dc3 100644 --- a/man/scale_fill.Rd +++ b/man/scale_fill.Rd @@ -14,7 +14,7 @@ scale_fill( ) } \arguments{ -\item{initiative}{Either "reach" or "agora.} +\item{initiative}{Either "reach" or "agora" or "default".} \item{palette}{Palette name from `pal_reach()` or `pal_agora()`.} diff --git a/man/theme_reach.Rd b/man/theme_reach.Rd index 6f0c50d..8718dc6 100644 --- a/man/theme_reach.Rd +++ b/man/theme_reach.Rd @@ -5,6 +5,7 @@ \title{ggplot2 theme with REACH color palettes} \usage{ theme_reach( + initiative = "reach", palette = "main", discrete = TRUE, reverse = FALSE, @@ -12,11 +13,14 @@ theme_reach( title_size = 12, title_color = cols_reach("main_grey"), title_font_face = "bold", + title_hjust = NULL, title_position_to_plot = TRUE, text_size = 10, text_color = cols_reach("main_grey"), text_font_face = "plain", panel_background_color = "#FFFFFF", + panel_border = FALSE, + panel_border_color = cols_reach("main_grey"), legend_position = "right", legend_direction = "vertical", legend_reverse = TRUE, @@ -52,13 +56,15 @@ theme_reach( ) } \arguments{ +\item{initiative}{Either "reach" or "default".} + \item{palette}{Palette name from 'pal_reach()'.} \item{discrete}{Boolean indicating whether color aesthetic is discrete or not.} \item{reverse}{Boolean indicating whether the palette should be reversed.} -\item{font_family}{The font family for all plot's texts. Default to "Leelawadee".} +\item{font_family}{The font family for all plot's texts. Default to "Segoe UI".} \item{title_size}{The size of the legend title. Defaults to 11.} @@ -66,6 +72,8 @@ theme_reach( \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{text_size}{The size of all text other than the title, subtitle and caption. Defaults to 10.} @@ -76,6 +84,10 @@ theme_reach( \item{panel_background_color}{The color for the panel background color. Default to white.} +\item{panel_border}{Boolean. Plot a panel border? Default to FALSE.} + +\item{panel_border_color}{A color. Default to REACH main grey.} + \item{legend_position}{Position of the legend; Default to "right". Can take "right", "left", "top", "bottom" or "none".} \item{legend_direction}{Direction of the legend. Default to "vertical". Can take "vertical" or "horizontal".} diff --git a/man/visualizeR-package.Rd b/man/visualizeR-package.Rd new file mode 100644 index 0000000..25e9400 --- /dev/null +++ b/man/visualizeR-package.Rd @@ -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} diff --git a/man/waffle.Rd b/man/waffle.Rd new file mode 100644 index 0000000..a46d9aa --- /dev/null +++ b/man/waffle.Rd @@ -0,0 +1,53 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/waffle.R +\name{waffle} +\alias{waffle} +\title{Simple waffle chart} +\usage{ +waffle( + df, + x, + y, + n_rows = 10, + size = 2, + x_title = NULL, + x_lab = NULL, + title = NULL, + subtitle = NULL, + caption = NULL, + arrange = TRUE, + theme = theme_reach(axis_x = FALSE, axis_y = FALSE, legend_position = "bottom", + legend_direction = "horizontal", title_hjust = 0.5) +) +} +\arguments{ +\item{df}{A data frame.} + +\item{x}{A character column or coercible as a character column. Will give the waffle's fill color.} + +\item{y}{A numeric column (if plotting proportion, make sure to have percentages between 0 and 100 and not 0 and 1).} + +\item{n_rows}{Number of rows. Default to 10.} + +\item{size}{Width of the separator between blocks (defaults to 2).} + +\item{x_title}{The x scale title. Default to NULL.} + +\item{x_lab}{The x scale caption. 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{arrange}{TRUE or FALSE. Arrange by highest percentage first.} + +\item{theme}{Whatever theme. Default to theme_reach().} +} +\value{ +A waffle chart +} +\description{ +Simple waffle chart +}