Creates an interactive graph visualization using the G6 graph visualization library. This function is the main entry point for creating G6 graph visualizations in R.
Usage
g6(
nodes = NULL,
edges = NULL,
combos = NULL,
width = "100%",
height = NULL,
elementId = NULL
)
Arguments
- nodes
A data frame or list of nodes in the graph. Each node should have at least an "id" field. See 'Data Structure' section for more details. Default: NULL.
- edges
A data frame or list of edges in the graph. Each edge should have "source" and "target" fields identifying the connected nodes. See 'Data Structure' section for more details. Default: NULL.
- 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 printed, included in R Markdown documents, or used in Shiny applications.
Details
The g6
function creates a G6 graph as an htmlwidget that can be used in R Markdown,
Shiny applications, or rendered to HTML. It takes graph data in the form of nodes, edges,
and optional combo groupings, along with various configuration options for customizing
the appearance and behavior of the graph.
Nodes
The nodes
parameter should be a data frame or list of nodes with at least an id
field
for each node. Additional fields can include:
id
(required): Unique identifier for the node. Must be a character.type
: Node type (e.g., "circle", "rect", "diamond").data
: Custom data associated with the node.style
: List of style attributes (color, size, etc.).states
: String. Initial states for the node, such as selected, active, hover, etc.combo
: ID of the combo this node belongs to.
Edges
The edges
parameter should be a data frame or list of edges with at least source
and
target
fields identifying the connected nodes. Additional fields can include:
source
(required): ID of the source node. Must be a character.target
(required): ID of the target node. Must be a character.id
: Unique identifier for the edge.type
: Edge type (e.g., "line", "cubic", "arc").data
: Custom data associated with the edge.style
: List of style attributes (color, width, etc.).states
: String. Initial states for the edge.
Combos
The combos
parameter is used for grouping nodes and can be a data frame or list with
combo definitions. Fields include:
id
(required): Unique identifier for the combo. Must be a character.type
: String: Combo type. It can be the type of built-in Combo, or the custom Combo.data
: Custom data associated with the combo.style
: List of style attributes.states
: String. Initial states for the combo.combo
: String. Parent combo ID. If there is no parent combo, it is null.
Nodes are assigned to combos by setting their combo
field to the ID of the combo.
Examples
# Create a simple graph with two nodes and one edge
nodes <- data.frame(
id = c("node1", "node2")
)
edges <- data.frame(
source = "node1",
target = "node2"
)
g6(nodes = nodes, edges = edges)