Network Visualization with jjarcdiagram
ClinicoPath Development Team
2025-07-13
Source:vignettes/jjstatsplot-24-jjarcdiagram-comprehensive.Rmd
jjstatsplot-24-jjarcdiagram-comprehensive.Rmd
Introduction
The jjarcdiagram()
function in ClinicoPath provides
elegant network visualization using arc diagrams. Arc diagrams are
particularly effective for displaying hierarchical relationships,
sequential connections, and network structures with minimal visual
clutter.
Key Features
- Multiple Network Types: Social networks, organizational hierarchies, gene regulation, supply chains
- Flexible Layouts: Horizontal and vertical arrangements
- Dynamic Sizing: Nodes sized by degree centrality or fixed values
- Group Coloring: Automatic color assignment based on categorical variables
- Weight Visualization: Arc thickness proportional to connection strength
- Network Analytics: Built-in calculation of network metrics and centrality measures
- Interactive Customization: Extensive styling and layout options
This vignette demonstrates all features of the jjarcdiagram function using various real-world network datasets.
Loading Required Libraries and Data
library(ClinicoPath)
# Load the original arc diagram dataset
data("arcDiagram")
# Preview the data structure
str(arcDiagram)
head(arcDiagram)
Data Requirements
The jjarcdiagram function works with edge list data representing network connections:
Required Variables:
- Source Node: Starting point of connections (factor or character)
- Target Node: Endpoint of connections (factor or character)
Basic Arc Diagram
Simple Network Visualization
# Basic arc diagram without weights or groups
jjarcdiagram(
data = arcDiagram,
source = "source",
target = "target",
showNodes = TRUE,
horizontal = TRUE,
plotTitle = "Basic Network Structure",
group = NULL,
weight = NULL
)
Network with Edge Weights
# Arc diagram with edge weights
jjarcdiagram(
data = arcDiagram,
source = "source",
target = "target",
weight = "weight",
arcWidth = "weight",
showNodes = TRUE,
plotTitle = "Weighted Network Connections",
group = NULL
)
Network with Group Colors
# Arc diagram with group-based coloring
jjarcdiagram(
data = arcDiagram,
source = "source",
target = "target",
weight = "weight",
group = "group",
colorByGroup = TRUE,
showLegend = TRUE,
showStats = TRUE,
plotTitle = "Network with Group-Based Coloring"
)
Advanced Network Datasets
Social Network Analysis
# Load social network test data
data("jjarcdiagram_social_network")
# Preview the social network data
str(social_network_data)
head(social_network_data)
# Create social network visualization
jjarcdiagram(
data = social_network_data,
source = "source",
target = "target",
weight = "weight",
group = "group",
colorByGroup = TRUE,
showLegend = TRUE,
nodeSize = "degree",
sortNodes = "degree",
sortDecreasing = TRUE,
showStats = TRUE,
plotTitle = "Social Network Analysis - Relationship Strength"
)
Academic Collaboration Network
# Load academic collaboration data
data("jjarcdiagram_academic_network")
# Preview the academic network data
str(academic_network_data)
head(academic_network_data)
# Create academic collaboration visualization
jjarcdiagram(
data = academic_network_data,
source = "author1",
target = "author2",
weight = "publications",
group = "department",
colorByGroup = TRUE,
showLegend = TRUE,
nodeSize = "degree",
arcWidth = "weight",
sortNodes = "group",
showStats = TRUE,
plotTitle = "Academic Collaboration Network by Department"
)
Organizational Hierarchy
# Load organizational hierarchy data
data("jjarcdiagram_org_hierarchy")
# Preview the organizational data
str(org_hierarchy_data)
head(org_hierarchy_data)
# Create organizational hierarchy visualization
jjarcdiagram(
data = org_hierarchy_data,
source = "employee",
target = "reports_to",
weight = "relationship_strength",
group = "department",
colorByGroup = TRUE,
showLegend = TRUE,
directed = TRUE,
sortNodes = "group",
nodeSize = "degree",
horizontal = FALSE,
showStats = TRUE,
plotTitle = "Organizational Reporting Structure"
)
Gene Regulatory Network
# Load gene regulatory network data
data("jjarcdiagram_gene_network")
# Preview the gene network data
str(gene_network_data)
head(gene_network_data)
# Create gene regulatory network visualization
jjarcdiagram(
data = gene_network_data,
source = "regulator",
target = "target",
weight = "regulation_score",
group = "pathway",
colorByGroup = TRUE,
showLegend = TRUE,
nodeSize = "degree",
arcWidth = "weight",
sortNodes = "degree",
sortDecreasing = TRUE,
showStats = TRUE,
plotTitle = "Gene Regulatory Network by Pathway"
)
Supply Chain Network
# Load supply chain data
data("jjarcdiagram_supply_chain")
# Preview the supply chain data
str(supply_chain_data)
head(supply_chain_data)
# Create supply chain visualization
jjarcdiagram(
data = supply_chain_data,
source = "supplier",
target = "customer",
weight = "volume",
group = "industry",
colorByGroup = TRUE,
showLegend = TRUE,
nodeSize = "degree",
arcWidth = "weight",
sortNodes = "group",
horizontal = TRUE,
showStats = TRUE,
plotTitle = "Supply Chain Network by Industry"
)
Layout and Styling Options
Horizontal vs Vertical Layouts
# Horizontal layout
jjarcdiagram(
data = simple_weighted_network,
source = "from_node",
target = "to_node",
weight = "connection_weight",
horizontal = TRUE,
showNodes = TRUE,
plotTitle = "Horizontal Arc Diagram"
)
# Vertical layout
jjarcdiagram(
data = simple_weighted_network,
source = "from_node",
target = "to_node",
weight = "connection_weight",
horizontal = FALSE,
showNodes = TRUE,
plotTitle = "Vertical Arc Diagram"
)
Node Sizing Options
# Fixed node size
jjarcdiagram(
data = academic_network_data,
source = "author1",
target = "author2",
weight = "publications",
group = "department",
nodeSize = "fixed",
nodeSizeValue = 3,
colorByGroup = TRUE,
plotTitle = "Fixed Node Sizes"
)
# Degree-based node sizing
jjarcdiagram(
data = academic_network_data,
source = "author1",
target = "author2",
weight = "publications",
group = "department",
nodeSize = "degree",
colorByGroup = TRUE,
plotTitle = "Degree-Based Node Sizing"
)
Arc Width Customization
# Fixed arc width
jjarcdiagram(
data = supply_chain_data,
source = "supplier",
target = "customer",
weight = "volume",
arcWidth = "fixed",
arcWidthValue = 2,
plotTitle = "Fixed Arc Width"
)
# Weight-proportional arc width
jjarcdiagram(
data = supply_chain_data,
source = "supplier",
target = "customer",
weight = "volume",
arcWidth = "weight",
arcWidthValue = 3,
plotTitle = "Weight-Proportional Arc Width"
)
Arc Transparency Effects
# Test different transparency levels
transparency_levels <- c(0.2, 0.5, 0.8)
for(alpha in transparency_levels) {
cat("\n=== Arc Transparency:", alpha, "===\n")
result <- jjarcdiagram(
data = social_network_data,
source = "source",
target = "target",
weight = "weight",
group = "group",
arcTransparency = alpha,
colorByGroup = TRUE,
plotTitle = paste("Arc Transparency =", alpha)
)
}
Node Sorting and Ordering
Sorting by Different Criteria
# Sort by node names
jjarcdiagram(
data = gene_network_data,
source = "regulator",
target = "target",
weight = "regulation_score",
group = "pathway",
sortNodes = "name",
colorByGroup = TRUE,
plotTitle = "Sorted by Node Names"
)
# Sort by degree centrality
jjarcdiagram(
data = gene_network_data,
source = "regulator",
target = "target",
weight = "regulation_score",
group = "pathway",
sortNodes = "degree",
sortDecreasing = TRUE,
colorByGroup = TRUE,
plotTitle = "Sorted by Degree (Descending)"
)
# Sort by groups
jjarcdiagram(
data = gene_network_data,
source = "regulator",
target = "target",
weight = "regulation_score",
group = "pathway",
sortNodes = "group",
colorByGroup = TRUE,
showLegend = TRUE,
plotTitle = "Sorted by Groups"
)
Network Direction Options
Directed vs Undirected Networks
# Directed network (default for hierarchical data)
jjarcdiagram(
data = org_hierarchy_data,
source = "employee",
target = "reports_to",
weight = "relationship_strength",
group = "department",
directed = TRUE,
colorByGroup = TRUE,
plotTitle = "Directed Network (Organizational Hierarchy)"
)
# Undirected network (treat connections as bidirectional)
jjarcdiagram(
data = org_hierarchy_data,
source = "employee",
target = "reports_to",
weight = "relationship_strength",
group = "department",
directed = FALSE,
colorByGroup = TRUE,
plotTitle = "Undirected Network (Mutual Relationships)"
)
Edge Case Scenarios
Minimal Networks
# Load minimal test data
data("jjarcdiagram_minimal_network")
# Visualize minimal network
jjarcdiagram(
data = minimal_network_data,
source = "from",
target = "to",
weight = "strength",
group = "category",
colorByGroup = TRUE,
showStats = TRUE,
plotTitle = "Minimal Network (3 nodes)"
)
Networks with Self-loops
# Load self-loop test data
data("jjarcdiagram_selfloop_network")
# Visualize network with self-loops
jjarcdiagram(
data = selfloop_network_data,
source = "node1",
target = "node2",
weight = "weight",
group = "type",
colorByGroup = TRUE,
showNodes = TRUE,
showStats = TRUE,
plotTitle = "Network with Self-loops"
)
Large Networks
# Load large network test data
data("jjarcdiagram_large_network")
# Preview large network
cat("Large network size:", nrow(large_network_data), "edges\n")
cat("Unique nodes:", length(unique(c(large_network_data$source, large_network_data$target))), "\n")
# Visualize large network
jjarcdiagram(
data = large_network_data,
source = "source",
target = "target",
weight = "weight",
group = "cluster",
colorByGroup = TRUE,
nodeSize = "degree",
sortNodes = "degree",
sortDecreasing = TRUE,
arcWidth = "weight",
showStats = TRUE,
plotTitle = "Large Network (50+ nodes)"
)
Network Analytics and Statistics
Network Metrics Interpretation
# Generate comprehensive network statistics
jjarcdiagram(
data = academic_network_data,
source = "author1",
target = "author2",
weight = "publications",
group = "department",
colorByGroup = TRUE,
showStats = TRUE,
nodeSize = "degree",
sortNodes = "degree",
plotTitle = "Academic Network with Comprehensive Statistics"
)
Understanding Network Metrics
The network statistics provide valuable insights:
- Network Density: Ratio of actual to possible connections (0-1 scale)
- Connectivity: Whether all nodes can reach each other
- Degree Centrality: Number of connections per node
- Betweenness Centrality: Nodes that act as bridges between others
Customization and Styling
Custom Colors and Labels
# Custom plot with enhanced labeling
jjarcdiagram(
data = social_network_data,
source = "source",
target = "target",
weight = "weight",
group = "group",
colorByGroup = TRUE,
showLegend = TRUE,
labelSize = 1.2,
nodeSize = "degree",
nodeSizeValue = 2.5,
arcWidth = "weight",
arcTransparency = 0.7,
plotTitle = "Customized Social Network Visualization",
showStats = TRUE
)
Multiple Group Variables
# Compare different grouping strategies
# grouping_vars <- c("group", "interaction_type")
# for(var in grouping_vars) {
# cat("\n=== Grouping by", var, "===\n")
# result <- jjarcdiagram(
# data = social_network_data,
# source = "source",
# target = "target",
# weight = "weight",
# group = var,
# colorByGroup = TRUE,
# showLegend = TRUE,
# plotTitle = paste("Grouped by", var)
# )
# }
Clinical and Research Applications
Biological Networks
# Gene regulation network analysis
jjarcdiagram(
data = gene_network_data,
source = "regulator",
target = "target",
weight = "regulation_score",
group = "effect_type",
colorByGroup = TRUE,
showLegend = TRUE,
nodeSize = "degree",
sortNodes = "degree",
showStats = TRUE,
plotTitle = "Gene Regulatory Network by Effect Type"
)
Organizational Analysis
# Department-level analysis
jjarcdiagram(
data = org_hierarchy_data,
source = "employee",
target = "reports_to",
weight = "relationship_strength",
group = "level",
colorByGroup = TRUE,
showLegend = TRUE,
directed = TRUE,
sortNodes = "group",
horizontal = FALSE,
showStats = TRUE,
plotTitle = "Organizational Structure by Hierarchy Level"
)
Collaboration Networks
# Research collaboration analysis
jjarcdiagram(
data = academic_network_data,
source = "author1",
target = "author2",
weight = "collaboration_years",
group = "department",
colorByGroup = TRUE,
showLegend = TRUE,
nodeSize = "degree",
arcWidth = "weight",
sortNodes = "degree",
sortDecreasing = TRUE,
showStats = TRUE,
plotTitle = "Long-term Research Collaborations"
)
Performance and Scalability
Handling Different Network Sizes
# Compare performance with different network sizes
network_sizes <- list(
"Small" = minimal_network_data,
"Medium" = social_network_data,
"Large" = large_network_data
)
for(size_name in names(network_sizes)) {
data_set <- network_sizes[[size_name]]
n_nodes <- length(unique(c(data_set[[1]], data_set[[2]])))
n_edges <- nrow(data_set)
cat("\n=== Network Size:", size_name, "===\n")
cat("Nodes:", n_nodes, ", Edges:", n_edges, "\n")
}
Best Practices and Recommendations
Data Preparation Guidelines
- Data Quality: Ensure clean source and target identifiers
- Weight Scaling: Normalize weights for better visualization
- Group Selection: Choose meaningful categorical variables
- Edge Validation: Remove duplicate or invalid connections
Visualization Guidelines
- Layout Choice: Use horizontal for wide networks, vertical for tall ones
- Node Sizing: Use degree-based sizing for centrality emphasis
- Color Coding: Limit groups to 8-10 for clarity
- Arc Transparency: Use 0.5-0.7 for overlapping connections
Analysis Workflow
- Explore Data Structure: Check node distribution and edge patterns
- Basic Visualization: Start with simple layout and default settings
- Add Grouping: Include categorical variables for insights
- Customize Appearance: Adjust sizing, colors, and layout
- Analyze Metrics: Review network statistics for interpretation
Advanced Features
Network Comparison
# Compare networks with different parameters
comparison_data <- academic_network_data
# Network sorted by names
jjarcdiagram(
data = comparison_data,
source = "author1",
target = "author2",
weight = "publications",
group = "department",
sortNodes = "name",
colorByGroup = TRUE,
plotTitle = "Academic Network - Alphabetical Order"
)
# Network sorted by centrality
jjarcdiagram(
data = comparison_data,
source = "author1",
target = "author2",
weight = "publications",
group = "department",
sortNodes = "degree",
sortDecreasing = TRUE,
colorByGroup = TRUE,
plotTitle = "Academic Network - Centrality Order"
)
Dynamic Network Properties
# Analyze temporal aspects using collaboration years
jjarcdiagram(
data = academic_network_data,
source = "author1",
target = "author2",
weight = "collaboration_years",
group = "department",
colorByGroup = TRUE,
showLegend = TRUE,
arcWidth = "weight",
nodeSize = "degree",
showStats = TRUE,
plotTitle = "Collaboration Duration Network"
)
Conclusion
The jjarcdiagram()
function provides a powerful and
flexible approach to network visualization that is particularly
well-suited for:
Key Advantages:
- Clarity: Minimal visual clutter compared to traditional network plots
- Scalability: Handles networks from 3 to 100+ nodes effectively
- Flexibility: Supports various network types and data formats
- Analytics: Built-in network metrics and centrality measures
- Customization: Extensive styling and layout options
Ideal Use Cases:
- Hierarchical Networks: Organizational charts, taxonomy trees
- Sequential Processes: Workflow diagrams, pipeline analysis
- Collaboration Networks: Research partnerships, social connections
- Biological Networks: Gene regulation, protein interactions
- Supply Chains: Manufacturing and distribution networks
Best Applications:
- Networks with clear directional flow
- Hierarchical or semi-hierarchical structures
- Medium-sized networks (10-100 nodes)
- Networks where edge overlap is problematic in traditional layouts
For additional resources and advanced network analysis techniques, see the ClinicoPath documentation and other visualization vignettes in this package.