diff --git a/DESCRIPTION b/DESCRIPTION index 80c3d5d..c1ab644 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: visualizeR Type: Package Title: What a color! What a viz! -Version: 0.5.9000 +Version: 0.6.9000 Authors@R: c( person( 'Noblet', 'Guillaume', @@ -24,6 +24,9 @@ Imports: grDevices, glue, scales, - ggtext + ggtext, + ggrepel, + tidyr, + dplyr Suggests: knitr, sf, tmap VignetteBuilder: knitr diff --git a/NEWS.md b/NEWS.md index 1c505d7..03d4d24 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +# visualizeR 0.6.9000 + +* Add `dumbbell()`. +* Add further parameters to `theme_reach()` + +--- + # visualizeR 0.5.9000 * Add wrapping of title, subtitle and caption thanks to `ggtext` diff --git a/R/theme_reach.R b/R/theme_reach.R index 15f95cf..0bb1fbe 100644 --- a/R/theme_reach.R +++ b/R/theme_reach.R @@ -16,6 +16,9 @@ #' @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_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_reverse Reverse the color in the guide? Default to TRUE. #' @param title_size The size of the legend title. Defaults to 11. #' @param title_color Legend title color. @@ -62,6 +65,9 @@ theme_reach <- function( legend_title_size = 11, legend_title_color = cols_reach("main_grey"), legend_title_font_face = "plain", + legend_text_size = 10, + legend_text_color = cols_reach("main_grey"), + legend_text_font_face = "plain", axis_x = TRUE, axis_y = TRUE, axis_text_size = 10, @@ -133,7 +139,13 @@ theme_reach <- function( size = legend_title_size, face = legend_title_font_face, family = font_family, - color = legend_title_color) + color = legend_title_color), + legend.text = ggplot2::element_text( + size = legend_text_size, + face = legend_text_font_face, + family = font_family, + color = legend_text_color + ) ) # Position of title diff --git a/README.Rmd b/README.Rmd index 72ea8c9..8d4e0a5 100644 --- a/README.Rmd +++ b/README.Rmd @@ -112,6 +112,33 @@ point(penguins, bill_length_mm, flipper_length_mm, island, alpha = 0.6, size = 3 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_x = T, title_position_to_plot = FALSE)) ``` + +### Example 3! Dumbbell plot, REACH themed + +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 example-dumbbell-plot, eval = TRUE} +# Prepare long data +df <- tibble::tibble( + admin1 = rep(c("A", "B", "C", "D", "E", "F", "G", "H"), 2), + 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)) + +# Example +dumbbell(df, + stat, + setting, + admin1, + title = "% of HHs that reported open defecation as sanitation facility", + group_y_title = "Admin 1", + theme = theme_reach(legend_position = "bottom", + legend_direction = "horizontal", + palette = "primary", + title_position_to_plot = FALSE)) +``` + ## Maps ```{r example-map} diff --git a/README.md b/README.md index 01231ad..1b1d0be 100644 --- a/README.md +++ b/README.md @@ -23,14 +23,14 @@ 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 - color palettes -- [ ] Add new types of visualization (e.g. dumbbell plot) -- [ ] Use examples -- [ ] Add some ease-map functions -- [ ] Add some interactive functions (maps and graphs) +- [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 +- [ ] Add new types of visualization (e.g. dumbbell plot) +- [ ] Use examples +- [ ] Add some ease-map functions +- [ ] Add some interactive functions (maps and graphs) ## Request @@ -96,7 +96,6 @@ 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")) ``` @@ -104,7 +103,6 @@ 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,7 +115,6 @@ 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) ``` @@ -125,7 +122,6 @@ 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)) ``` @@ -133,17 +129,45 @@ 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_x = T, title_position_to_plot = FALSE)) ``` +### Example 3! Dumbbell plot, REACH themed + +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(c("A", "B", "C", "D", "E", "F", "G", "H"), 2), + 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)) + +# Example +dumbbell(df, + stat, + setting, + admin1, + title = "% of HHs that reported open defecation as sanitation facility", + group_y_title = "Admin 1", + theme = theme_reach(legend_position = "bottom", + legend_direction = "horizontal", + palette = "primary", + title_position_to_plot = FALSE)) +``` + + + ## Maps ``` r - # Add indicator layer # - based on "pretty" classes and title "Proportion (%)" # - buffer to add a 10% around the bounding box diff --git a/docs/404.html b/docs/404.html index 5eb2dff..b23886a 100644 --- a/docs/404.html +++ b/docs/404.html @@ -31,7 +31,7 @@ visualizeR - 0.5.9000 + 0.6.9000 + + + + + +
+
+
+ +
+

Make dumbbell chart.

+
+ +
+

Usage

+
dumbbell(
+  df,
+  col,
+  group_x,
+  group_y,
+  point_size = 5,
+  point_alpha = 1,
+  segment_size = 2.5,
+  segment_color = cols_reach("main_lt_grey"),
+  group_x_title = NULL,
+  group_y_title = NULL,
+  x_title = NULL,
+  title = NULL,
+  subtitle = NULL,
+  caption = NULL,
+  line_to_y_axis = TRUE,
+  line_to_y_axis_type = 3,
+  line_to_y_axis_width = 0.5,
+  line_to_y_axis_color = cols_reach("main_grey"),
+  add_text = TRUE,
+  add_text_vjust = 2,
+  add_text_size = 3.5,
+  add_text_color = cols_reach("main_grey"),
+  theme = theme_reach(palette = "primary")
+)
+
+ +
+

Arguments

+
df
+

A data frame.

+ + +
col
+

A numeric column.

+ + +
group_x
+

The grouping column on the x-axis; only two groups.

+ + +
group_y
+

The grouping column on the y-axis.

+ + +
point_size
+

Point size.

+ + +
point_alpha
+

Point alpha.

+ + +
segment_size
+

Segment size.

+ + +
segment_color
+

Segment color.

+ + +
group_x_title
+

X-group and legend title.

+ + +
group_y_title
+

Y-axis and group title.

+ + +
x_title
+

X-axis title.

+ + +
title
+

Title.

+ + +
subtitle
+

Subtitle.

+ + +
caption
+

Caption.

+ + +
line_to_y_axis
+

TRUE or FALSE; add a line connected points and Y-axis.

+ + +
line_to_y_axis_type
+

Line to Y-axis type.

+ + +
line_to_y_axis_width
+

Line to Y-axis width.

+ + +
line_to_y_axis_color
+

Line to Y-axis color.

+ + +
add_text
+

TRUE or FALSE; add text at the points.

+ + +
add_text_vjust
+

Vertical adjustment.

+ + +
add_text_size
+

Text size.

+ + +
add_text_color
+

Text color.

+ + +
theme
+

A ggplot2 theme, default to `theme_reach()`

+ +
+
+

Value

+ + +

A dumbbell chart.

+
+ +
+ + +
+ + + +
+ + + + + + + diff --git a/docs/reference/figures/README-example-bar-chart-1.png b/docs/reference/figures/README-example-bar-chart-1.png index 135815e..a9678fc 100644 Binary files a/docs/reference/figures/README-example-bar-chart-1.png and b/docs/reference/figures/README-example-bar-chart-1.png differ diff --git a/docs/reference/figures/README-example-bar-chart-2.png b/docs/reference/figures/README-example-bar-chart-2.png index 636cac0..25c19c8 100644 Binary files a/docs/reference/figures/README-example-bar-chart-2.png and b/docs/reference/figures/README-example-bar-chart-2.png differ diff --git a/docs/reference/figures/README-example-bar-chart-3.png b/docs/reference/figures/README-example-bar-chart-3.png index 8483aac..513a3bb 100644 Binary files a/docs/reference/figures/README-example-bar-chart-3.png and b/docs/reference/figures/README-example-bar-chart-3.png differ diff --git a/docs/reference/figures/README-example-dumbbell-plot-1.png b/docs/reference/figures/README-example-dumbbell-plot-1.png new file mode 100644 index 0000000..aedc63b Binary files /dev/null and b/docs/reference/figures/README-example-dumbbell-plot-1.png differ diff --git a/docs/reference/figures/README-example-map.png b/docs/reference/figures/README-example-map.png index ce2727b..eb3162e 100644 Binary files a/docs/reference/figures/README-example-map.png and b/docs/reference/figures/README-example-map.png differ diff --git a/docs/reference/figures/README-example-point-chart-1.png b/docs/reference/figures/README-example-point-chart-1.png index 3efabaf..aad8829 100644 Binary files a/docs/reference/figures/README-example-point-chart-1.png and b/docs/reference/figures/README-example-point-chart-1.png differ diff --git a/docs/reference/figures/README-example-point-chart-2.png b/docs/reference/figures/README-example-point-chart-2.png index 7aa740b..ed92e1d 100644 Binary files a/docs/reference/figures/README-example-point-chart-2.png and b/docs/reference/figures/README-example-point-chart-2.png differ diff --git a/docs/reference/figures/README-example-point-chart-3.png b/docs/reference/figures/README-example-point-chart-3.png index 39d056b..7ad059b 100644 Binary files a/docs/reference/figures/README-example-point-chart-3.png and b/docs/reference/figures/README-example-point-chart-3.png differ diff --git a/docs/reference/frontier_admin0.html b/docs/reference/frontier_admin0.html index 29d63e0..959a37b 100644 --- a/docs/reference/frontier_admin0.html +++ b/docs/reference/frontier_admin0.html @@ -10,7 +10,7 @@ visualizeR - 0.5.9000 + 0.6.9000