gg_tabular_comparison: Generates a ggplot with tiles and tables according to...

Description Usage Arguments Value Examples

View source: R/gg_tabular_comparison.R

Description

Inspired by Excel's conditional formatting, the function generates a ggplot object similar to what an excel conditional formatted table would produce when comparing averages. This is particularly useful when comparing a lot of measures between a number of organizational units or services. The measures would appear in rows, organizational units in columns, values in cells. Coloring of cells can be specified (either within the row or within the column).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
gg_tabular_comparison(
  x,
  grouping_var,
  scaling_by = c("grouping", "measure"),
  color_gradient = c("#FEE08B", "#1A9850"),
  overall_average_title = "Average",
  small_sample_warning = 15,
  top_down_mark = 1,
  top_down_emoji = c("V", "X"),
  top_down_color = c("blue", "red"),
  top_down_nudge = 0.5,
  top_down_size = 5
)

Arguments

x

a tbl() with raw data

grouping_var

grouping variable by which averages are computed

scaling_by

by which variable should scaling be performed (either grouping or measure)

color_gradient

the minimum and maximum colors in the gradient

overall_average_title

The title used to described the overall average

small_sample_warning

no coloring applies for cells with sample under specified number (use 0 to disable)

top_down_mark

How many top/bottom observations should be indicated. Use 0 for none, 1 for first and last.

top_down_emoji

What emoji should be used to indicate top/bottom observations. Defaults to c("V", "X") but can also be used as emojis

top_down_color

What colors should be used to indiate top/bottom observations.

top_down_nudge

What should the text/emoji be nudged by (nudge_x of the geom_text function).

top_down_size

The text/emoji's size.

Value

A ggplot2 object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
tib <- tibble::tribble(~department, ~quality, ~quantity, ~performance,
                       "HR", 5, 3, 3,
                       "HR", NA, 2, 5,
                       "HR", 5, 5, 4,
                       "Marketing", 4, 2, 2,
                       "Marketing", 5, NA, 4,
                       "Marketing", 3, 4, 4,
                       "Financials", 2, 2, 4,
                       "Financials", 4, 2, 5,
                       "Sales", 5, 4, 4
                       )
gg_tabular_comparison(tib, grouping_var = department, small_sample_warning = 0)
gg_tabular_comparison(tib, grouping_var = department, small_sample_warning = 2) +
  scale_fill_gradient(low = "red", high = "blue", na.value = "gray")

sarid-ins/saridr documentation built on Nov. 10, 2020, 9:07 p.m.