| prepare.graph {ivue} | R Documentation |
Prepare Graph Data for Visualization
Description
Validate graph input and expose vertex IDs, edge order, weights, and
attributes without loading rgl, opening a device, or computing a layout.
The prepared object can be inspected and reused by plot3D.graph().
Usage
prepare.graph(graph, vertices = NULL, directed = NULL, weight.type = NULL)
Arguments
graph |
A named list with adj.list and weight.list (neighbors are row
indices); a list with edges and vertices; a weighted data frame with from,
to, weight columns plus the vertices argument; a numerical square adjacency
matrix; a Matrix sparse adjacency matrix; or an igraph object. Matrices use
zero for absent edges; use lists/tables to represent zero-weight edges.
A graph returned by |
vertices |
Explicit vertex IDs or a data frame with a unique id column. Required for edge-table input, including isolated vertices. Adjacency lists default to list names, or character row numbers when unnamed. |
directed |
Logical directedness; NULL uses stored directedness or FALSE. This release rejects directed rendering, self-loops, and parallel edges. Undirected adjacency lists must be reciprocal with equal weights. |
weight.type |
"distance", "strength", or "unweighted". Required for weighted layout algorithms but not supplied-coordinate drawing. The fr algorithm requires strengths; kk requires distances. No inversion occurs. Unweighted mode only accepts missing or unit weights. |
Details
Vertex order is preserved. Edge-table input retains edge row order;
reciprocal undirected adjacency input retains one copy of each edge, from
the lower vertex index. Matrix inputs follow that adjacency convention.
edge.col and edge.width follow this prepared edge order and are never
inferred automatically from weights. Isolates remain in the vertex table.
Prepared objects are revalidated on reuse; editing them does not bypass
validation. Directed data can be prepared but cannot currently be rendered.
Missing weights require explicit weight.type = "unweighted".
Value
An ivue_graph list with vertices (a data frame with canonical
character id plus supplied attributes), edges (a data frame with
integer from and to row indices into vertices, numerical weight,
and supplied attributes), directed, and weight.type.
Examples
edges <- data.frame(from = "a", to = "b", weight = 2)
graph <- prepare.graph(edges, vertices = c("a", "b", "isolate"),
weight.type = "strength")
graph$vertices
graph$edges
widths <- 1 + graph$edges$weight
X <- rbind(b = c(1, 0, 0), isolate = c(0, 1, 0), a = c(0, 0, 0))
values <- c(isolate = 3, a = 1, b = 2)
if (nzchar(system.file(package = "rgl"))) {
w <- plot3D.graph(graph, X = X, values = values, edge.width = widths)
}