Learn R Programming

cograph

cograph is a modern R package that provides tools for the analysis, visualization, and manipulation of dynamical, social and complex networks. The package supports multiple network formats and offers flexible tools for heterogeneous, multi-layer, and hierarchical network analysis with simple syntax and extensive tool-set.

Key features:

  • Tools for analysis, visualization, and manipulation of dynamical, social, and complex networks
  • Provides network metrics including centrality measures, motif analysis, and community detection
  • Supports multiple input formats: adjacency matrices, edge lists, and igraph objects
  • Tools for heterogeneous, multi-layer, and hierarchical network analysis
  • Publication-ready plotting with customizable layouts, node shapes, edge styles, and themes
  • Intuitive, pipe-friendly API
  • Fully compatible with the tna package

Installation

# Install from CRAN (when available)
#install.packages("cograph")

# Or install the development version from GitHub
# install.packages("devtools")
#devtools::install_github("sonsoleslp/cograph")
library(cograph)

Plotting Transition Network Analysis

library(tna)
tna_obj <- tna(group_regulation)
splot(tna_obj)

Simple network plotting

# 10-node directed transition matrix (TNA-style)
set.seed(42)
states <- c("Explore", "Plan", "Monitor", "Evaluate", "Adapt",
            "Reflect", "Regulate", "Execute", "Collaborate", "Review")
mat <- matrix(runif(100, 0, 0.3), nrow = 10, dimnames = list(states, states))
diag(mat) <- 0
mat <- mat / rowSums(mat)  # row-normalize

cograph supports statistical edge visualization with CI underlays and significance notation.

# Publication-ready with CI underlays and labels
splot(mat,
  edge_ci = runif(sum(mat > 0), 0.05, 0.2), layout = "oval",
  edge_label_template = "{est}{stars}",
  edge_label_p = runif(sum(mat > 0), 0, 0.1),
  edge_label_stars = TRUE, edge_label_bg = "transparent", edge_label_color = "maroon", 
  edge_label_size = 0.5, edge_label_position = 0.6
)

Template placeholders: {est}, {low}, {up}, {range}, {p}, {stars}

Pie Chart Nodes and shapes

set.seed(1)
# Each node gets a vector of pie segment values
pie_vals <- lapply(1:10, function(i) runif(4))
pie_cols <- c("#E41A1C", "#377EB8", "#4DAF4A", "#FF7F00")

splot(mat,
  node_shape = "pie",
  pie_values = pie_vals,
  pie_colors = pie_cols,  node_size = 10,
  layout = "oval"
)

# Per-node color palettes
pie_cols_multi <- list(
  c("#E63946", "#F1FAEE", "#A8DADC"),
  c("#264653", "#2A9D8F", "#E9C46A"),
  c("#F72585", "#7209B7", "#3A0CA3"),
  c("#003049", "#D62828", "#F77F00"),
  c("#606C38", "#283618", "#DDA15E"),
  c("#0077B6", "#00B4D8", "#90E0EF"),
  c("#9B2226", "#AE2012", "#BB3E03"),
  c("#023047", "#219EBC", "#8ECAE6"),
  c("#5F0F40", "#9A031E", "#FB8B24"),
  c("#2D00F7", "#6A00F4", "#8900F2")
)
splot(mat,
  node_shape = "pie",
  pie_values = lapply(1:10, function(i) runif(3)),
  pie_colors = pie_cols_multi,
  node_size = 10,
  layout = "oval"
)

Donut Nodes

fills <- runif(10, 0.3, 0.95)

