Learn R Programming

diceplot (version 0.1.7)

order_cat_b: Order Category B

Description

Determines the ordering of category B based on the counts within each group, ordered by group and count.

Usage

order_cat_b(data, group, cat_b, group_colors, reverse_order = FALSE)

Value

A vector of category B labels ordered according to group and count.

Arguments

data

A data frame containing the variables.

group

The name of the column representing the grouping variable.

cat_b

The name of the column representing category B.

group_colors

A named vector of colors for each group. The names correspond to group names.

reverse_order

Reverse the ordering? Default is FALSE.

Examples

Run this code
library(dplyr)
data <- data.frame(
  group = rep(c("G1", "G2"), each = 5),
  cat_b = sample(LETTERS[1:3], 10, replace = TRUE)
)
group_colors <- c("G1" = "red", "G2" = "blue")
order_cat_b(data, "group", "cat_b", group_colors)

Run the code above in your browser using DataLab