Create a graph object of class graph

Description

Create a graph object of class graphNEL or graphAM. You might also use the graph creating facility provided by the graph package.

Usage

1
newgraph(nodeNames, mat, weights = NULL, directed = FALSE, isAdjacency = FALSE, ...)

Arguments

nodeNames

Numeric or character string vector.

mat

Either an adjacency matrix or a from to matrix.

weights

Numeric weights for edges. Either in the same order as the from to matrix or as a square matrix, depending what one have chosen for the mat argument.

directed

Logical value for defining a directed or undirected graph.

isAdjacency

If argument mat is adjacency matrix.

...

Currently not needed.

Value

graphNEL or grapAM object.

Author(s)

Adrian Waddell and R. Wayne Oldford

See Also

navGraph, completegraph, linegraph

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Using from to matrices
from <- c("A","A","C","C")
to   <- c("B","C","B","D")
ftEmat <- cbind(from,to)

## note how the E node is added
G <- newgraph(nodeNames = LETTERS[1:5], mat = ftEmat)

## say you would like to add weights to the graph
weights <- c(2,1,3,4)
G <- newgraph(nodeNames = LETTERS[1:5], mat = ftEmat, weights = weights)

## newgraph with adjacency matrix
V <- c('s.L', 's.W', 'p.L', 'p.W')
adjM <- matrix(c(0,1,1,0,1,0,1,1,1,1,0,0,0,1,0,0), ncol = 4)
all(adjM == t(adjM)) ## is symmetric (undirected)
G <- newgraph(nodeNames = V, mat= adjM, isAdjacency=TRUE)

## if you use adjacency matrices, you can add a matrix with weights
adjM <-     matrix(c(0,0,1,0,1,0,1,1,0,0,0,0,0,1,0,0), ncol = 4)
weightsM <- matrix(c(0,0,5,0,2,0,1,3,0,0,0,0,0,7,0,0), ncol = 4)
G <- newgraph(nodeNames = V, mat= adjM, weights = weightsM, directed = TRUE, isAdjacency=TRUE)
edgeData(G, attr = "weight")

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.