Skip to contents

Wrapper around stem_plot() to make creating stacked barplots easier.

Usage

stem_plot_barstack(
  data,
  item,
  group = NULL,
  weight = NULL,
  geom = ggplot2::geom_col,
  geom_args = list(position = "stack"),
  label_text_color = "black",
  label_args = list(position = ggplot2::position_stack(vjust = 0.5), color =
    label_text_color, size = ggplot2::rel(5)),
  scale_y = ggplot2::scale_y_continuous(labels = scales::percent_format(accuracy = 1,
    suffix = " %"), limits = c(0, NA)),
  label = TRUE,
  label_scale = 100,
  label_hide = 0.05,
  coorf_flip = TRUE,
  item_reverse = TRUE,
  legend_rows = 1,
  legend_byrow = TRUE,
  palette = "div1",
  ...
)

Arguments

data

Dataframe including item (and group) variables

item

Plotted item

group

Optional; plotted grouping variable

weight

Optional; survey weights

geom

geom that will represent data

geom_args

Optional, a named list to collapse group categories

label_text_color

Color of text labels. Default is black.

label_args

Arguments for the labels function like vjust, postion, etc.

scale_y

Format y axis using ggplot2::scale_y_continuous()

label

Should geom labels be printed? Yes by default

label_scale

Multiplicative scale of geom labels. 100 multiple the values by 100.

label_hide

Hides geom labels with values smaller than this threshold. Defaults to 0.05.

coorf_flip

Should the x and y axis be flipped? Defaults to TRUE

item_reverse

Should the order of item categories be reversed? Defaults to TRUE

legend_rows

Number of rows in legend

legend_byrow

Shoul legend be filled by rows? (FALSE to fill by columns)

palette

Stem palette to be used in the plot. See scale_color_stem() and scale_fill_stem() for details.

...

Other arguments passed to stem_plot()

Value

A ggplot2 object with custom attribute "stem_plot"

Examples

if (FALSE) { # \dontrun{
stem_plot_barstack(trust, police, eu_index)
stem_plot_barstack(trust, police)
} # }