# Per-node donut color palettes
donut_cols_multi <- list(
  c("#003049", "#D62828", "#F77F00", "#FCBF49"),
  c("#606C38", "#283618", "#DDA15E", "#BC6C25"),
  c("#0077B6", "#00B4D8", "#90E0EF", "#CAF0F8"),
  c("#9B2226", "#AE2012", "#BB3E03", "#CA6702"),
  c("#5F0F40", "#9A031E", "#FB8B24", "#E36414"),
  c("#023047", "#219EBC", "#8ECAE6", "#FFB703"),
  c("#264653", "#2A9D8F", "#E9C46A", "#F4A261"),
  c("#F72585", "#B5179E", "#7209B7", "#560BAD"),
  c("#10002B", "#240046", "#3C096C", "#5A189A"),
  c("#D8F3DC", "#B7E4C7", "#95D5B2", "#74C69D")
)
splot(mat,
  donut_values = lapply(1:10, function(i) runif(4)),
  donut_colors = donut_cols_multi,
  donut_inner_ratio = 0.55,
  node_size = 8
)

# Donut + Pie combo: outer donut ring with inner pie segments
  splot(mat,
  node_shape = "donut",
  donut_fill = fills,
  donut_shape = c("circle", "hexagon", "square", "diamond", "triangle",
                  "pentagon", "circle", "hexagon", "square", "diamond"),
  donut_color = palette_viridis(10)
)

plot_htna() - Heterogeneous Multi-Group Networks

plot_htna() creates multi-group network layouts where node groups are arranged in geometric patterns (bipartite, triangle, rectangle, polygon, or circular).

layout(t(1:2)); par(mar=c(0,0,0,0))
# Create network with 3 groups
set.seed(42)
nodes <- paste0("N", 1:15)
m <- matrix(runif(225, 0, 0.3), 15, 15)
diag(m) <- 0
colnames(m) <- rownames(m) <- nodes

node_types <- list(
  Teacher = paste0("N", 1:5),
  Student = paste0("N", 6:10),
  System = paste0("N", 11:15)
)

# Polygon layout (triangle for 3 groups)
plot_htna(m, node_types, layout = "polygon", minimum = 0.15)

# Circular layout (groups as arcs)
plot_htna(m, node_types, layout = "circular", minimum = 0.15)

plot_mtna() - Multi-Cluster Networks

plot_mtna() visualizes multiple network clusters with summary edges between clusters and individual edges within clusters. Each cluster is displayed as a shape (circle, square, diamond, triangle) containing its nodes.

par(mar=c(0,0,0,0))
# Create network with 6 clusters
set.seed(42)
nodes <- paste0("N", 1:30)
m <- matrix(runif(900, 0, 0.3), 30, 30)
diag(m) <- 0
colnames(m) <- rownames(m) <- nodes

clusters <- list(
  Alpha = paste0("N", 1:5),
  Beta = paste0("N", 6:10),
  Gamma = paste0("N", 11:15),
  Delta = paste0("N", 16:20),
  Epsilon = paste0("N", 21:25),
  Zeta = paste0("N", 26:30)
)

# Summary edges between clusters + individual edges within
plot_mtna(m, clusters)

Key parameters: * spacing: Distance between cluster centers * shape_size: Size of cluster shells * node_spacing: Node placement within shapes (0-1) * shapes: Vector of shapes per cluster (“circle”, “square”, “diamond”, “triangle”) * summary_edges: Show aggregated between-cluster edges (default TRUE) * within_edges: Show individual within-cluster edges (default TRUE)

Alias: mtna() is available as a shorthand for plot_mtna().

plot_mlna() - Multilevel 3D Networks

plot_mlna() visualizes multilevel/multiplex networks where multiple layers are stacked in a 3D perspective view. Each layer contains nodes connected by solid edges (within-layer), while dashed lines connect nodes between adjacent layers (inter-layer edges).

par(mar=c(0,0,0,0))
# Create multilevel network
set.seed(42)
nodes <- paste0("N", 1:21)
m <- matrix(runif(441, 0, 0.3), 21, 21)
diag(m) <- 0
colnames(m) <- rownames(m) <- nodes

# Define 3 layers
layers <- list(
  Macro = paste0("N", 1:7),
  Meso = paste0("N", 8:14),
  Micro = paste0("N", 15:21)
)

