Package 'impactR.viz'

Title: Color and viz helpers, wrappers, templates
Description: It basically provides colors as hex codes, color palettes, and some viz functions (graphs and maps).
Authors: Noblet Guillaume [aut, cre]
Maintainer: Guillaume Noblet <[email protected]>
License: MIT + file LICENSE
Version: 0.11.9000
Built: 2026-10-09 10:14:48 UTC
Source: https://github.com/impact-initiatives-hppu/impactR.viz

Help Index


Simple bar chart

Description

Simple bar chart

Usage

bar(
  df,
  x,
  y,
  group = "",
  add_color = color("branding_reach_red"),
  flip = TRUE,
  wrap = NULL,
  position = "dodge",
  alpha = 1,
  x_title = NULL,
  y_title = NULL,
  group_title = NULL,
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  width = 0.5,
  add_text = TRUE,
  add_text_size = 5,
  add_text_color = color("branding_reach_grey"),
  add_text_font_face = "plain",
  add_text_threshold_display = 0.05,
  add_text_suffix = "%",
  add_text_expand_limit = 1.2,
  add_text_round = 1,
  theme_fun = theme_reach(grid_major_x = FALSE, axis_x = FALSE, axis_ticks_y = FALSE,
    legend_direction = "horizontal", legend_position = "bottom"),
  palette = "cat_5_ibm",
  scale_impact = TRUE,
  direction = 1,
  reverse_guide = TRUE
)

Arguments

df

A data frame.

x

A quoted numeric column.

y

A quoted character column or coercible as a character column.

group

Some quoted grouping categorical column, e.g. administrative areas or population groups.

add_color

Add a color to bars (if no grouping).

flip

TRUE or FALSE. Default to TRUE or horizontal bar plot.

wrap

Should x-labels be wrapped? Number of characters.

position

Should the chart be stacked? Default to "dodge". Can take "dodge" and "stack".

alpha

Fill transparency.

x_title

The x scale title. Default to NULL.

y_title

The y scale title. Default to NULL.

group_title

The group legend title. Default to NULL.

title

Plot title. Default to NULL.

subtitle

Plot subtitle. Default to NULL.

caption

Plot caption. Default to NULL.

width

Bar width.

add_text

TRUE or FALSE. Add values as text.

add_text_size

Text size.

add_text_color

Text color.

add_text_font_face

Text font_face.

add_text_threshold_display

Minimum value to add the text label.

add_text_suffix

If percent is FALSE, should we add a suffix to the text label?

add_text_expand_limit

Default to adding 10% on top of the bar.

add_text_round

Round the text label.

theme_fun

Whatever theme function. For no custom theme, use theme_fun = NULL.

palette

Palette name from palette().

scale_impact

Use the package custom scales for fill and color.

direction

1 or -1; should the order of colors be reversed?

reverse_guide

Boolean indicating whether the guide should be reversed.


Functions to extract IMPACT colors as hex codes

Description

color() returns the requested columns, returns NA if absent. color_pattern() returns all colors that start with the pattern.

Usage

color(..., unname = TRUE)

color_pattern(pattern, unname = TRUE)

Arguments

...

Character names of colors. If NULL returns all colors.

unname

Boolean. Should the output vector be unnamed? Default to TRUE.

pattern

Pattern of the start of colors' name.

Value

Hex codes named or unnamed.

Naming of colors

  • All branding colors start with "branding";

  • All categorical colors start with "cat_";

  • All continuous colors start with "quant_";

Then, a number indicates the number of colors that belong to the palettes, a string the name of the palette, and, finally, a number the position of the color. E.g., "quant_5_red_4" would be the 4th color of a continuous palettes of 5 colors in the red band. Exception is made for white, light_grey, dark_grey, and black.


Interpolate a color palette

Description

Interpolate a color palette

Usage

palette(
  palette = "branding_reach",
  reverse = FALSE,
  show_palettes = FALSE,
  ...
)

Arguments

palette

Character name of a palette in palettes

reverse

Boolean indicating whether the palette should be reversed

show_palettes

Should the ouput be the set of palettes names to pick from? Default to FALSE

...

Additional arguments to pass to colorRampPalette()

Value

A color palette


Generate color palettes

Description

