# 初次尝试igraph包

 This post was kindly contributed by 数据科学与R语言 - go there to comment and to read the full post.

igraph是为了进行社会网络分析而创建的一个包。与R语言中同类包相比，它的速度更快，而且函数命令与图形展现更为丰富。它可以处理有向网络和无向网络，但无法处理混合网络。igraph中的函数非常多，本文只是初步的介绍如何创建图形，并提供一些简单的例子。
`# 可以使用最基本的graph函数，用向量作为参数来创建图形，之后用plot绘制出结果library(igraph)g1 <- graph( c(0,1, 1,2, 2,3, 3,4))plot(g1,layout=layout.circle(g1))`
`# 也可以画出一些特殊结构的图形，例如下面的星形图g2 <- graph.star(10, mode = "in")plot(g2,layout=layout.fruchterman.reingold(g2))`
`# 当然也能从文件创建图形# 首先读入数据，整理后用graph.data.frame函数创建图形对象traits <- read.csv('http://igraph.sourceforge.net/igraphbook/traits.csv', head=FALSE)names(traits) <- c('name','age','gender')traits[,1] <- sapply(strsplit(as.character(traits[,1]),' '),'[',1)relation <- read.csv('http://igraph.sourceforge.net/igraphbook/relations.csv', head=FALSE)names(relation) <- c('from','to','sameroom','friendship','advice')g4 <- graph.data.frame(relation,vertices=traits)plot(g4,layout=layout.kamada.kawai,vertex.shape='rectangle',vertex.label=V(g4)\$name,vertex.size=20,asp=F)`
`# 可以通过summary函数观察内部结构，看到了10个顶点，34条边summary(g4)`

Vertices: 10
Edges: 34
Directed: TRUE
No graph attributes.
Vertex attributes: name, age, gender.

igraph参考资料：

http://www.stanford.edu/~messing/RforSNA.html

http://rdatamining.wordpress.com/2012/05/17/an-example-of-social-network-analysis-with-r-using-package-igraph/
http://librestats.com/2012/05/17/visualizing-the-cran-graphing-package-dependencies/
http://www.surefoss.org/visualisation/when-venn-diagrams-are-not-enough-visualizing-overlapping-data-with-social-network-analysis-in-r/
http://www.r-chart.com/2012/05/github-follower-graph-with-r.html
http://www.statistik.uni-dortmund.de/useR-2008/slides/Csardi.pdf

introduction to social network methods