Build a radial hierarchy from one counted leaf ledger, keep parent totals consistent, and make narrow outer sectors inspectable.
Sunburst charts: reconcile the leaf ledger before drawing rings
One record belongs to one leaf
A sunburst partitions a whole into nested categories. The center represents the root, the next ring divides it into top-level groups, and each outward ring divides its parent again. Start from records or an explicitly aggregated leaf ledger, with one complete path per counted item. The same support ticket cannot appear once under Email and again under Chat unless the measure is deliberately ticket-channel events rather than distinct tickets. State that grain next to the chart. A root total of 47 tickets means every first-ring wedge must add to 47, and each branch must equal the sum of its immediate children when the branches represent totals. A separate parent count entered from another report is a common double-counting route. The preparation code below derives parent totals from leaves. Treemaps share the accounting requirement; grain and denominator checks establish what the area means.
Treat absent categories as data, not empty geometry
An incomplete classification is still a counted record. Give it an explicit category such as Unassigned at the first stage where classification is absent, or stop its path at a documented terminal node. Do not distribute its count across known children to make the ring appear complete. If one branch stops at depth two while another reaches depth four, the outer rings describe different levels of detail; the caption must say so. This lesson uses three-level paths so every ticket has the same depth and comparison is direct. Repeated label text in different branches does not imply the same node: the full path is the identifier. For example, Resolved under Email and Resolved under Portal are two separate sectors. Preserve full-path IDs in hover text, exports, and keyboard focus targets. Missingness and export manifests cover the adjoining data contract.
Read angular share against the right parent
A sector's angle communicates its share of the root at its depth, while a child-to-parent percentage answers a different question. Show both numerator and denominator in a tooltip or adjacent table. In the worked ledger, the Support branch contains 33 of 47 tickets, so it spans roughly 253 degrees of the first ring. Within Support, Email accounts for 19 of 33, not 19 of 47. A viewer cannot recover those denominators reliably from a small arc alone. Freeze branch order for repeated reports; re-sorting by the latest count makes equal categories move around the circle between periods. Use a stable color mapping for the first ring, then related shades or labels for descendants. If every small leaf receives a different saturated color, color stops carrying a useful meaning. Stacked bars are often clearer when only two levels matter.
Provide a route out of crowded outer rings
The outer ring can contain dozens of thin sectors even when its parent occupies a generous angle. Do not turn a two-pixel arc into the only way to discover a category. Expose a searchable hierarchy table with full path, count, share of parent and share of root. Keyboard users should be able to enter a branch, inspect children and return to the same focus position. If categories are grouped into Other, define the threshold in counts or root share, retain the original leaves in the downloadable ledger, and never combine categories across different parents merely because their labels match. A sunburst is strongest for following hierarchy and relative composition, not for precise comparison between distant narrow sectors. For precise ranking, pair it with a bar view. Chart accessibility and waffle charts offer alternatives for small shares.
Worked contract
from collections import Counter
def prepare_ticket_sunburst(leaf_ledger):
totals = Counter()
if not leaf_ledger:
raise ValueError("leaf ledger cannot be empty")
for path, ticket_count in leaf_ledger:
if (not isinstance(path, tuple) or len(path) != 3 or
any(not isinstance(label, str) or not label.strip() for label in path) or
isinstance(ticket_count, bool) or not isinstance(ticket_count, int) or
ticket_count <= 0):
raise ValueError("each leaf needs three labels and a positive count")
for depth in range(4):
totals[path[:depth]] += ticket_count
for path, parent_count in totals.items():
if len(path) == 3:
continue
child_sum = sum(count for child, count in totals.items()
if len(child) == len(path) + 1 and child[:-1] == path)
assert parent_count == child_sum
return totals
ticket_leaves = [
(("Support", "Email", "Resolved"), 14),
(("Support", "Email", "Escalated"), 5),
(("Support", "Chat", "Resolved"), 11),
(("Support", "Chat", "Escalated"), 3),
(("Billing", "Portal", "Resolved"), 8),
(("Billing", "Portal", "Escalated"), 4),
(("Billing", "Phone", "Unassigned"), 2),
]
totals = prepare_ticket_sunburst(ticket_leaves)
assert totals[()] == 47
assert totals[("Support",)] == 33
assert totals[("Support", "Email")] == 19
assert round(totals[("Support",)] / totals[()] * 360) == 253Performance and operating cost
Let R be the number of leaf-ledger rows, D the path depth and N the number of distinct hierarchy nodes. Accumulating prefixes takes O(RD) time and O(N) space. The audit loop shown compares each parent with all nodes, so its simple form costs O(N²) time; for a large hierarchy, keep a child-sum counter during the same prefix pass and reduce reconciliation to O(RD + N). The code prepares totals, not drawing coordinates. A renderer assigns a parent interval first, then partitions that interval among children using the derived totals and a fixed category order. It must not sum the root and branch totals again as if each were independent data.
Common Mistakes
- Counting the same record under multiple leaves without changing the measure definition.
- Supplying independent parent values that exceed or disagree with their children.
- Merging identical leaf labels from different parents instead of using full-path IDs.
- Interpreting a sector's root share as its share of its immediate parent.
- Leaving narrow outer-ring categories inaccessible without a searchable table.
Validation drill
Build a three-stage classification for 47 customer tickets. Introduce an Unassigned path for records lacking a final outcome, reconcile every parent with its children, and report both parent share and root share for the smallest leaf before drawing any arcs.
Read next
- Treemaps: validate hierarchy and leaf totals before assigning area
- Aggregation grain and denominator: make every plotted mark auditable
- Interactive charts: make selection work without a pointer
- Stacked bars: separate composition from volume and preserve denominators