# Basic usage with spring layout
plot_mlna(m, layers, layout = "spring", minimum = 0.18, legend = FALSE)

License

MIT License. See LICENSE for details.

Copy Link

Version

Install

install.packages('cograph')

Version

1.5.2

License

MIT + file LICENSE

Maintainer

Sonsoles López-Pernas

Last Published

March 2nd, 2026

Functions in cograph (1.5.2)

atan2_usr

Aspect-Corrected atan2
arrow_points

Calculate Arrow Head Points
arrow_radius

Calculate Arrow Radius
bezier_points

Calculate Bezier Curve Points
arrow_head_points

Calculate Arrow Head Points
arrow_base_midpoint

Calculate Arrow Base Midpoint
as_cograph

Convert to Cograph Network
as_cograph_network

Create cograph_network S3 class wrapper
cograph

Create a Network Visualization
cograph-main

Main Entry Point
compute_connectivity_jitter_horizontal

Compute Connectivity-Based Jitter (Horizontal Layout)
cloud_vertices

Generate Cloud Vertices
compute_connectivity_jitter_vertical

Compute Connectivity-Based Jitter (Vertical Layout)
cograph-package

cograph: Modern Network Visualization
cent_to_edge

Calculate Point on Node Boundary
circle_vertices

Generate Circle Vertices
build_edge_labels_from_template

Build Edge Labels from Template
brain_vertices

Generate Brain Vertices
detect_duplicate_edges

Detect Duplicate Edges in Undirected Network
curve_control_point

Calculate Control Point for Curved Edge
compute_adaptive_esize

Compute Adaptive Base Edge Size
compute_circular_layout

Compute Circular Layout
create_grid_grob

Create Grid Grob Tree
create_edges_df

Create Edge Data Frame
create_nodes_df

Create Node Data Frame
draw_curved_arrow_base

Draw Curved Arrow Head
draw_cloud

Draw Cloud Node
diamond_vertices

Generate Diamond Vertices
cross_vertices

Generate Cross/Plus Vertices
compute_polygon_layout

Compute Polygon Layout
draw_curved_edge

Draw Curved Edge
draw_circle_arrow_base

Draw Circle Arrow (Dot)
draw_arrow_base

Draw Arrow Head
draw_brain

Draw Brain Node
compute_layout_gephi_fr

Wrapper for Gephi FR Layout (for layout registry)
draw_chip

Draw Chip Node
draw_double_donut_pie_node_base

Draw Double Donut with Inner Pie
draw_curve_with_start_segment

Draw Curve with Optional Start Segment
draw_chip_node_base

Draw Chip Node (Base R)
draw_gear

Draw Gear Node
draw_donut

Draw Donut Node
draw_network_node_base

Draw Network Node (Base R)
draw_circle

Draw Circle Node
draw_double_donut_pie

Draw Double Donut with Inner Pie Node
draw_diamond

Draw Diamond Node
draw_ellipse

Draw Ellipse Node
draw_edge_label_base

Draw Edge Label
draw_database_node_base

Draw Database Node (Base R)
draw_donut_pie

Draw Donut with Inner Pie Node
draw_cross

Draw Cross/Plus Node
draw_curved_edge_base

Draw Curved Edge with xspline (qgraph-style)
draw_donut_pie_node_base

Draw Donut with Inner Pie
draw_neural_node_base

Draw Neural Node (Base R)
draw_heart

Draw Heart Node
draw_donut_node_base

Draw Donut Chart Node
draw_node_base

Draw a Single Node
draw_database

Draw Database Node
draw_polygon_donut_node_base

Draw Polygon Donut Node (Base R)
draw_network

Draw Network Node
draw_pentagon

Draw Pentagon Node
draw_pie

Draw Pie Node
draw_hexagon

Draw Hexagon Node
draw_polygon_donut

