在R中调用igraph绘制网络图

  1. igraph简介

  2. igraph is a free software package for creating and manipulating undirected and directed graphs. It includes implementations for classic graph theory problems like minimum spanning trees and network flow, and also implements algorithms for some recent network analysis methods, like community structure search.

    igraph contains functions for generating regular and random graphs, manipulating graphs, assigning attributes to vertices and edges. It can calculate various structural properties, graph isomorphism, includes heuristics for community structure detection, supports many file formats. The R and Python interfaces support visualization.

    igraph runs on most modern machines and operating systems, and it is tested on MS Windows, Mac OSX and various Linux versions. The software you need for installing igraph depends on whether you want to use the C library, the R package or the Python extension; and may vary depending on your platform.

  3. 一个实例

  4. 实际问题:大鼠(rat)中转录因子与其靶基因之间的调控网络。
    原始数据Integrated Transcription Factor Platform
    中间数据:经整理后得到2个文件,如下所示:
    node.txt——节点(转录因子与基因)数据;
    relation.txt——连线(转录因子与其调控的靶基因)数据。
    最终网络
    rat_tf_tg
    PS1:这种一张图片中包含成百上千个节点与连线的网络图除了忽悠忽悠人,真的有什么实际用途吗?
    PS2:这张图还是蛮漂亮的:弯弯的月亮、头戴两朵小花……
    简单注释:绿色的节点是转录因子,蓝色的节点是基因;红色的连线表示转录因子调控(表达)转录因子(的基因),黑色的连线表示转录因子调控一般的基因。

  5. 相关网站

  6. 官网主页(The igraph library)
    Network Analysis with igraph(Creating Graphs)
    Experiments with igraph
    Plotting texts as graphs with R and igraph

  7. 数据及R脚本下载

  8. data_script

  1. 您好,我试了下出了好多错误,俺是个菜鸟,以前没有接触过R语言,敢问大侠,这三个文件应该放在哪个目录下,以及还需要安装什么才能将程序文件run,万分感谢!!

  2. 文件放在工作目录中。查看工作目录:getwd();设置工作目录:setwd()。
    需要在R中安装igraph包。install.packages(“igraph”)安装包;library(igraph)载入包。

  3. 错误于file(file, “rt”) : 无法打开链结
    此外: 警告信息:
    In file(file, “rt”) : 无法打开文件’node.txt’: No such file or directory

    我将所有的文件解压缩完后,放到R-curl的工作目录下面了,为啥还会出现这样的错误呢?

    • 我对Rcurl不熟悉。
      看报错信息,应该还是路径设置的问题。
      默认情况下,压缩包内的脚本和输入数据都要在同一个目录下才行。当然也可以自己修改脚本、设定自己喜欢的路径。

  4. 你好~请问g <- add.edges(g,t(edges),anno=as.character(rel[,3]))这句是什么意思?t()是什么意思?第三个变量不是应该是attr=list[]么?这个语句运行一直报错

  5. g <- add.edges(g,t(edges),anno=as.character(rel[,3])) 这句就是t(edges) 有问题?不知道怎么解决啊

  6. ids[from]有问题啊,from是个字符串。。导致g <- add.edges(g,t(edges),anno=as.character(rel[,3]))运行出错。。

  7. 报这个错咋办??> source(‘igraph.r’);Error in .Call(“R_igraph_add_edges”, graph, as.igraph.vs(graph, edges) – : At type_indexededgelist.c:272 : cannot add edges, Invalid vertex id

  8. cannot add edges, Invalid vertex id,新版igraph id必须从1开始,ids <- 1:length(names)-1 改为ids <- 1:length(names)即可