Skip to contents

Converts an igraph graph object into the format required by the g6() function and creates an interactive G6 graph visualization. This is a convenience wrapper around g6() that allows you to work directly with igraph objects.

Usage

g6_igraph(
  graph,
  combos = NULL,
  width = "100%",
  height = NULL,
  elementId = NULL
)

Arguments

graph

An object of class igraph::igraph containing the graph to visualize.

combos

A data frame or list of combo groups in the graph. Each combo should have at least an "id" field. Nodes can be assigned to combos using their "combo" field. See 'Data Structure' section for more details. Default: NULL.

width

Width of the graph container in pixels or as a valid CSS unit. Default: NULL (automatic sizing).

height

Height of the graph container in pixels or as a valid CSS unit. Default: NULL (automatic sizing).

elementId

A unique ID for the graph HTML element. Default: NULL (automatically generated).

Value

An htmlwidget object that can be rendered in R Markdown, Shiny apps, or the R console.

Details

This function extracts the node and edge data from an igraph object, converts them into the appropriate format for G6, and passes them to g6(). Node styling is derived from vertex attributes, and edge styling from edge attributes.

If the graph is directed, edges will automatically be rendered with arrows.

See also

g6() for more information about node, edge, and combo structure.

Examples

if (require(igraph)) {
  g <- igraph::make_ring(5)
  g6_igraph(g)
}
#> Loading required package: igraph
#> 
#> Attaching package: ‘igraph’
#> The following objects are masked from ‘package:stats’:
#> 
#>     decompose, spectrum
#> The following object is masked from ‘package:base’:
#> 
#>     union