Skip to contents

`bar()` is a simple bar chart with some customization allowed, in particular the `theme_fun` argument for theming. `hbar()` uses `bar()` with sane defaults for a horizontal bar chart.

Usage

hbar(
  ...,
  flip = TRUE,
  add_text = FALSE,
  theme_fun = theme_bar(flip = flip, add_text = add_text)
)

bar(
  df,
  x,
  y,
  group = "",
  facet = "",
  order = "none",
  x_rm_na = TRUE,
  y_rm_na = TRUE,
  group_rm_na = TRUE,
  facet_rm_na = TRUE,
  y_expand = 0.1,
  add_color = color("cat_5_main_1"),
  add_color_guide = TRUE,
  flip = FALSE,
  wrap = NULL,
  position = "dodge",
  alpha = 1,
  x_title = NULL,
  y_title = NULL,
  group_title = NULL,
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  width = 0.8,
  add_text = FALSE,
  add_text_size = 4.5,
  add_text_color = color("dark_grey"),
  add_text_font_face = "bold",
  add_text_threshold_display = 0.05,
  add_text_suffix = "%",
  add_text_expand_limit = 1.2,
  add_text_round = 1,
  theme_fun = theme_bar(flip = flip, add_text = add_text, axis_text_x_angle = 0,
    axis_text_x_vjust = 0.5, axis_text_x_hjust = 0.5),
  scale_fill_fun = scale_fill_visualizer_discrete(),
  scale_color_fun = scale_color_visualizer_discrete()
)

Arguments

...

Additional arguments passed to `bar()`

flip

TRUE or FALSE (default). Default to TRUE or horizontal bar plot.

add_text

TRUE or FALSE. Add values as text.

theme_fun

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

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.

facet

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

order

A character scalar specifying the order type (one of "none", "y", "grouped"). See details.

x_rm_na

Remove NAs in x?

y_rm_na

Remove NAs in y?

group_rm_na

Remove NAs in group?

facet_rm_na

Remove NAs in facet?

y_expand

Multiplier to expand the y axis.

add_color

Add a color to bars (if no grouping).

add_color_guide

Should a legend be added?

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_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.

scale_fill_fun

Scale fill function. Default to scale_fill_visualizer_discrete().

scale_color_fun

Scale color function. Default to scale_color_visualizer_discrete().