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", weighted=NULL), 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)
graph.edgelist(el, directed=TRUE), directed=TRUE)
graph.extended.chordal.ring(n, w)
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, for graph.lattice and graph.ring it is FALSE. For the mode argument sh
The number of vertices in the graph for most functions.

For graph this 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

For graph.adjacency the possible values of this argument are
  • directed
{the graph will be directed and a matrix element gives the number of edges between two vertex.} undirected

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. 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 graph.lattice, it creates a one dimensional circular lattice.

graph.tree creates regular trees.

graph.full simply creates full graphs.

graph.atlas creates graphs from the book An Atlas of Graphs by Roland C. Read and Robin J. Wilson. The atlas contains all undirected graphs with up to seven vertices, numbered from 0 up to 1252. The graphs are listed:

{in increasing order of number of nodes;} {for a fixed number of nodes, in increasing order of the number of edges;} {for fixed numbers of nodes and edges, in increasing order of the degree sequence, for example 111223 < 112222;} {for fixed degree sequence, in increasing number of automorphisms.}


  • Every function documented here returns a graph object.


graph.lattice(dimvector = NULL, length = NULL, dim = NULL, nei = 1, directed = FALSE, mutual = FALSE, circular = FALSE, ...)


  • weighted
  • center
  • dimvector
  • nei
  • mutual
  • circular
  • length
  • dim
  • children
  • loops
  • graph
  • el
  • d
  • w




  • W
  • W
  • W

  • graph.empty
  • graph
  • graph.adjacency
  • graph.lattice
  • graph.ring
  • graph.tree
  • graph.full
  • graph.atlas
  • graph.edgelist
  • graph.extended.chordal.ring
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 )
adjm <- matrix(sample(0:5, 100, replace=TRUE,
                      prob=c(0.9,0.02,0.02,0.02,0.02,0.02)), nc=10)
g4 <- graph.adjacency(adjm, weighted=TRUE)
g5 <-, mode="out")
g6 <- graph.lattice(c(5,5,5))
g7 <- graph.lattice(length=5, dim=3)
g8 <- graph.ring(10)
g9 <- graph.tree(10, 2)
g10 <- graph.full(5, loops=TRUE)
g11 <- graph.atlas(sample(0:1252, 1))
el <- matrix( c("foo", "bar", "bar", "foobar"), nc=2, byrow=TRUE)
g12 <- graph.edgelist(el)
d <-
d$weight <- 1:2
g13 <-
g14 <- graph.extended.chordal.ring(15, matrix(c(3,12,4,7,8,11), nr=2))
Documentation reproduced from package igraph, version 0.4.4, License: GPL version 2 or later (June, 1991)

Community examples

Looks like there are no examples yet.