R/illustration_functions.R
draw_chr_bar.RdCreates a chromosome bar annotation track for ComplexHeatmap visualization, which includes alternating black and grey bars to distinguish chromosomes and chromosome number labels. The function handles both standard (22 autosomes + X, Y) and custom chromosome sets.
draw_chr_bar(window_data)A HeatmapAnnotation object from the ComplexHeatmap package containing:
A text annotation track with chromosome numbers
A binary pattern track with alternating black and grey bars
The function performs the following steps:
Standardizes chromosome column names to lowercase
Computes chromosome lengths and boundaries
Creates alternating binary pattern for visual separation
Calculates mean positions for chromosome labels
Generates chromosome text annotations
if (FALSE) { # \dontrun{
# Create sample window data
window_data <- data.frame(
chr = rep(paste0("chr", c(1:22, "X")), each = 100),
start = 1:2300,
end = 101:2400
)
# Generate chromosome bar annotation
chr_annotation <- draw_chr_bar(window_data)
# Use in ComplexHeatmap
library(ComplexHeatmap)
Heatmap(matrix_data,
top_annotation = chr_annotation)
} # }