November 19, 2015
library("igraph") # We will use it a lot read.graph(file, format = c("edgelist", "pajek", "ncol", "lgl", "graphml", "dimacs","graphdb", "gml", "dl"), ...)
Read the web as:
And write it as:
Edge.list <- matrix(c("a","b","a","c", "b","a","b","b", "c","b"),ncol=2, byrow=TRUE)
Which translates to:
Edge.list <- matrix(c("a","b","a","c", "b","a","b","b", "c","b"),ncol=2, byrow=TRUE) Edge.list
## [,1] [,2] ## [1,] "a" "b" ## [2,] "a" "c" ## [3,] "b" "a" ## [4,] "b" "b" ## [5,] "c" "b"
Read the web as:
And write it as:
Adjacency.matrix <- matrix(c(0,1,1, 1,1,0, 0,1,0), nrow=3,ncol=3, byrow=TRUE) row.names(Adjacency.matrix) <- colnames(Adjacency.matrix) <- c("a","b","c")
Which translates to:
Adjacency.matrix
## a b c ## a 0 1 1 ## b 1 1 0 ## c 0 1 0
igraph can read those webs easily:
graph.data.frame(Edge.list,directed=TRUE) -> Edge.web
The order matters: FROM -> TO.
graph.adjacency(Adjacency.matrix,mode="directed") -> Adjacency.web
Notice we have to use two different functions.
plot(Edge.web)
plot(Adjacency.web)