palette_gen() generates a color palette and let you choose whether continuous or discrete. palette_gen_discrete() and palette_gen_continuous() generates respectively discrete and continuous palettes.

Usage

palette_gen(palette, type, direction = 1, ...)

palette_gen_discrete(palette = "branding_reach", direction = 1)

palette_gen_continuous(palette = "quant_7_artichoke", direction = 1, ...)

Arguments

palette

Palette name from palette().

type

"discrete" or "continuous".

direction

1 or -1; should the order of colors be reversed?

...

Additional arguments to pass to colorRampPalette() when type is "continuous".


Simple point chart

Description

Simple point chart

Usage

point(
  df,
  x,
  y,
  group = "",
  add_color = color("branding_reach_red"),
  flip = TRUE,
  alpha = 1,
  size = 2,
  x_title = NULL,
  y_title = NULL,
  group_title = NULL,
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  theme_fun = theme_reach(grid_major_y = TRUE),
  palette = "cat_5_ibm",
  scale_impact = TRUE,
  direction = 1,
  reverse_guide = TRUE
)

Arguments

df

A data frame.

x

A numeric column.

y

Another numeric column.

group

Some grouping categorical column, e.g. administrative areas or population groups.

add_color

Add a color to bars (if no grouping).

flip

TRUE or FALSE. Default to TRUE or horizontal bar plot.

alpha

Fill transparency.

size

Point size.

x_title

The x scale title. Default to NULL.

y_title

The y scale title. Default to NULL.

group_title

The group legend title. Default to NULL.

title

Plot title. Default to NULL.

subtitle

Plot subtitle. Default to NULL.

caption

Plot caption. Default to NULL.

theme_fun

Whatever theme. Default to theme_reach(). NULL if no theming needed.

palette

Palette name from palette().

scale_impact

Use the package custom scales for fill and color.

direction

1 or -1; should the order of colors be reversed?

reverse_guide

Boolean indicating whether the guide should be reversed.


Scale constructors for fill and colors

Description

This function is based on palette(). If palette is NULL, the used palette will be magma from gpplot2's viridis scale constructors.

Usage

scale_color_impact_discrete(
  palette = "cat_5_ibm",
  direction = 1,
  reverse_guide = TRUE,
  ...
)

scale_fill_impact_discrete(
  palette = "cat_5_ibm",
  direction = 1,
  reverse_guide = TRUE,
  ...
)

scale_fill_impact_continuous(
  palette = "quant_7_artichoke",
  direction = 1,
  reverse_guide = TRUE,
  ...
)

scale_color_impact_continuous(
  palette = "quant_7_artichoke",
  direction = 1,
  reverse_guide = TRUE,
  ...
)

Arguments

palette

Palette name from palette().

direction

1 or -1; should the order of colors be reversed?

reverse_guide

Boolean indicating whether the guide should be reversed.

...

Additional arguments passed to ggplot2::discrete_scale() if discrete or ggplot2::scale_fill_gradient() if continuous.


ggplot2 theme wrapper with REACH fonts and colors

Description

Give some reach colors and fonts to a ggplot.

Usage

theme_reach(
  font_family = "Segoe UI",
  title_size = 16,
  title_color = color("branding_reach_grey"),
  title_font_face = "bold",
  title_hjust = NULL,
  title_position_to_plot = TRUE,
  title_font_family = "Roboto Condensed",
  text_size = 14,
  text_color = color("branding_reach_grey"),
  text_font_face = "plain",
  panel_background_color = "#FFFFFF",
  panel_border = FALSE,
  panel_border_color = color("branding_reach_grey"),
  legend_position = "bottom",
  legend_direction = "horizontal",
  legend_justification = "left",
  legend_reverse = TRUE,
  legend_title_size = 14,
  legend_title_color = color("branding_reach_grey"),
  legend_title_font_face = "plain",
  legend_text_size = 12,
  legend_text_color = color("branding_reach_grey"),
  legend_text_font_face = "plain",
  axis_x = TRUE,
  axis_y = TRUE,
  axis_text_x = TRUE,
  axis_line_x = TRUE,
  axis_ticks_x = TRUE,
  axis_text_y = TRUE,
  axis_line_y = TRUE,
  axis_ticks_y = TRUE,
  axis_text_size = 14,
  axis_text_color = color("branding_reach_grey"),
  axis_text_font_face = "plain",
  axis_title_size = 15,
  axis_title_color = color("branding_reach_grey"),
  axis_title_font_face = "plain",
  axis_text_x_angle = 0,
  axis_text_x_vjust = 0.5,
  axis_text_x_hjust = 0.5,
  grid_major_x = TRUE,
  grid_major_y = FALSE,
  grid_major_color = color("branding_reach_light_grey"),
  grid_major_x_size = 0.01,
  grid_major_y_size = 0.01,
  grid_minor_x = FALSE,
  grid_minor_y = FALSE,
  grid_minor_color = color("branding_reach_light_grey"),
  grid_minor_x_size = 0.005,
  grid_minor_y_size = 0.005,
  caption_position_to_plot = TRUE,
  ...
)

