Learn R Programming

cograph (version 1.5.2)

sn_ggplot: Convert Network to ggplot2

Description

Convert a Cograph network visualization to a ggplot2 object for further customization and composability.

Usage

sn_ggplot(network, title = NULL)

Value

A ggplot2 object.

Arguments

network

A cograph_network object, matrix, data.frame, or igraph object. Matrices and other inputs are auto-converted.

title

Optional plot title.

Examples

Run this code
adj <- matrix(c(0, 1, 1, 1, 0, 1, 1, 1, 0), nrow = 3)
# With cograph()
p <- cograph(adj) |> sn_ggplot()
print(p)

# Direct matrix input
p <- adj |> sn_ggplot()

# Further customization
p + ggplot2::labs(title = "My Network")

Run the code above in your browser using DataLab