Skip to contents

Creates a horizontal bar plot representing a single proportion, with optional formatting and colors.

Usage

proportion_bar(
  proportion,
  format = fmt_percent(),
  fgcol = "maroon",
  bgcol = "grey90",
  textcol = "black",
  textcol_inverted = "white",
  proportion_inversion_point = 0.5,
  size = NA
)

Arguments

proportion

Numeric value between 0 and 1 representing the proportion to be plotted.

format

Function to format the proportion label. Defaults to fmt_percent(). Most common alternative is to use fmt_round().

fgcol

Color for the foreground (proportion) part of the bar. Defaults to "maroon".

bgcol

Color for the background (remaining) part of the bar. Defaults to "grey90".

textcol

Colour of proportion label when proportion is less than proportion_inversion_point

textcol_inverted

Colour of proportion label when proportion greater than proportion_inversion_point

proportion_inversion_point

The proportion above which the proportion will be rendered on top of progress bar, not

size

Numeric value for the text size of the proportion label. Defaults to NA.

Value

A ggplot object representing the proportion bar plot.

Details

The for proportion values below proportion_inversion_point, the text label will be placed on the far right side of the bar and coloured by textcol. Otherwise, will be aligned on the inside of the bar and colour will be set to textcol_inverted

Examples

proportion_bar(0.75)

proportion_bar(0.5, fgcol = "blue", bgcol = "lightblue")