Update to v 0.8.9000

This commit is contained in:
gnoblet 2023-05-29 11:13:34 +02:00
parent 09ef523c64
commit 06c757fcc5
23 changed files with 174 additions and 22 deletions

View file

@ -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

11
NEWS.md
View file

@ -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()`

View file

@ -3,7 +3,7 @@
# visualizeR <img src="man/figures/logo.png" align="right" alt="" width="120"/>
> 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 IMPACTs colors
- [x] Add all color palettes from the internal documentation
- [ ] There remains to be added more-than-7-color palettes and black
- \[X\] Add IMPACTs 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
<img src="man/figures/README-example-bar-chart-1.png" width="65%" />
``` 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 = "
<img src="man/figures/README-example-bar-chart-2.png" width="65%" />
``` 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)
<img src="man/figures/README-example-point-chart-1.png" width="65%" />
``` 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
<img src="man/figures/README-example-point-chart-2.png" width="65%" />
``` 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,
<img src="man/figures/README-example-dumbbell-plot-1.png" width="65%" />
### 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,
<img src="man/figures/README-example-donut-plot-1.png" width="65%" />
### 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")
```
<img src="man/figures/README-example-waffle-plot-1.png" width="65%" />
### 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,
<img src="man/figures/README-example-alluvial-plot-1.png" width="65%" />
### Example 6: lollipop chart
### Example 7: lollipop chart
``` r
library(tidyr)
@ -260,6 +277,7 @@ lollipop(df,
<img src="man/figures/README-example-lollipop-chart-1.png" width="65%" />
``` 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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 246 KiB

After

Width:  |  Height:  |  Size: 239 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 111 KiB

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 109 KiB

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 141 KiB

After

Width:  |  Height:  |  Size: 149 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 182 KiB

After

Width:  |  Height:  |  Size: 177 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 285 KiB

After

Width:  |  Height:  |  Size: 281 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 125 KiB

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 319 KiB

After

Width:  |  Height:  |  Size: 318 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 166 KiB

After

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

31
man/pal_fallback.Rd Normal file
View file

@ -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()
}

View file

@ -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()`.}

View file

@ -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()`.}

View file

@ -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".}

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}

53
man/waffle.Rd Normal file
View file

@ -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
}