Learn R Programming

g6R (version 0.1.0)

g6_igraph: Create a G6 Graph from an igraph Object

Description

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
)

Value

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

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).

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

Run this code
if (require(igraph)) {
  g <- igraph::make_ring(5)
  g6_igraph(g)
}

Run the code above in your browser using DataLab