order_cat_b | R Documentation |
Determines the ordering of category B based on the counts within each group, ordered by group and count.
order_cat_b(data, group, cat_b, group_colors, reverse_order = FALSE)
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. |
A vector of category B labels ordered according to group and count.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.