diff --git a/.gitignore b/.gitignore index ae73e6d..ecb1ef1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .Rdata .httr-oauth .DS_Store +R/test.R diff --git a/DESCRIPTION b/DESCRIPTION index 083bbdd..20aabba 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: visualizeR Type: Package Title: What a color! What a viz! -Version: 0.3.9000 +Version: 0.4.9000 Authors@R: c( person( 'Noblet', 'Guillaume', @@ -17,13 +17,12 @@ Depends: R (>= 4.1.0) License: GPL (>= 3) Encoding: UTF-8 LazyData: true -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.3 Imports: ggplot2, rlang, grDevices, glue, - scales, - ggblanket (== 1.6.1) + scales Suggests: knitr, sf, tmap VignetteBuilder: knitr diff --git a/NEWS.md b/NEWS.md index fa45d9e..ef65da6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,9 +1,16 @@ +# visualizeR 0.4.9000 + +* Breaking changes: remove dependency to `ggblanket`. +* Full rewrite of `theme_reach()`. +* `bar_reach` is now `bar()` and theming is passed through argument `theme` for which default is `theme_reach()`. +* `point_reach` is now `point()` and theming is passed through argument `theme` for which default is `theme_reach()`. + + # visualizeR 0.3.9000 * Breaking changes: update to `ggblanket` v1.6.1. * Add plotting functions for indicator maps. - # visualizeR 0.2.9000 * Breaking changes: almost all functions got refinements, and there are new functions, typically `hbar()` becomes `bar_reach()` and `point_reach()` is added. diff --git a/README.md b/README.md index 2fec6ca..79104a1 100644 --- a/README.md +++ b/README.md @@ -89,20 +89,28 @@ df <- penguins |> mean_fl = mean(flipper_length_mm, na.rm = T)) |> ungroup() -# Simple bar chart by group -bar_reach(df, mean_bl, island, species, percent = FALSE, x_title = "Mean of bill length") +# Simple bar chart by group with some alpha transparency +bar(df, island, mean_bl, species, percent = FALSE, alpha = 0.6, x_title = "Mean of bill length") ``` ``` r -# Using another color palette -bar_reach(df, mean_bl, island, species, percent = FALSE, palette = "artichoke_3", legend_rev = TRUE) +# 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")) ``` +``` 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)) +``` + + + ### Example 2: Point chart, already REACH themed At this stage, `point_reach()` only supports categorical grouping colors @@ -111,7 +119,7 @@ with the `group` arg. ``` r # Simple point chart -point_reach(penguins, bill_length_mm, flipper_length_mm) +point(penguins, bill_length_mm, flipper_length_mm) ``` @@ -119,7 +127,7 @@ point_reach(penguins, bill_length_mm, flipper_length_mm) ``` r # Point chart with grouping colors, greater dot size, some transparency, reversed color palette -point_reach(penguins, bill_length_mm, flipper_length_mm, island, alpha = 0.6, size = 3, reverse = TRUE) +point(penguins, bill_length_mm, flipper_length_mm, island, alpha = 0.6, size = 3, theme = theme_reach(reverse = TRUE)) ``` @@ -127,7 +135,7 @@ point_reach(penguins, bill_length_mm, flipper_length_mm, island, alpha = 0.6, si ``` r # Using another color palettes -point_reach(penguins, bill_length_mm, flipper_length_mm, island, palette = "artichoke_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)) ``` diff --git a/man/bar.Rd b/man/bar.Rd new file mode 100644 index 0000000..5ec812a --- /dev/null +++ b/man/bar.Rd @@ -0,0 +1,67 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/bar.R +\name{bar} +\alias{bar} +\title{Simple bar chart} +\usage{ +bar( + df, + x, + y, + group = NULL, + flip = TRUE, + percent = TRUE, + position = "dodge", + alpha = 1, + x_title = NULL, + y_title = NULL, + group_title = NULL, + title = NULL, + subtitle = NULL, + caption = NULL, + add_text = FALSE, + add_text_suffix = "", + theme = theme_reach() +) +} +\arguments{ +\item{df}{A data frame.} + +\item{x}{A numeric column.} + +\item{y}{A character column or coercible as a character column.} + +\item{group}{Some grouping categorical column, e.g. administrative areas or population groups.} + +\item{flip}{TRUE or FALSE. Default to TRUE or horizontal bar plot.} + +\item{percent}{TRUE or FALSE. Should the x-labels (and text labels if present) be displayed as percentages? Default to TRUE.} + +\item{position}{Should the chart be stacked? Default to "dodge". Can take "dodge" and "stack".} + +\item{alpha}{Fill transparency.} + +\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{add_text}{TRUE or FALSE. Add the value as text.} + +\item{add_text_suffix}{If percent is FALSE, should we add a suffix to the text label?} + +\item{theme}{Whatever theme. Default to theme_reach().} +} +\value{ +A bar chart +} +\description{ +Simple bar chart +} diff --git a/man/bar_reach.Rd b/man/bar_reach.Rd deleted file mode 100644 index e3091f6..0000000 --- a/man/bar_reach.Rd +++ /dev/null @@ -1,82 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/bar.R -\name{bar_reach} -\alias{bar_reach} -\title{Simple bar chart} -\usage{ -bar_reach( - df, - x, - y, - group = NULL, - percent = TRUE, - palette = "main", - reverse = FALSE, - family = "Leelawadee", - alpha = 1, - width = 0.5, - x_title = NULL, - y_title = NULL, - group_title = NULL, - position = "dodge", - title = NULL, - subtitle = NULL, - caption = NULL, - text_size = 10, - title_size = 14, - legend_position = "right", - legend_rev = TRUE, - ... -) -} -\arguments{ -\item{df}{A data frame.} - -\item{x}{A numeric column.} - -\item{y}{A character column or coercible as a character column.} - -\item{group}{Some grouping categorical column, e.g. administrative areas or population groups.} - -\item{percent}{TRUE or FALSE. Should the x-labels be displayed as percentages? Default to TRUE.} - -\item{palette}{Palette name from 'pal_reach()'.} - -\item{reverse}{Boolean indicating whether the palette should be reversed.} - -\item{family}{The font family for all plot's texts. Default to "Leelawadee".} - -\item{alpha}{Transparency.} - -\item{width}{Width.} - -\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{position}{Should the chart be stacked? Default to "dodge". Can take "dodge" and "stack".} - -\item{title}{Plot title. Default to NULL.} - -\item{subtitle}{Plot subtitle. Default to NULL.} - -\item{caption}{Caption title string. Default to NULL.} - -\item{text_size}{The size of all text other than the title, subtitle and caption. Defaults to 10.} - -\item{title_size}{The size of the title text. Defaults to 14.} - -\item{legend_position}{Position of the legend; Default to "right". Can take "right", "left", "top", "bottom" or "none".} - -\item{legend_rev}{Reverse the color in the guide? Default to TRUE.} - -\item{...}{Other arguments to be passed to "ggblanket::gg_col"} -} -\value{ -A bar chart -} -\description{ -`ggblanket` as internals for deciding whether the bar chart is horizontally readable. -} diff --git a/man/figures/README-example-bar-chart-1.png b/man/figures/README-example-bar-chart-1.png index d423d85..1b328ac 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 d6639d8..a9e8da6 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 new file mode 100644 index 0000000..f46b200 Binary files /dev/null and b/man/figures/README-example-bar-chart-3.png differ diff --git a/man/figures/README-example-point-chart-1.png b/man/figures/README-example-point-chart-1.png index ded89e0..d8056fa 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 7fe5e16..5fd1bd2 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 f102ee0..2e0b892 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/point.Rd b/man/point.Rd new file mode 100644 index 0000000..6a4a31f --- /dev/null +++ b/man/point.Rd @@ -0,0 +1,58 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/point.R +\name{point} +\alias{point} +\title{Simple bar chart} +\usage{ +point( + df, + x, + y, + group = NULL, + flip = TRUE, + alpha = 1, + size = 1, + x_title = NULL, + y_title = NULL, + group_title = NULL, + title = NULL, + subtitle = NULL, + caption = NULL, + theme = theme_reach() +) +} +\arguments{ +\item{df}{A data frame.} + +\item{x}{A numeric column.} + +\item{y}{A character column or coercible as a character column.} + +\item{group}{Some grouping categorical column, e.g. administrative areas or population groups.} + +\item{flip}{TRUE or FALSE. Default to TRUE or horizontal bar plot.} + +\item{alpha}{Fill transparency.} + +\item{size}{Point size.} + +\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{theme}{Whatever theme. Default to theme_reach().} +} +\value{ +A bar chart +} +\description{ +Simple bar chart +} diff --git a/man/point_reach.Rd b/man/point_reach.Rd deleted file mode 100644 index d069f4c..0000000 --- a/man/point_reach.Rd +++ /dev/null @@ -1,73 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/point.R -\name{point_reach} -\alias{point_reach} -\title{Simple point chart} -\usage{ -point_reach( - df, - x, - y, - group = NULL, - palette = "main", - reverse = FALSE, - family = "Leelawadee", - alpha = 1, - size = 1.5, - x_title = NULL, - y_title = NULL, - group_title = NULL, - title = NULL, - subtitle = NULL, - caption = NULL, - text_size = 10, - title_size = 14, - legend_position = "right", - ... -) -} -\arguments{ -\item{df}{A data frame.} - -\item{x}{A numeric column.} - -\item{y}{A character column or coercible as a character column.} - -\item{group}{Some grouping categorical column, e.g. administrative areas or population groups.} - -\item{palette}{Palette name from 'pal_reach()'.} - -\item{reverse}{Boolean indicating whether the palette should be reversed.} - -\item{family}{The font family for all plot's texts. Default to "Leelawadee".} - -\item{alpha}{Transparency.} - -\item{size}{Dot size. Default to 1.5.} - -\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}{Caption title string. Default to NULL.} - -\item{text_size}{The size of all text other than the title, subtitle and caption. Defaults to 10.} - -\item{title_size}{The size of the title text. Defaults to 14.} - -\item{legend_position}{Position of the legend; Default to "right". Can take "right", "left", "top", "bottom" or "none".} - -\item{...}{Other arguments to be passed to "ggblanket::gg_col"} -} -\value{ -A bar chart -} -\description{ -`ggblanket` as internals for deciding whether the bar chart is horizontally readable. -} diff --git a/man/theme_reach.Rd b/man/theme_reach.Rd index 3ad58ed..cd8f2c5 100644 --- a/man/theme_reach.Rd +++ b/man/theme_reach.Rd @@ -8,14 +8,24 @@ theme_reach( palette = "main", discrete = TRUE, reverse = FALSE, - family = "Leelawadee", + font_family = "Leelawadee", + title_size = 12, + title_color = cols_reach("main_grey"), + title_font_face = "bold", text_size = 10, - title_size = 14, - plot_background_pal = "#FFFFFF", - panel_background_pal = "#FFFFFF", + text_color = cols_reach("main_grey"), + text_font_face = "bold", + panel_background_color = "#FFFFFF", legend_position = "right", legend_direction = "vertical", legend_reverse = TRUE, + axis_x = TRUE, + axis_y = TRUE, + grid_x = FALSE, + grid_y = FALSE, + grid_color = cols_reach("main_lt_grey"), + grid_x_size = 0.1, + grid_y_size = 0.1, ... ) } @@ -26,15 +36,21 @@ theme_reach( \item{reverse}{Boolean indicating whether the palette should be reversed.} -\item{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 "Leelawadee".} + +\item{title_size}{The size of the title. Defaults to 12.} + +\item{title_color}{Title color.} + +\item{title_font_face}{Title font face. Default to "bold". Font face ("plain", "italic", "bold", "bold.italic").} \item{text_size}{The size of all text other than the title, subtitle and caption. Defaults to 10.} -\item{title_size}{The size of the title text_family. Defaults to 14.} +\item{text_color}{Text color.} -\item{plot_background_pal}{The color for the plot background color. Default to white.} +\item{text_font_face}{Text font face. Default to "bold". Font face ("plain", "italic", "bold", "bold.italic").} -\item{panel_background_pal}{The color for the panel background color. Default to white.} +\item{panel_background_color}{The color for the panel background color. Default to white.} \item{legend_position}{Position of the legend; Default to "right". Can take "right", "left", "top", "bottom" or "none".} @@ -42,7 +58,21 @@ theme_reach( \item{legend_reverse}{Reverse the color in the guide? Default to TRUE.} -\item{...}{Additional arguments passed to `ggblanket::gg_theme()`.} +\item{axis_x}{Boolean. Do you need x-axis?} + +\item{axis_y}{Boolean. Do you need y-axis?} + +\item{grid_x}{Boolean. Do you need major grid lines for x-axis?} + +\item{grid_y}{Boolean. Do you need major grid lines for y-axis?} + +\item{grid_color}{Grid lines color.} + +\item{grid_x_size}{X line size.} + +\item{grid_y_size}{Y line size.} + +\item{...}{Additional arguments passed to `ggplot2::gg_theme()`.} } \value{ The base REACH theme