Learn R Programming

shp2graph (version 1-0)

nel2igraph: Produce an “igraph” object

Description

A function to produce an “igraph” object with the “nodelist” and “edgelist”, which could be returned by the function readshpnw.

Usage

nel2igraph(nodelist, edgelist, weight = NULL, eadf = NULL, Directed = FALSE)

Value

gr

An “igraph” object

Arguments

nodelist

A “nodelist” object

edgelist

An “edgelist” object

weight

A numberic vector to weight all the edges in the “edgelist”, of which the length equals to the number of edges;

eadf

A data frame of attributes corresponding to all the edges;

Directed

TRUE if edges are directed, FALSE otherwise;

Author

Binbin Lu binbinlu@whu.edu.cn

Details

1. The weighting vector, “weight”, will be used as default for any weigted calculations with edges in the “igraph” object.

2. The coordinate of each node is attached as attributes “X” and “Y”, which could be retrived via the function “get.vertex.attribute” from the package igraph.

Examples

Run this code
data(ORN)
rtNEL<-readshpnw(ORN.nt, ELComputed=TRUE)
#Add the edge length as the weight for graph
igr<-nel2igraph(rtNEL[[2]],rtNEL[[3]],weight=rtNEL[[4]])
plot(igr, vertex.label=NA, vertex.size=2,vertex.size2=2)
#plot(ORN.nt)

Run the code above in your browser using DataLab