Various methods for creating graphs
These method can create various (mostly regular) graphs: empty graphs, graphs with the given edges, graphs from adjacency matrices, star graphs, lattices, rings, trees.
graph.empty(n=0, directed=TRUE) graph(edges, n=max(edges)+1, directed=TRUE) graph.adjacency(adjmatrix, mode="directed") graph.star(n, mode = "in", center = 0) graph.lattice(dimvector, nei = 1, directed = FALSE, mutual = FALSE, circular = FALSE) graph.lattice(length, dim, nei = 1, directed = FALSE, mutual = FALSE, circular = FALSE) graph.ring(n, directed = FALSE, mutual = FALSE, circular=TRUE) graph.tree(n, children = 2, mode="out") graph.full(n, directed = FALSE, loops = FALSE)
- Numeric vector defining the edges, the first edge points from the first element to the second, the second edge from the third to the fourth, etc.
- A square adjacency matrix.
- Logical, if TRUE a directed graph will be
created. Note that for while most constructors the default is TRUE,
graph.ringit is FALSE. For
- The number of vertices in the graph.
graphthis parameter is ignored if there is a bigger vertex id in
edges. This means that for this function it is safe to supply zero here if the vertex with the largest id is
graph.adjacencythe possible values of this argument are
All these functions create graphs in a deterministic way.
graph.empty is the simplest one, this creates an empty graph.
graph creates a graph with the given edges.
graph.adjacency creates a graph from an adjacency matrix.
graph.star creates a star graph, in this every single vertex is
connected to the center vertex and nobody else.
graph.lattice is a flexible function, it can create lattices of
arbitrary dimensions, periodic or unperiodic ones.
graph.ring is actually a special case of
it creates a one dimensional circular lattice.
graph.tree creates regular trees.
graph.full simply creates full graphs.
- Every function documented here returns a
graph.lattice(dimvector = NULL, length = NULL, dim = NULL, nei = 1, directed = FALSE, mutual = FALSE, circular = FALSE, ...)
g1 <- graph.empty() g2 <- graph( c(1,2,2,3,3,4,5,6), directed=FALSE ) adjm <- matrix(sample(0:1, 100, replace=TRUE, prob=c(0.9,0.1)), nc=10) g3 <- graph.adjacency( adjm ) g4 <- graph.star(10, mode="out") g5 <- graph.lattice(c(5,5,5)) g6 <- graph.lattice(length=5, dim=3) g7 <- graph.ring(10) g8 <- graph.tree(10, 2) g9 <- graph.full(5, loops=TRUE)