Skip to contents

An undirected graph composed of vertex dots and edge lines. Supports multiple layout algorithms (spring, circular, grid, tree, spectral) with optional igraph integration for more advanced layouts.

Super classes

manimR::MObject -> manimR::VMobject -> Graph

Public fields

vertices

Named list of vertex MObjects keyed by vertex id

edges

List of edge VMobjects

vertex_ids

Character vector of vertex identifiers

edge_list

List of c(from, to) pairs

layout_name

Name of the layout used

positions

Named list of vertex positions

vertex_config

Default vertex appearance

edge_config

Default edge appearance

labels

Named list of vertex label MObjects

Methods

Inherited methods


Method new()

Create a Graph

Usage

Graph$new(
  vertices,
  edges,
  layout = "spring",
  vertex_config = NULL,
  edge_config = NULL,
  labels = NULL,
  ...
)

Arguments

vertices

Character vector of vertex ids (or integer count)

edges

List of c(from, to) pairs or 2-column matrix

layout

Layout algorithm ("spring", "circular", "grid", "tree", "spectral", "random", "kamada_kawai", or a named list of positions)

vertex_config

List of default vertex appearance options

edge_config

List of default edge appearance options

labels

Named list of labels or TRUE for automatic labels

...

Additional args


Method get_vertex()

Get a vertex mobject by id

Usage

Graph$get_vertex(id)

Arguments

id

Vertex identifier


Method get_edge()

Get an edge mobject by vertex pair

Usage

Graph$get_edge(from, to)

Arguments

from

Source vertex id

to

Target vertex id


Method change_layout()

Change the layout of the graph

Usage

Graph$change_layout(layout)

Arguments

layout

New layout name or position list

Returns

Self (for chaining)


Method highlight_vertex()

Highlight a vertex

Usage

Graph$highlight_vertex(id, color = YELLOW, scale = 1.5)

Arguments

id

Vertex identifier

color

Highlight color

scale

Scale factor


Method highlight_edge()

Highlight an edge

Usage

Graph$highlight_edge(from, to, color = YELLOW, stroke_width = 4)

Arguments

from

Source vertex

to

Target vertex

color

Highlight color

stroke_width

Highlighted stroke width


Method to_igraph()

Convert to igraph object (requires igraph package)

Usage

Graph$to_igraph()


Method clone()

The objects of this class are cloneable with this method.

Usage

Graph$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.