graph.constructors {igraph}R Documentation

Various methods for creating graphs

Description

These method can create various (mostly regular) graphs: empty graphs, graphs with the given edges, graphs from adjacency matrices, star graphs, lattices, rings, trees.

Usage

graph.empty(n=0, directed=TRUE)
graph(edges, n=max(edges)+1, directed=TRUE)
graph.adjacency(adjmatrix, mode="directed", weighted=NULL)
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)
graph.atlas(n)
graph.edgelist(el, directed=TRUE)
graph.data.frame(d, directed=TRUE)
graph.extended.chordal.ring(n, w)

Arguments

edges 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.
adjmatrix A square adjacency matrix.
directed 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 graph.star the mode argument should be used for creating an undirected graph.
n 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 the largest id is not an isolate.
For graph.atlas this is the number (id) of the graph to create.
mode 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
    this is the same as max, for convenience.
    max
    undirected graph will be created and the number of edges between vertex i and j is max(A(i,j), A(j,i)).
    upper
    undirected graph will be created, only the upper right triangle (including the diagonal) is used for the number of edges.
    lower
    undirected graph will be created, only the lower left triangle (including the diagonal) is used for creating the edges.
    min
    undirected graph will be created with min(A(i,j), A(j,i)) edges between vertex i and j.
    plus
    undirected graph will be created with A(i,j)+A(j,i) edges between vertex i and j.

For graph.star it defines the direction of the edges, in: the edges point to the center, out: the edges point from the center, undirected: the edges are undirected.
For igraph.tree this parameter defines the direction of the edges. out indicates that the edges point from the parent to the children, in indicates that they point from the children to their parents, while undirected creates an undirected graph.
weighted This argument specifies whether to create a weighted graph from an adjacency matrix. If it is NULL then an unweighted graph is created and the elements of the adjacency matrix gives the number of edges between the vertices. If it is a character constant then for every non-zero matrix entry an edge is created and the value of the entry is added as an edge attribute named by the weighted argument. If it is TRUE then the name of the edge attribute will be weight.
center For graph.star the center vertex of the graph, by default the first vertex.
dimvector A vector giving the size of the lattice in each dimension, for graph.lattice.
nei The distance within which (inclusive) the neighbors on the lattice will be connected. This parameter is not used right now.
mutual Logical, if TRUE directed lattices will be mutually connected.
circular Logical, if TRUE the lattice or ring will be circular.
length Integer constant, for regular lattices, the size of the lattice in each dimension.
dim Integer constant, the dimension of the lattice.
children Integer constant, the number of children of a vertex (except for leafs) for graph.tree.
loops If TRUE also loops edges (self edges) are added.
graph An object.
el An edge list, a two column matrix, character or numeric. See details below.
d A data frame object, this will be converted to a graph.
w A matrix which specifies the extended chordal ring. See details below.

Details

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 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.

graph.edgelist creates a graph from an edge list. Its argument is a two-column matrix, each row defines one edge. If it is a numeric matrix then its elements are interpreted as vertex ids. If it is a character matrix then it is interpreted as symbolic vertex names and a vertex id will be assigned to each name, and also a name vertex attribute will be added.

graph.data.frame creates a graph from a data frame. The data frame should have at least two columns. The first two columns will be used as a symbolic edge list and the other columns will be added as edge attributes.

graph.extended.chordal.ring creates an extended chordal ring. An extended chordal ring is regular graph, each node has the same degree. It can be obtained from a simple ring by adding some extra edges specified by a matrix. Let p denote the number of columns in the ‘W’ matrix. The extra edges of vertex i are added according to column i mod p in ‘W’. The number of extra edges is the number of rows in ‘W’: for each row j an edge i->i+w[ij] is added if i+w[ij] is less than the number of total nodes. See also Kotsis, G: Interconnection Topologies for Parallel Processing Systems, PARS Mitteilungen 11, 1-6, 1993.

Value

Every function documented here returns a graph object.

Author(s)

Gabor Csardi csardi@rmki.kfki.hu

Examples

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)
E(g4)$weight
g5 <- graph.star(10, 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 <- as.data.frame(el)
d$weight <- 1:2
g13 <- graph.data.frame(d)
g14 <- graph.extended.chordal.ring(15, matrix(c(3,12,4,7,8,11), nr=2))

[Package igraph version 0.4.2 Index]