Draw Polygon Donut Node
draw_pie_node_base

Draw Pie Chart Node
draw_straight_edge_base

Draw Straight Edge
draw_robot_node_base

Draw Robot Node (Base R)
draw_self_loop

Draw Self-Loop
draw_robot

Draw Robot Node
draw_svg_shape

Draw SVG Shape (Grid)
draw_triangle

Draw Triangle Node
draw_svg_shape_base

Draw SVG Shape (Base R)
draw_straight_edge

Draw Straight Edge
draw_star

Draw Star Node
get_edges

Get Edges from Cograph Network
from_qgraph

Convert a qgraph object to cograph parameters
get_labels

Get Labels from Cograph Network
format_pvalue

Format P-value
draw_self_loop_base

Draw Self-Loop Edge (qgraph-style)
fontface_to_string

Convert Numeric Fontface to String
draw_neural

Draw Neural Node
gear_vertices

Generate Gear Vertices
from_tna

Convert a tna object to cograph parameters
draw_node_label_base

Draw Node Label
draw_square

Draw Square Node
format_edge_label_template

Format Edge Label from Template
draw_open_arrow_base

Draw Open Arrow Head
get_donut_base_vertices

Get Polygon Vertices by Shape Name
get_edge_order

Get Edge Rendering Order
format_ci_range

Format CI Range
get_edge_label_position

Get Label Position on Edge
get_shape

Get a Registered Shape
get_nodes

Get Nodes from Cograph Network
find_curve_split_index

Find Split Index for Curve Based on Arc Length Fraction
get_layout

Get a Registered Layout
fontface_to_numeric

Convert Fontface String to Numeric
handle_deprecated_param

Handle Deprecated Parameter
ellipse_vertices

Generate Ellipse Vertices
edge_endpoint

Calculate Edge Endpoint on Node Border
globals

Global Registries for cograph
get_template_from_style

Get Template from Style Preset
get_scale_constants

Get Scaling Constants
get_shape_vertices

Get Shape Vertices
filter_edges_by_weight

Filter Edges by Weight Threshold
get_theme

Get a Registered Theme
get_x_scale

Get X-axis Scale Factor (inches per user unit)
get_svg_shape

Get Registered SVG Shape
get_node_order

Get Node Rendering Order
input-igraph

igraph Input Parsing
get_significance_stars

Get Significance Stars from P-values
get_y_scale

Get Y-axis Scale Factor (inches per user unit)
input-edgelist

Edge List Input Parsing
expand_param

Expand Parameter to Length (Strict)
init_registries

Initialize Global Registries
input-matrix

Matrix Input Parsing
hexagon_vertices

Generate Hexagon Vertices
input-parse

Input Parsing Functions
in_to_usr_y

Convert Inches to User Coordinates (Y-axis)
layout_groups

Group-based Layout
layout-groups

Group-based Layout
output-save

Output and Saving
layout-spring

Fruchterman-Reingold Spring Layout
is_cograph_theme

Check if object is a CographTheme
inset_polygon_vertices

Inset Polygon Vertices
layout-registry

Layout Registry Functions
input-statnet

Statnet Network Input Parsing
input-tna

tna Input Parsing
layout-circle

Circular Layout
layout_bipartite_fn

Bipartite Layout
layout-oval

Oval/Ellipse Layout
layout_random_fn

Random Layout
has_package

Check if a package is available
input-qgraph

qgraph Input Parsing
layout_grid_fn

Grid Layout
heart_vertices

Generate Heart Vertices
layout_gephi_fr

Gephi Fruchterman-Reingold Layout
layout_spring

Fruchterman-Reingold Spring Layout
list_svg_shapes

List Registered SVG Shapes
layout_circle

Circular Layout
palette_blues

Blues Palette
map_node_colors

Map Node Colors by Group
methods-plot

Plot Methods
in_to_usr_x

