GG_ordinal: Plot ordinal proportions

GG_ordinalR Documentation

Plot ordinal proportions

Description

Plot ordinal proportions

Usage

GG_ordinal(
  data,
  vars = NULL,
  group = NULL,
  clean_factor_levels = T,
  order = "positive",
  reverse_factor_levels = F,
  percentages = T,
  add_values = T,
  font_size = 4,
  exclude_values_below = 0
)

Arguments

data

A data frame with ordinal variables

vars

Which variables to plot. Default is all.

group

Grouping variable. Default is NULL.

clean_factor_levels

Whether to clean the factor levels

order

How to order the variables. Default is "positive" which sorts them by largest value. Alternatives are "negative", and "none" which leaves them in place.

reverse_factor_levels

Whether to reverse the factor levels. Default is FALSE.

percentages

Whether to plot percentages or counts. Default is TRUE.

add_values

Whether to add values to the plot. Default is TRUE.

font_size

Font size for the values. Default is 4.

exclude_values_below

Exclude values below this value. Default is 0.

Value

A ggplot2 object

Examples

xx = tibble(
ord_1 = cut(rnorm(200), breaks = c(-Inf, -1, 0, 1, Inf), labels = c("A", "B", "C", "D")),
ord_2 = cut(rnorm(200, mean = 1), breaks = c(-Inf, -1, 0, 1, Inf), labels = c("A", "B", "C", "D")),
ord_3 = cut(rnorm(200, mean = -1), breaks = c(-Inf, -1, 0, 1, Inf), labels = c("A", "B", "C", "D")),
ord_4 = cut(rnorm(200, mean = 0), breaks = c(-Inf, -1, 0, 1, Inf), labels = c("A", "B", "C", "D"))
)
GG_ordinal(xx)
GG_ordinal(xx, order = "negative")
GG_ordinal(xx, order = "none")

#long form
xx %>% pivot_longer(everything()) %>% GG_ordinal(vars = "value", group = "name")

Deleetdk/kirkegaard documentation built on Feb. 28, 2025, 5:04 p.m.