spiral_newrle: Render a Spiral Plot Using Run-Length Encoding

View source: R/EnrichmentSpiralize.R

spiral_newrleR Documentation

Render a Spiral Plot Using Run-Length Encoding

Description

This function creates a spiral plot for visualizing sequential data in a compact and visually appealing way. It uses run-length encoding to represent the lengths and colors of sequences in the spiral.

Usage

spiral_newrle(x, samples, values, colors, labels = FALSE)

Arguments

x

A vector representing categories or segments.

samples

A vector indicating the sample each segment belongs to.

values

Numeric vector indicating the lengths of each segment.

colors

Character vector specifying the colors for each segment.

labels

Logical, whether to add labels to each segment.

Value

No return value, called for side effects. This function generates a spiral plot and optionally adds labels.

Examples

# Example: Creating a spiral plot using the spiral_newrle function

# Define example data
x <- c("A", "A", "B", "C")
samples <- c("Sample1", "Sample1", "Sample2", "Sample2")
values <- c(20, 30, 15, 35)
colors <- c("red", "blue", "green", "purple")
labels <- TRUE

# Initialize the spiral plot, setting the x-axis range and scaling
spiralize::spiral_initialize(xlim = c(0, sum(values)), scale_by = "curve_length",
                 vp_param = list(x = grid::unit(0, "npc"), just = "left"))

# Create a track for the spiral plot
spiralize::spiral_track(height = 0.5)

# Add segments to the spiral plot using run-length encoding
spiral_newrle(x, samples, values, colors, labels)


TransProR documentation built on April 4, 2025, 3:16 a.m.