Convert Inches to User Coordinates (X-axis)
map_edge_colors

Map Edge Colors by Weight
is_directed

Check if Network is Directed
methods-print

Print Methods
is_symmetric_matrix

Detect if Matrix is Symmetric
layout_custom_fn

Custom Layout (passthrough)
layout_star_fn

Star Layout
is_cograph_network

Check if object is a CographNetwork
layout_oval

Oval Layout
list_shapes

List Available Shapes
list_palettes

List Available Color Palettes
parse_svg

Parse SVG Content
list_layouts

List Available Layouts
palette_pastel

Pastel Palette
perp_mid

Calculate Perpendicular Midpoint for Curved Edges
palette_colorblind

Colorblind-friendly Palette
list_themes

List Available Themes
palette_rainbow

Rainbow Palette
nodes

Get Nodes from Cograph Network (Deprecated)
offset_point

Offset Point from Center
palette_diverging

Diverging Palette
plot_mtna

Multi-Cluster TNA Network Plot
palette_viridis

Viridis Palette
palette_reds

Reds Palette
map_qgraph_lty

Map qgraph lty codes to cograph edge style names
pentagon_vertices

Generate Pentagon Vertices
map_qgraph_shape

Map qgraph shape names to cograph equivalents
point_on_circle

Calculate Point on Circle
palettes

Color Palettes
n_edges

Get Number of Edges
n_nodes

Get Number of Nodes
parse_input

Parse Network Input
point_angle

Calculate Angle Between Two Points
qgraph_cent_to_edge_simple

qgraph Point on Node Boundary
qgraph_norm_curve

qgraph Curve Normalization Factor
print.cograph_network

Print cograph_network Object
plot.cograph_network

Plot cograph_network Object
qgraph_default_esize

qgraph Default Edge Size
plot_mlna

Multilevel Network Visualization
point_distance

Calculate Distance Between Two Points
qgraph_default_vsize

qgraph Default Node Size
qgraph_arrow_size

qgraph-style Arrow Size Calculation
plot_htna

Plot Heterogeneous TNA Network (Multi-Group Layout)
render_edge_labels_grid

Render Edge Labels
rectangle_vertices

Generate Rectangle Vertices
register_builtin_layouts

Register Built-in Layouts
render_edges_splot

Render Edges for splot
recycle_to_length

Recycle Value to Length
qgraph_vsize_to_user

qgraph Node Size to User Coordinates
register_layout

Register a Custom Layout
plot_tna

TNA-Style Network Plot (qgraph Compatible)
render_edges_grid

Render All Edges
register_builtin_palettes

Register Built-in Palettes
resolve_edge_widths

Resolve Edge Widths
render-edges

Edge Rendering
render-grid

Grid Rendering
render_nodes_splot

Render Nodes for splot
qgraph_plot_info

Get Plot Dimension Info
qgraph_scale_edge_widths

qgraph Edge Width Scaling (EXACT)
register_builtin_shapes

Register Built-in Shapes
rescale_layout

Rescale Layout to -1 to 1 Range
register_builtin_themes

Register Built-in Themes
qgraph_cent2edge

qgraph Cent2Edge (EXACT - critical formula)
register_theme

Register a Custom Theme
register_shape

Register a Custom Shape
register_svg_shape

Register Custom SVG Shape
render_legend_splot

Render Legend for splot
render_legend_grid

Render Legend
resolve_node_colors

Resolve Node Colors
resolve_label_sizes

Resolve Label Sizes
render_node_labels_grid

Render Node Labels
render-ggplot

ggplot2 Conversion
resolve_aesthetic

Resolve Aesthetic Value
resolve_curvatures

Resolve Curvature Parameter
regular_polygon_vertices

Generate Regular Polygon Vertices
render-nodes

Node Rendering
render_nodes_grid

Render All Nodes
render_nodes_base

Render All Nodes
scale-constants

Scaling Constants
resolve_edge_colors

