API Reference
Complete reference for all exported functions and types.
Main Functions
ChordPlots.cooccurrence_matrix — Function
cooccurrence_matrix(df::DataFrame, columns::Vector{Symbol}; normalize=false)Compute a co-occurrence matrix from a DataFrame.
Each row in the DataFrame represents one observation. Labels from different columns that appear in the same row are considered co-occurring.
Arguments
df::DataFrame: Input datacolumns::Vector{Symbol}: Column names to analyze
Keywords
normalize::Bool=false: If true, normalize counts to frequencies
Returns
CoOccurrenceMatrix: Matrix of co-occurrence counts/frequencies
Example
df = DataFrame(
V_call = ["IGHV1-2*01", "IGHV1-2*01", "IGHV3-23*01"],
D_call = ["IGHD2-2*01", "IGHD3-10*01", "IGHD2-2*01"],
J_call = ["IGHJ6*01", "IGHJ6*01", "IGHJ4*02"]
)
cooc = cooccurrence_matrix(df, [:V_call, :D_call, :J_call])ChordPlots.chordplot — Function
chordplot(cooc::CoOccurrenceMatrix)
chordplot!(ax, cooc::CoOccurrenceMatrix)Create a chord diagram from co-occurrence data.
Attributes
inner_radius = 0.92: Inner radius for ribbons (closer to outer for less wasted space)outer_radius = 1.0: Outer radius for arcsarc_width = 0.08: Width of arc segmentsgap_fraction = 0.03: Gap between arcs as fraction of circleribbon_alpha = 0.65: Transparency for ribbonsribbon_alpha_by_value = false: If true, scale opacity by ribbon value (min 10%, larger ribbons more visible)ribbon_alpha_scale = :linear: Scaling method for value-based opacity (:lineardefault,:logfor better distribution of small integers)ribbon_tension = 0.5: Bezier curve tension (0=straight, 1=tight)show_labels = true: Show labelslabel_offset = 0.12: Distance from arc to label (increase for longer labels to avoid overlap)label_fontsize = 10: Label font sizerotate_labels = true: Rotate labels to follow arcs (prevents upside-down text)label_justify = :inside: Label justification (:insidealigns toward circle center,:outsidealigns away)min_arc_flow = 0: Filter out arcs and labels with total flow below this value (helps reduce overlap from many small segments)colorscheme = :group: Color scheme (:group, :categorical, or AbstractColorScheme)arc_strokewidth = 0.5: Arc border widtharc_strokecolor = :black: Arc border colorarc_alpha = 0.9: Transparency for arcs (slight transparency for modern look)sort_by = :group: How to sort arcs (:group, :value, :none)min_ribbon_value = 0: Hide ribbons below this value
Example
using CairoMakie, ChordPlots, DataFrames
df = DataFrame(
V_call = ["V1", "V1", "V2", "V2", "V3"],
D_call = ["D1", "D2", "D1", "D2", "D1"],
J_call = ["J1", "J1", "J2", "J2", "J1"]
)
cooc = cooccurrence_matrix(df, [:V_call, :D_call, :J_call])
fig, ax, plt = chordplot(cooc)chordplot(df::DataFrame, columns; kwargs...)Create chord plot directly from DataFrame.
ChordPlots.setup_chord_axis! — Function
setup_chord_axis!(ax::Axis)Configure axis for chord plot display (equal aspect, no decorations).
ChordPlots.compute_layout — Function
compute_layout(cooc::CoOccurrenceMatrix{T, S}, config::LayoutConfig=LayoutConfig()) where {T, S}Compute the complete layout for a chord diagram.
Algorithm
- Calculate total flow for each label
- Allocate angular width proportional to flow
- Assign arc positions
- Generate ribbon endpoints based on co-occurrence values
Data Management
ChordPlots.filter_top_n — Function
filter_top_n(cooc::CoOccurrenceMatrix, n::Int)Keep only the top n labels by total flow.
ChordPlots.filter_by_threshold — Function
filter_by_threshold(cooc::CoOccurrenceMatrix{T, S}, min_value::T) where {T, S}Create a new CoOccurrenceMatrix with values below threshold set to zero.
ChordPlots.normalize — Function
normalize(cooc::CoOccurrenceMatrix{T, S}) where {T, S}Return a normalized version where all values sum to 1.
ChordPlots.CoOccurrenceMatrix — Type
CoOccurrenceMatrix{T<:Real, S<:AbstractString}Stores co-occurrence counts between labels with group information.
Type Parameters
T: Numeric type for counts (enables Integer or Float)S: String type for labels
Fields
matrix::Matrix{T}: Symmetric co-occurrence matrixlabels::Vector{S}: Combined list of all labelsgroups::Vector{GroupInfo{S}}: Group informationlabel_to_index::Dict{S, Int}: Fast label lookup
Example
cooc = CoOccurrenceMatrix(df, [:V_call, :D_call, :J_call])
cooc["IGHV1-2*01", "IGHD2-2*01"] # Get co-occurrence countLayout Functions
ChordPlots.filter_ribbons — Function
filter_ribbons(layout::ChordLayout, min_value::Real)Filter ribbons below a minimum value threshold.
ChordPlots.filter_ribbons_top_n — Function
filter_ribbons_top_n(layout::ChordLayout, n::Int)Keep only the top n ribbons by value.
ChordPlots.LayoutConfig — Type
LayoutConfig{T<:Real}Configuration for layout computation.
Fields
inner_radius::T: Inner radius for ribbon attachmentouter_radius::T: Outer radius for arcsgap_fraction::T: Fraction of circle to use for gaps between arcsstart_angle::T: Starting angle (0 = right, π/2 = top)direction::Int: 1 for counterclockwise, -1 for clockwisesort_by::Symbol: How to sort arcs (:group, :value, :none)
ChordPlots.ChordLayout — Type
ChordLayout{T<:Real}Complete layout information for rendering a chord diagram.
Fields
arcs::Vector{ArcSegment{T}}: Arc segments for each labelribbons::Vector{Ribbon{T}}: All ribbonsinner_radius::T: Inner radius for ribbonsouter_radius::T: Outer radius for arcsgap_angle::T: Gap between adjacent arcs
Color Functions
ChordPlots.group_colors — Function
group_colors(cooc::CoOccurrenceMatrix; palette=:default)Create a color scheme based on groups using Makie's default categorical palette (same as AlgebraOfGraphics uses - Wong colors, colorblind-friendly).
Arguments
palette::Symbol: Color palette style (:defaultfor Makie/AoG palette,:modernfor custom)
ChordPlots.gradient_colors — Function
gradient_colors(; colormap=:viridis, min_val=0.0, max_val=1.0)Create a gradient-based color scheme.
ChordPlots.with_alpha — Function
with_alpha(color::Colorant, alpha::Real)Return color with specified alpha value.
ChordPlots.darken — Function
darken(color::Colorant, factor::Real=0.2)Darken a color by the given factor.
ChordPlots.lighten — Function
lighten(color::Colorant, factor::Real=0.2)Lighten a color by the given factor.
ChordPlots.GroupColorScheme — Type
GroupColorScheme{C<:Colorant}Assigns colors based on label groups.
Fields
group_colors::Dict{Symbol, C}: Color for each groupdefault_color::C: Fallback color
ChordPlots.CategoricalColorScheme — Type
CategoricalColorScheme{C<:Colorant}Assigns distinct colors to each label.
Fields
colors::Vector{C}: Color palette
ChordPlots.GradientColorScheme — Type
GradientColorSchemeColors based on a gradient (e.g., by value).
Fields
colormap::Symbol: Makie colormap namerange::Tuple{Float64, Float64}: Value range for mapping
categorical_colors(n::Int; palette=:default) - Create n distinguishable colors using Makie's default categorical palette (same as AlgebraOfGraphics uses - Wong colors, colorblind-friendly).
Geometry Functions
ChordPlots.arc_points — Function
arc_points(start_angle::Real, end_angle::Real, radius::Real; n_points::Int=50)Generate points along an arc.
Arguments
start_angle: Start angle in radiansend_angle: End angle in radiansradius: Arc radiusn_points: Number of points (more = smoother)
Returns
Vector{Point2f}: Points along the arc
ChordPlots.arc_polygon — Function
arc_polygon(inner_radius::Real, outer_radius::Real, start_angle::Real, end_angle::Real; n_points::Int=30)Generate a filled arc (annular sector) as a polygon.
Returns points forming a closed polygon: outer arc → inner arc (reversed) → close.
ChordPlots.ribbon_path — Function
ribbon_path(ribbon::Ribbon, radius::Real; n_bezier::Int=30, tension::Real=0.5)Generate the path for a ribbon connecting two arcs.
The ribbon consists of:
- Source arc segment
- Bezier curve to target
- Target arc segment
- Bezier curve back to source
Arguments
ribbon: Ribbon geometry specificationradius: Radius where ribbons attachn_bezier: Points per Bezier curvetension: Control point tension (0 = straight, 1 = tight curves)
ChordPlots.ribbon_paths — Function
ribbon_paths(ribbons::Vector{Ribbon{T}}, radius::Real; kwargs...)Generate paths for multiple ribbons.
ChordPlots.label_position — Function
label_position(arc::ArcSegment, radius::Real, offset::Real; rotate::Bool=true, justify::Symbol=:inside)Calculate position for an arc's label.
Arguments
arc: Arc segmentradius: Outer radius of the arcoffset: Distance from arc to labelrotate: Whether to rotate label to follow arcjustify: Label justification (:insidealigns toward circle center,:outsidealigns away)
ChordPlots.label_positions — Function
label_positions(arcs::Vector{ArcSegment{T}}, radius::Real, offset::Real; kwargs...)Calculate positions for all arc labels.
Keyword Arguments
rotate::Bool=true: Whether to rotate labels to follow arcsjustify::Symbol=:inside: Label justification (:insideor:outside)
ChordPlots.ArcSegment — Type
ArcSegment{T<:Real}Represents an arc on the outer circle for a single label.
Fields
label_idx::Int: Index into the label arraystart_angle::T: Starting angle in radiansend_angle::T: Ending angle in radiansvalue::T: Total flow value (determines arc width)
ChordPlots.RibbonEndpoint — Type
RibbonEndpoint{T<:Real}Represents one end of a ribbon attached to an arc.
Fields
label_idx::Int: Which label this endpoint is onstart_angle::T: Start angle on the arcend_angle::T: End angle on the arc
ChordPlots.Ribbon — Type
Ribbon{T<:Real}Represents a ribbon connecting two labels.
Fields
source::RibbonEndpoint{T}: Source endpointtarget::RibbonEndpoint{T}: Target endpointvalue::T: Co-occurrence value
ChordPlots.RibbonPath — Type
RibbonPathStores the complete path for rendering a ribbon.
Types
ChordPlots.GroupInfo — Type
GroupInfo{S<:AbstractString}Information about a group of labels (e.g., V calls, D calls, J calls).
Fields
name::Symbol: Group identifierlabels::Vector{S}: Labels belonging to this groupindices::UnitRange{Int}: Index range in the combined label list
Utility Functions
These functions are exported but don't have separate docstrings:
nlabels(cooc)- Number of labels in co-occurrence matrixngroups(cooc)- Number of groupstotal_flow(cooc, label_idx)- Total flow for a label (sum of all connections)get_group(cooc, label_idx)- Get group symbol for a labelnarcs(layout)- Number of arcs in layoutnribbons(layout)- Number of ribbons in layoutarc_span(arc)- Span angle of an arcarc_midpoint(arc)- Midpoint angle of an arcendpoint_span(endpoint)- Span of a ribbon endpointendpoint_midpoint(endpoint)- Midpoint of a ribbon endpointis_self_loop(ribbon)- Check if ribbon is a self-loopresolve_arc_color(scheme, arc, cooc)- Resolve color for an arcresolve_ribbon_color(scheme, ribbon, cooc)- Resolve color for a ribbonchordplot!(ax, cooc; kwargs...)- In-place version ofchordplot