prepare_plot_data | R Documentation |
Prepares data for plotting by calculating positions based on provided variable positions and orders.
prepare_plot_data(
data,
cat_a,
cat_b,
cat_c,
group,
var_positions,
cat_a_order,
cat_b_order
)
data |
A data frame containing the variables. |
cat_a |
The name of the column representing category A. |
cat_b |
The name of the column representing category B. |
cat_c |
The name of the column representing category C. |
group |
The name of the column representing the grouping variable. |
var_positions |
A data frame with variable positions, typically output from |
cat_a_order |
A vector specifying the order of category A. |
cat_b_order |
A vector specifying the order of category B. |
A data frame ready for plotting with added x_pos and y_pos columns.
library(dplyr)
data <- data.frame(
cat_a = rep(letters[1:3], each = 4),
cat_b = rep(LETTERS[1:2], times = 6),
cat_c = rep(c("Var1", "Var2"), times = 6),
group = rep(c("G1", "G2"), times = 6)
)
var_positions <- data.frame(
var = c("Var1", "Var2"),
x_offset = c(0.1, -0.1),
y_offset = c(0.1, -0.1)
)
cat_a_order <- c("a", "b", "c")
cat_b_order <- c("A", "B")
prepare_plot_data(data, "cat_a", "cat_b", "cat_c", "group", var_positions, cat_a_order, cat_b_order)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.