Wednesday 27 December 2017

R igraph

Introduction to igraph

Delete weak correlations from network in igraph (vertices and edges)

~~~~
g=delete.edges(g, which(E(g)$weight <=.1))
g=delete.vertices(g,which(degree(g)<1))
~~~~

In R, how can I generate a subgraph from a igraph object based on multiple attribute scores?

~~~
new_graph <- induced.subgraph(old_graph, 
  V(old_graph)[ city %in% c("LOS ANGELES", "BOSTON", "KALAMAZOO") ])
~~~

The Book "Statistical Analysis of Network Data with R"

Initializing an igraph object

g <- graph.formula(1-2, 1-3, 2-3, 2-4, 3-5, 4-5, 4-6, 4-7, 5-6, 6-7) 
str(g)

Vertex labels can be changed from the default after initially creating the graph, by modifying the name vertex attribute of the graph object.

V(dg)$name <- c("Sam", "Mary", "Tom")

~~~
Useful igraph code Statistical Analysis of Network Data with R


No comments:

Post a Comment