Data Analysis and VisualizationUnit 514 min read
Hierarchical & Tree-Based Visualization: Techniques, Tools & Real-World Applications
Unit 5 of Data Analysis and Visualization explores hierarchical data structures, tree-based visualization techniques (treemaps, dendrograms, sunburst charts), and their applications in decision-making, file systems, and organizational charts. Learn how to encode nested relationships visually, compare techniques with wo
TAKEAWAYS:
- Hierarchical data is nested data (e.g., folders/files, organizational charts) best visualized using tree structures like treemaps, sunburst charts, or dendrograms.
- Treemaps use rectangular areas to show nested proportions (e.g., Daraz’s product categories by revenue), while sunburst charts use radial segments (e.g., eSewa’s transaction types by user).
- Dendrograms (cluster trees) visualize hierarchical clustering (e.g., NTC’s customer segmentation by spending patterns).
- Interactive techniques (collapsible branches, tooltips) improve usability for large hierarchies (e.g., Khalti’s transaction history).
- Real-world tools: D3.js, Tableau, and Python’s
plotlyimplement these visualizations for business analytics. - Exam focus: Compare techniques, explain when to use each, and justify choices for given datasets (e.g., "Detroit dataset" → sunburst for demographic hierarchies).
1. Hierarchical Data: Structure and Representation
Hierarchical data organizes information in parent-child relationships, like:
- Filesystems (folders containing files/subfolders).
- Organizational charts (CEO → managers → employees).
- Biological taxonomies (Kingdom → Phylum → Class → ... → Species).
Key Properties:
- Root node: Top-level parent (e.g., "Root" in a filesystem).
- Leaves: Nodes with no children (e.g., files in a folder).
- Depth: Number of levels (e.g., 3 levels:
Documents/Reports/2023_Q1.pdf). - Branching factor: Average children per node (e.g., 2–5 in org charts).
graph TD
A["Root: eSewa Transactions"] --> B["2023"]
A --> C["2024"]
B --> D["Jan: 500 txns"]
B --> E["Feb: 620 txns"]
D --> F["User A: 120 txns"]
D --> G["User B: 80 txns"]Example: eSewa’s transaction hierarchy by year/month/user. Why it matters: Helps users drill down from high-level summaries (e.g., "2023 revenue") to details (e.g., "User A’s February payments").
2. Tree-Based Visualization Techniques
A. Treemaps
Definition: A space-filling map where:
- Area = value (e.g., revenue, count).
- Color = additional dimension (e.g., profit margin).
- Rectangles = nested categories.
How it works:
- Root rectangle = total value (e.g., 100% of Daraz’s revenue).
- Split children proportionally (e.g., Electronics: 40%, Grocery: 30%).
- Recursively subdivide until leaves (e.g., "Smartphones" under Electronics).
Worked Example: Daraz Product Categories
| Category | Revenue (₹) | % of Total | Color (Profit Margin) |
|---|---|---|---|
| Electronics | 4,000,000 | 40% | Green (High) |
| Grocery | 3,000,000 | 30% | Yellow (Medium) |
| Clothing | 2,000,000 | 20% | Red (Low) |
| Books | 1,000,000 | 10% | Blue (Very Low) |
Visualization:
Advantages:
- Shows part-to-whole relationships clearly.
- Scalable for thousands of items (e.g., NEPSE stock hierarchies). Limitations:
- Overplotting if too many leaves.
- Distortion in aspect ratios (e.g., a 1% category may look tiny).
Real-World Use:
- Microsoft Excel: Built-in treemap for pivot tables.
- Tableau: Drag-and-drop treemaps for sales data.
- eSewa: Visualizing transaction volumes by service type (e.g., Electricity > Water > Internet).
B. Sunburst Charts
Definition: A radial treemap where:
- Angular position = category (e.g., time periods).
- Radius = depth in hierarchy.
- Arc length = value.
How it works:
- Root at center (e.g., "Total Revenue").
- First ring = top-level categories (e.g., "Q1", "Q2").
- Subsequent rings = nested subcategories (e.g., "Q1 → Electronics → Phones").
Worked Example: NTC Customer Segments by Spending
pie
title NTC Revenue by Segment (2023)
"Residential: ₹50M" : 50
"Corporate: ₹30M" : 30
"Government: ₹20M" : 20Expanded Sunburst:
graph TD
A["NTC Revenue (₹100M)"]
A --> B["Residential (50%)"]
A --> C["Corporate (30%)"]
A --> D["Government (20%)"]
B --> E["Prepaid: ₹30M"]
B --> F["Postpaid: ₹20M"]
C --> G["SMEs: ₹15M"]
C --> H["Enterprises: ₹15M"]Advantages:
- Natural for time-based hierarchies (e.g., "Year → Quarter → Month").
- Avoids overplotting better than treemaps for deep hierarchies. Limitations:
- Radial layout can be harder to read for non-technical users.
- Tooling required: Not natively supported in Excel (use Tableau/Power BI).
Real-World Use:
- Google Analytics: Sunbursts for user acquisition paths.
- Pathao: Visualizing ride demand by zone/hour/day.
- NEPSE: Stock performance by sector/industry over time.
C. Dendrograms
Definition: A tree diagram showing hierarchical clustering (e.g., grouping similar items).
- Leaves = individual data points (e.g., customers, products).
- Branches = merge points based on similarity (e.g., Euclidean distance).
How it works:
- Start with all items as separate clusters.
- Merge closest pairs iteratively (e.g., customers with similar spending).
- Draw branches at merge points (height = distance between clusters).
Worked Example: NTC Customer Segmentation
| Customer | Monthly Spend (₹) | Churn Rate (%) |
|---|---|---|
| A | 2,000 | 5% |
| B | 1,800 | 3% |
| C | 500 | 20% |
| D | 450 | 18% |
Cluster Steps:
- Merge A & B (distance = 200).
- Merge C & D (distance = 50).
- Merge (A+B) & (C+D) (distance = 1,300).
graph TD
A["A & B"] -->|"200"| AB["Cluster 1"]
C["C & D"] -->|"50"| CD["Cluster 2"]
AB -->|"1300"| Root["All Customers"]
CD --> RootApplications:
- Market segmentation (e.g., Khalti’s user groups by transaction frequency).
- Anomaly detection (e.g., Ncell’s fraudulent call patterns).
- Genomics: Phylogenetic trees for species evolution.
Tools:
- Python:
scipy.cluster.hierarchy+matplotlib. - R:
dendextendpackage.
D. Other Techniques
| Technique | Use Case | Example |
|---|---|---|
| Icicle Charts | Deep hierarchies (5+ levels) | File system explorer (Windows) |
| Chord Diagrams | Relationships between nodes | eSewa’s payment flows (user → bank → service) |
| Network Graphs | Directed hierarchies (e.g., org charts) | Daraz’s supplier-product links |
3. Design Principles for Hierarchical Visualizations
A. Separation, Order, and Alignment
- Separation: Use white space or color to distinguish branches (e.g., Pathao’s ride categories: Bike, Car, Auto).
- Order: Top-down (root at top) or bottom-up (root at center) based on audience familiarity.
- Alignment: Horizontal (treemaps) or radial (sunbursts) to minimize crossings.
Example: eSewa Transaction Flow
flowchart TD
A["User"] -->|"Initiates"| B["eSewa App"]
B --> C["Payment Gateway"]
C --> D["Bank/NPL"]
D --> E["Service Provider"]
E --> F["User"]B. Word Clouds for Text Hierarchies
Not a tree visualization, but useful for textual hierarchies (e.g., keywords in a document).
- Size = frequency/importance.
- Color = category (e.g., "technology" vs. "finance").
Worked Example: NEPSE Stock Reports
Tools: Python’s wordcloud library, Tableau’s text analysis.
4. Tools and Libraries
| Tool/Library | Platform | Key Features |
|---|---|---|
| Tableau | Desktop/Web | Drag-and-drop treemaps/sunbursts |
| D3.js | Web | Custom interactive hierarchies |
| Python (Plotly) | Jupyter/Notebook | plotly.express.sunburst() |
| Excel | Desktop | Basic treemaps (PivotTable → Insert Visual) |
| Flourish | Web | No-code sunburst/icicle charts |
5. Real-World Applications
A. eSewa: Transaction Hierarchy
- Problem: Users need to see monthly spending by service type.
- Solution: Sunburst chart with:
- Outer ring: Service (Electricity, Water, Internet).
- Inner rings: Months → Transactions.
- Impact: Users identify high-spend categories (e.g., "Internet in Jan") and adjust budgets.
B. Daraz: Product Catalog
- Problem: Sellers need to see category performance (e.g., "Electronics vs. Grocery").
- Solution: Treemap with:
- Area = Revenue.
- Color = Profit margin.
- Impact: Sellers reallocate inventory to high-margin categories.
C. NTC: Customer Churn Analysis
- Problem: Predict which customers are likely to churn.
- Solution: Dendrogram clustering customers by:
- Spending.
- Call frequency.
- Complaint history.
- Impact: Targeted retention campaigns for high-risk clusters.
D. Pathao: Ride Demand Forecasting
- Problem: Drivers need to know peak demand zones/hours.
- Solution: Sunburst chart with:
- Outer ring: Day of week.
- Inner rings: Hour → Zone (e.g., "Mon 8AM → Thamel").
- Impact: Drivers optimize routes for higher earnings.
6. Common Pitfalls and Best Practices
| Pitfall | Solution |
|---|---|
| Overcrowded treemap | Limit to 3–4 levels; use tooltips. |
| Misleading sunburst | Ensure arc lengths match data proportions. |
| Poor clustering in dendrogram | Use domain knowledge to guide merge rules. |
| Ignoring accessibility | Add text labels, avoid red-green contrast. |
Best Practices:
- Start with the root: Guide users from the big picture.
- Use interactivity: Collapsible branches (e.g., Tableau’s drill-down).
- Annotate key insights: Highlight outliers (e.g., "Q4 revenue spike").
- Test with stakeholders: Ask non-technical users to interpret the chart.
7. Exam Tip: How to Score Full Marks
For Short Questions (2–3 Marks):
- Define the technique (e.g., "A treemap is a space-filling visualization...").
- State one use case (e.g., "Daraz uses treemaps to show product category revenue").
- Mention one tool (e.g., "Tableau supports treemaps via drag-and-drop").
For Long Questions (5–7 Marks):
- Introduction: Briefly define hierarchical data and its importance.
- Technique Deep Dive:
- Explain how it works (e.g., "Sunburst charts use radial segments to represent nested proportions").
- Draw a small diagram (use Mermaid or describe it).
- Give a worked example with real numbers (e.g., NTC’s revenue breakdown).
- Comparison: Contrast with another technique (e.g., "Treemaps are better for flat hierarchies, while sunbursts suit time-based data").
- Applications: Link to a real-world scenario (e.g., "eSewa uses sunbursts to analyze transaction patterns").
- Limitations: Mention one drawback (e.g., "Sunbursts can be hard to read for users unfamiliar with radial layouts").
For Dataset-Based Questions (e.g., "Detroit Dataset"):
- Analyze the data: Identify hierarchical structure (e.g., "Demographics → Age Group → Income Level").
- Choose a technique:
- Treemap: If comparing proportions (e.g., "Income distribution by neighborhood").
- Sunburst: If time is a factor (e.g., "Population growth by decade").
- Justify: Explain why your choice is suitable (e.g., "Sunburst shows temporal trends better than a treemap").
- Sketch: Describe how the visualization would look (use Mermaid).
Example Answer Snippet:
"The Detroit dataset’s hierarchical structure (e.g., census tracts → blocks → households) is best visualized using a sunburst chart because it naturally represents nested, time-based hierarchies. For instance, the outer ring could show decades (1980–2020), the next ring census tracts, and the innermost ring income levels. This would reveal trends like 'Income decline in the downtown tract from 1990–2000.' A treemap would work but would obscure temporal patterns. Tools like Tableau or Plotly can generate this interactively, allowing users to drill down from high-level trends to specific blocks."
8. Practice Questions
- Compare treemaps and sunburst charts using Daraz’s product hierarchy as an example. Which would you choose for:
- Showing quarterly revenue by category?
- Showing monthly sales trends for a single category?
- Design a dendrogram to cluster NEPSE stocks by:
- Sector (Banking, IT, Manufacturing).
- Market capitalization.
- 3-month return volatility. Draw the first 3 merge steps.
- Critique this visualization:
graph TD A["Root"] --> B["A"] A --> C["B"] A --> D["C"] A --> E["D"] B --> F["A1"] B --> G["A2"] C --> H["B1"] D --> I["D1"] D --> J["D2"] D --> K["D3"]- What’s wrong with the layout?
- How would you improve it for a treemap?
Based on the TU BCA syllabus for Data Analysis and Visualization (CACS455), unit 5.
Discussion
Loading…