plotParallel: Create a 2-variable parallel sets diagrams

View source: R/func_basics.R

plotParallelR Documentation

Create a 2-variable parallel sets diagrams

Description

This function uses the ggforce package to produce a parallel sets diagram for visualising interaction between 2 variables.

Usage

plotParallel(
  lab1,
  lab2,
  labels = c("label1", "label2"),
  color = NULL,
  add_counts = FALSE,
  add_breakdown = FALSE,
  text_size = 5,
  xlab_size = 14,
  theme_size = 18
)

Arguments

lab1, lab2

Each is a character vector containing membership information.

labels

A character vector of length 2 containing the labels for lab1 and lab2. Default is c("label1", "label2").

color

A character vector of colour codes indicating the colours of the elements in the parallel sets diagram. Default is NULL, and use choosePalette() to select a palette.

add_counts

Logical scalar indicating whether to show total counts of each element with the labels. Default is FALSE.

add_breakdown

A string to control which side to show the detailed breakdown of counts. Allowable character values are "left", "right" and "both" (same as add_breakdown = TRUE). Use add_breakdown = FALSE to disable breakdown. Default is FALSE.

text_size

A numeric scalar indicating the size of membership labels. Default is 5.

xlab_size

A numeric scalar indicating the size of main categorical label. Default is 14.

theme_size

A numeric scalar indicating the base font size. Default is 18.

Value

A ggplot object

Author(s)

I-Hsuan Lin

See Also

ggforce::geom_parallel_sets()

Examples

library(ggforce)
data <- as.data.frame(Titanic)
plotParallel(data$Class, data$Age, labels = c("class", "age"))

# Load demo dataset
data(sce)

plotParallel(sce$label, sce$CellType,
  labels = c("Cluster", "Cell Type"),
  add_counts = TRUE
)

ycl6/scRUtils documentation built on Feb. 18, 2025, 6:14 a.m.