Learn R Programming

diceplot (version 0.2.0)

prepare_plot_data: Prepare Plot Data

Description

Prepares data for plotting by calculating positions based on provided variable positions and orders.

Usage

prepare_plot_data(
  data,
  cat_a,
  cat_b,
  cat_c,
  group,
  var_positions,
  cat_a_order,
  cat_b_order
)

Value

A data frame ready for plotting with added x_pos and y_pos columns.

Arguments

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 create_var_positions.

cat_a_order

A vector specifying the order of category A.

cat_b_order

A vector specifying the order of category B.

Examples

Run this code
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)

Run the code above in your browser using DataLab