Resolve Edge Colors
resolve_edge_labels

Resolve Edge Labels
scale_alpha

Create an Alpha Scale
resolve_labels

Resolve Labels
resolve_loop_rotation

Resolve Loop Rotation
set_edges

Set Edges in Cograph Network
resolve_node_sizes

Resolve Node Sizes
scale_width

Create a Width Scale
set_layout

Set Layout in Cograph Network
set_nodes

Set Nodes in Cograph Network
scale_edge_widths_simple

Scale Edge Widths (Simple Version)
scale_color_discrete

Create a Categorical Color Scale
scale_size

Create a Size Scale
resolve_stars

Resolve Stars from Various Inputs
scale_edge_widths

Scale Edge Widths Based on Weights
resolve_shapes

Resolve Shape Parameter
scale_node_sizes

Scale Node Sizes
scale_color

Create a Color Scale
shapes-registry

Shape Registry Functions
shapes-basic

Basic Node Shapes
sn_edges

Set Edge Aesthetics
shapes-svg

Custom SVG Node Shapes
shapes-special

Special Node Shapes
sn_ggplot

Convert Network to ggplot2
sn_save_ggplot

Save as ggplot2
sn_palette

Apply Color Palette to Network
sn_layout

Apply Layout to Network
sn_save

Save Network Visualization
sn_nodes

Set Node Aesthetics
shorten_edge_for_arrow

Calculate Shortened Edge Endpoint
sn_theme

Apply Theme to Network
splot-geometry

Base R Graphics Geometry Utilities
splot-params

splot Parameter Vectorization Helpers
soplot

Plot Cograph Network
splot-edges

Base R Edge Rendering
splot-arrows

Base R Arrow Drawing
splot-polygons

Base R Polygon Shape Definitions
sonplot-qgraph-geometry

qgraph-Compatible Geometry Utilities
splot-nodes

Base R Node Rendering
splot-labels

Edge Label Template Formatting
splot_distance

Calculate Distance Between Two Points
theme_cograph_dark

Dark Theme
splot

Base R Graphics Network Plotting
theme_cograph_classic

Classic Theme
theme_cograph_gray

Grayscale Theme
splot_angle

Calculate Angle Between Two Points
summary.cograph_network

Summary of cograph_network Object
star_vertices

Generate Star Vertices
theme_cograph_colorblind

Colorblind-friendly Theme
square_vertices

Generate Square Vertices
theme_cograph_nature

Nature Theme
themes-registry

Theme Registry Functions
usr_to_in_x

Convert User Coordinates to Inches (X-axis)
theme_cograph_minimal

Minimal Theme
theme_cograph_viridis

Viridis Theme
unregister_svg_shape

Unregister SVG Shape
themes-builtin

Built-in Themes
triangle_vertices

Generate Triangle Vertices
tna_color_palette

Generate TNA-style Color Palette for Nodes
usr_to_in_y

Convert User Coordinates to Inches (Y-axis)
utils-validation

Input Validation Utilities
utils-deprecation

Deprecation Utilities
validate_color

Validate Color
validate_network

Validate Network Object
validate_choice

Validate Choice
validate_length

Validate Length Match
zzz

Package Load and Unload Functions
validate_range

Validate Numeric Range
utils-colors

Color Utilities
utils-geometry

Geometry Utilities
CographLayout

CographLayout R6 Class
aes-edges

Edge Aesthetics
aes-nodes

Node Aesthetics
COGRAPH_SCALE_LEGACY

Legacy Scaling Constants (Pre-v2.0 Behavior)
CographTheme

CographTheme R6 Class
COGRAPH_SCALE

cograph Scaling Constants
aggregate_duplicate_edges

Aggregate Duplicate Edges
aes-scales

Aesthetic Scale Functions
QGRAPH_SCALE

qgraph Scaling Constants (Exact Values)
CographNetwork

CographNetwork R6 Class