Arguments

font_family

The font family for all plot's texts. Default to "Segoe UI".

title_size

The size of the legend title. Defaults to 11.

title_color

Legend title color.

title_font_face

Legend title font face. Default to "plain". Font face ("plain", "italic", "bold", "bold.italic").

title_hjust

Title horizontal justification. Default to NULL. Use 0.5 to center the title.

title_position_to_plot

TRUE or FALSE. Positioning to plot or to panel?

title_font_family

Title font family. Default to "Roboto Condensed".

text_size

The size of all text other than the title, subtitle and caption. Defaults to 10.

text_color

Text color.

text_font_face

Text font face. Default to "bold". Font face ("plain", "italic", "bold", "bold.italic").

panel_background_color

The color for the panel background color. Default to white.

panel_border

Boolean. Plot a panel border? Default to FALSE.

panel_border_color

A color. Default to REACH main grey.

legend_position

Position of the legend; Default to "right". Can take "right", "left", "top", "bottom" or "none".

legend_direction

Direction of the legend. Default to "vertical". Can take "vertical" or "horizontal".

legend_justification

In addition to legend_direction, place the legend. Can take "left", "bottom", "center", "right", "top".

legend_reverse

Reverse the color in the guide? Default to TRUE.

legend_title_size

Legend title size.

legend_title_color

Legend title color.

legend_title_font_face

Legend title font face. Default to "plain". Font face ("plain", "italic", "bold", "bold.italic").

legend_text_size

Legend text size.

legend_text_color

Legend text color.

legend_text_font_face

Legend text font face. Default to "plain". Font face ("plain", "italic", "bold", "bold.italic").

axis_x

Boolean. Do you need x-axis?

axis_y

Boolean. Do you need y-axis?

axis_text_x

Boolean. Do you need the text for the x-axis?

axis_line_x

Boolean. Do you need the line for the x-axis?

axis_ticks_x

Boolean. Do you need the line for the x-axis?

axis_text_y

Boolean. Do you need the text for the y-axis?

axis_line_y

Boolean. Do you need the line for the y-axis?

axis_ticks_y

Boolean. Do you need the line for the y-axis?

axis_text_size

Axis text size.

axis_text_color

Axis text color.

axis_text_font_face

Axis text font face. Default to "plain". Font face ("plain", "italic", "bold", "bold.italic").

axis_title_size

Axis title size.

axis_title_color

Axis title color.

axis_title_font_face

Axis title font face. Default to "plain". Font face ("plain", "italic", "bold", "bold.italic").

axis_text_x_angle

Angle for the x-axis text.

axis_text_x_vjust

Vertical adjustment for the x-axis text.

axis_text_x_hjust

Vertical adjustment for the x-axis text.

grid_major_x

Boolean. Do you need major grid lines for x-axis?

grid_major_y

Boolean. Do you need major grid lines for y-axis?

grid_major_color

Major grid lines color.

grid_major_x_size

Major X line size.

grid_major_y_size

Major Y line size.

grid_minor_x

Boolean. Do you need minor grid lines for x-axis?

grid_minor_y

Boolean. Do you need minor grid lines for y-axis?

grid_minor_color

Minor grid lines color.

grid_minor_x_size

Minor X line size.

grid_minor_y_size

Minor Y line size.

caption_position_to_plot

TRUE or FALSE. Positioning to plot or to panel?

...

Additional arguments passed to ggplot2::theme().