<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>生信菜鸟团 &#187; 网络图</title>
	<atom:link href="http://www.bio-info-trainee.com/tag/%e7%bd%91%e7%bb%9c%e5%9b%be/feed" rel="self" type="application/rss+xml" />
	<link>http://www.bio-info-trainee.com</link>
	<description>欢迎去论坛biotrainee.com留言参与讨论，或者关注同名微信公众号biotrainee</description>
	<lastBuildDate>Sat, 28 Jun 2025 14:30:13 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.33</generator>
	<item>
		<title>R语言画网络图三部曲之igraph</title>
		<link>http://www.bio-info-trainee.com/2082.html</link>
		<comments>http://www.bio-info-trainee.com/2082.html#comments</comments>
		<pubDate>Mon, 28 Nov 2016 10:08:59 +0000</pubDate>
		<dc:creator><![CDATA[ulwvfje]]></dc:creator>
				<category><![CDATA[R]]></category>
		<category><![CDATA[网络分析]]></category>
		<category><![CDATA[网络图]]></category>

		<guid isPermaLink="false">http://www.bio-info-trainee.com/?p=2082</guid>
		<description><![CDATA[经过热心的小伙伴的提醒，我才知道我以前写的R语言画网络图三部曲竟然漏掉了最基础的 &#8230; <a href="http://www.bio-info-trainee.com/2082.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>经过热心的小伙伴的提醒，我才知道我以前写的R语言画网络图三部曲竟然漏掉了最基础的一个包，就是igraph，不了解这个，后面的两个也是无源之水。</p>
<h2><a title="详细阅读 R语言画网络图三部曲之networkD3" href="http://www.bio-info-trainee.com/1357.html" rel="bookmark">R语言画网络图三部曲之networkD3</a></h2>
<h2><a title="详细阅读 R语言画网络图三部曲之sna" href="http://www.bio-info-trainee.com/1355.html" rel="bookmark">R语言画网络图三部曲之sna</a></h2>
<div>包说明书：<a href="https://cran.r-project.org/web/packages/igraph/igraph.pdf">https://cran.r-project.org/web/packages/igraph/igraph.pdf</a></div>
<div>包例子：<a href="https://www.r-project.org/conferences/useR-2008/slides/Csardi.pdf">https://www.r-project.org/conferences/useR-2008/slides/Csardi.pdf</a></div>
<div>包函数：<a href="http://igraph.org/r/doc/">http://igraph.org/r/doc/</a></div>
<div>PPI实例：<a href="http://a-little-book-of-r-for-bioinformatics.readthedocs.io/en/latest/src/chapter11.html">http://a-little-book-of-r-for-bioinformatics.readthedocs.io/en/latest/src/chapter11.html</a></div>
<div>其实包括了3个包：igraph/RBGL/Rgraphviz</div>
<div>用到了一个测试数据，是构建好的PPI网络对象：We will first analyse a curated data set of protein-protein interactions in the yeast Saccharomyces cerevisiae extracted from published papers. This data set comes from with an R package called “yeastExpData”, which calls the data set “litG”. This data was first described in a paper by Ge et al (2001) in Nature Genetics (<a href="http://www.nature.com/ng/journal/v29/n4/full/ng776.html">http://www.nature.com/ng/journal/v29/n4/full/ng776.html</a>).</div>
<div></div>
<p><span id="more-2082"></span></p>
<div><span style="color: #ff0000;">重点是graphNEL graph对象如何构造以及如何用函数来处理它！</span></div>
<div><span style="color: #ff0000;">构造方式，请记住，构造网络对象是重点，就是graph.data.frame+as_graphnel即可，一系列以网络对象为基础的包都需要这个步骤，学会了，也就没有问题了！</span></div>
<div>读取PPI数据到data.frame里面，比如my_edges</div>
<div><img src="file:///C:/Users/jimmy1314/AppData/Local/YNote/data/jmzeng1314@163.com/218613774f924593bf4f8c0c9409d9ec/clipboard.png" alt="" data-media-type="image" data-attr-org-src-id="A5A10EECE0EE4050BB621ECF2A264D50" /><a href="http://www.bio-info-trainee.com/wp-content/uploads/2016/11/clipboard1.png"><img class="alignnone size-full wp-image-2083" src="http://www.bio-info-trainee.com/wp-content/uploads/2016/11/clipboard1.png" alt="clipboard" width="359" height="124" /></a></div>
<div>tmp &lt;- graph.data.frame(my_edges)</div>
<div>tmp;summary(tmp)</div>
<div>plot(tmp, layout=layout.kamada.kawai)</div>
<div>subnet &lt;- as_graphnel(tmp)</div>
<div>这个时候得到的subnet就是一个网络对象啦！</div>
<div>&gt; subnet</div>
<div>A graphNEL graph with directed edges</div>
<div>Number of Nodes = 818</div>
<div>Number of Edges = 12249</div>
<div>有了这个网络对象，就可以用BioNet来处理找<a href="http://www.bio-info-trainee.com/2071.html">maximal-scoring subgraph</a></div>
<div></div>
<div>对于网络对象，其它处理的函数有</div>
<div>mynodes &lt;- nodes(litG) 得到网络里面的所有节点信息</div>
<div>adj(litG, "YBR009C") 得到网络里面的YBR009C这个node节点的所有edges</div>
<div>mydegrees &lt;- graph::degree(litG) 算出网络里面的每个node的degree</div>
<div>table(mydegrees);mean(mydegrees);hist(mydegrees, col="red") 看看degree的分布情况。</div>
<div>对比较大的网络来说，并非里面的node都是连通的，可以用RBGL包来看看哪些nodes被隔离开了。</div>
<div>library("RBGL") myconnectedcomponents &lt;- connectedComp(litG)</div>
<div>返回的myconnectedcomponents这个list的每个元素都是一个被隔离开的网络图，可以去找最大连通图，也可以对这个list找到特定的某个node参与的连通图。</div>
<div>component3 &lt;- myconnectedcomponents[[3]]</div>
<div>mysubgraph &lt;- subGraph(component3, litG) 取指定的连通图，生成graphNEL对象，其实就是根据nodes来取子网络图。</div>
<div>下面代码可以把网络图展现出来：</div>
<div>library("Rgraphviz") mysubgraph &lt;- subGraph(component3, litG) mygraphplot &lt;- layoutGraph(mysubgraph, layoutType="neato") renderGraph(mygraphplot)</div>
<div></div>
<div>对网络图还可以找communities，这个又是一个网络图研究术语了： <a href="http://en.wikipedia.org/wiki/Community_structure">http://en.wikipedia.org/wiki/Community_structure</a></div>
<div>还可以进行聚类，就是cluster，还有很多，我就不一一介绍了。</div>
<div>上面的连通图也是一个网络研究术语：<a href="http://en.wikipedia.org/wiki/Connected_component_(graph_theory)">http://en.wikipedia.org/wiki/Connected_component_(graph_theory)</a></div>
<div></div>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.bio-info-trainee.com/2082.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>cytoscape五步曲之二：在cytoscape里面生成网络图</title>
		<link>http://www.bio-info-trainee.com/2055.html</link>
		<comments>http://www.bio-info-trainee.com/2055.html#comments</comments>
		<pubDate>Thu, 24 Nov 2016 03:21:49 +0000</pubDate>
		<dc:creator><![CDATA[ulwvfje]]></dc:creator>
				<category><![CDATA[基础软件]]></category>
		<category><![CDATA[cytoscape]]></category>
		<category><![CDATA[网络图]]></category>

		<guid isPermaLink="false">http://www.bio-info-trainee.com/?p=2055</guid>
		<description><![CDATA[通过上一讲大家应该明白了，网络图是为了展现分子之间的连接关系的，并不是一定要用c &#8230; <a href="http://www.bio-info-trainee.com/2055.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div>通过上一讲大家应该明白了，网络图是为了展现分子之间的连接关系的，并不是一定要用cytoscape来做，只需要根据连接关系给我们的所有点安排一个坐标，然后把相应的线连接起来即可！那么既然我们要学习cytoscape，肯定是要用cytoscape做好第一步，就是根据输入数据来做网络图。</div>
<div>可以先了解一下cytoscape定义好的输入数据，</div>
<div><a href="http://wiki.cytoscape.org/Cytoscape_User_Manual/Network_Formats">http://wiki.cytoscape.org/Cytoscape_User_Manual/Network_Formats</a> 当然，其实木有意义！因为我们不可能拿到cytoscape的输入文件（cys格式的），除非是你朋友传给你的。我们肯定是根据txt.csv等分割的文本文件来做网络图。</div>
<p><span id="more-2055"></span></p>
<div>cytoscape里面有很多示例数据，请务必打开看看：C:\Program Files\Cytoscape_v3.3.0\sampleData 了解它要求什么数据！！！</div>
<div>你可以打开cytoscape，然后直接点击菜单栏的file--&gt;open--&gt;然后选择示例数据的cys文件，就可以看到一个图啦！但是木有任何意义，还是那句老话，你不可能预先得到cys文件，必然是你自己有txt文本数据，然后做出cys的文件。</div>
<div>文本数据必须要有2列，就是source node和target node，其余的都是可选！！！</div>
<div>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>source</td>
<td>target</td>
</tr>
<tr>
<td>YKR026C</td>
<td>YGL122C</td>
</tr>
<tr>
<td>YGR218W</td>
<td>YGL097W</td>
</tr>
<tr>
<td>YGL097W</td>
<td>YOR204W</td>
</tr>
<tr>
<td>YLR249W</td>
<td>YPR080W</td>
</tr>
<tr>
<td>YLR249W</td>
<td>YBR118W</td>
</tr>
<tr>
<td>YLR293C</td>
<td>YGL097W</td>
</tr>
<tr>
<td>YMR146C</td>
<td>YDR429C</td>
</tr>
<tr>
<td>YDR429C</td>
<td>YFL017C</td>
</tr>
<tr>
<td>YPR080W</td>
<td>YAL003W</td>
</tr>
<tr>
<td>YBR118W</td>
<td>YAL003W</td>
</tr>
<tr>
<td>YOL123W</td>
<td>YGL044C</td>
</tr>
<tr>
<td>YPL211W</td>
<td>YGR014W</td>
</tr>
<tr>
<td>YJL030W</td>
<td>YGL229C</td>
</tr>
<tr>
<td>YJL013C</td>
<td>YGL229C</td>
</tr>
<tr>
<td>YGL122C</td>
<td>YOL123W</td>
</tr>
<tr>
<td>YGR014W</td>
<td>YJL030W</td>
</tr>
<tr>
<td>YGR014W</td>
<td>YJL013C</td>
</tr>
<tr>
<td>YGR203W</td>
<td>YIL061C</td>
</tr>
<tr>
<td>YCR084C</td>
<td>YBR112C</td>
</tr>
<tr>
<td>YCR084C</td>
<td>YCL067C</td>
</tr>
</tbody>
</table>
</div>
<div></div>
<div>导入文本的方式如下：</div>
<div><a href="http://www.bio-info-trainee.com/wp-content/uploads/2016/11/15.png"><img class="alignnone size-full wp-image-2056" src="http://www.bio-info-trainee.com/wp-content/uploads/2016/11/15.png" alt="1" width="848" height="536" /></a></div>
<div><img src="file:///C:/Users/jimmy1314/AppData/Local/YNote/data/jmzeng1314@163.com/5dc2039034d641538c531dcb9a2cf8c3/clipboard.png" alt="" data-media-type="image" data-attr-org-src-id="FD876A7F42DC48919D465A2A2866B2B1" /></div>
<div>其实已经有了这两列信息，在R里面就可以自己画网络图了，或者在html网页里面写js来做。实在是没必要用cytoscape，这也就是为什么像我这样的大神，到现在才开始使用cytoscape的原因。即使用cytoscape生成了网络图，还需要进行一大堆的细节调整，很烦人的。</div>
<div></div>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bio-info-trainee.com/2055.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>cytoscape五步曲之一：明白什么是网络图</title>
		<link>http://www.bio-info-trainee.com/2053.html</link>
		<comments>http://www.bio-info-trainee.com/2053.html#comments</comments>
		<pubDate>Thu, 24 Nov 2016 03:12:25 +0000</pubDate>
		<dc:creator><![CDATA[ulwvfje]]></dc:creator>
				<category><![CDATA[基础软件]]></category>
		<category><![CDATA[cytoscape]]></category>
		<category><![CDATA[网络图]]></category>

		<guid isPermaLink="false">http://www.bio-info-trainee.com/?p=2053</guid>
		<description><![CDATA[想了想还是写一个系列教程吧，问的朋友也太多了，主要是因为cytoscape跟py &#8230; <a href="http://www.bio-info-trainee.com/2053.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div>想了想还是写一个系列教程吧，问的朋友也太多了，主要是因为cytoscape跟python一样，经历了从2到3的进化阵痛过程，而且进化的面目全非了！！！很多人拿着2.x的说明书教程，视频，然后下载的却是3.x版本的cytoscape，真可怕！！！</div>
<div>已经从两万个芯片探测到的基因里面找到了近千个差异基因了，对它们做了GO/KEGG分析还是抓不住重点，看到文献说可以用PPI数据库做network analysis之后找hub基因，也也许可以说明一些问题！</div>
<div>提到 network analysis ，我想起来我以前总结过 R语言画网络图的三部曲，里面讲到过网络分析的基本原理！</div>
<p><span id="more-2053"></span></p>
<div></div>
<div>网络图是为了展示数据与数据之间的联系，在生物信息学领域，一般是基因直接的相互作用关系，或者通路之间的联系！</div>
<div><span style="color: #ff0000;">通俗点说，就是我有一些点，它们之间并不是两两相互联系，而是有部分是有连接的，那么我应该如何把这些点画在图片上面呢？因为这些都并没有X,Y坐标，只有连接关系，所以我们要根据一个理论来给它们分配坐标，这样就可以把它们画出来了，然后也可以对这些点进行连线，连完线后，就是网络图啦！！！</span></div>
<div>而给它们分配坐标的理论有点复杂，大概类似于物理里面的万有引力和洛仑磁力相结合来给它们分配一个位置，使得总体的能量最小，就是最稳定状态！而通常这个状态是逼近，而不是精确，所以我们其实对同样的数据可以画出无数个网络图，只需使得网络图合理即可！</div>
<div><a href="http://www.bio-info-trainee.com/1355.html">R语言画网络图三部曲之sna</a></div>
<div></div>
<div><a href="http://www.bio-info-trainee.com/1357.html">R语言画网络图三部曲之networkD3</a></div>
<div></div>
<div><img src="file:///C:/Users/jimmy1314/AppData/Local/YNote/data/jmzeng1314@163.com/092902c2814a4945b5e0a9e5e9718c23/13.png" alt="" data-media-type="image" data-attr-org-src-id="345299B1A62B43C4BCAF8E5998BAAA13" /></div>
<div><a href="http://www.bio-info-trainee.com/wp-content/uploads/2016/01/13.png"><img class="alignnone size-full wp-image-1361" src="http://www.bio-info-trainee.com/wp-content/uploads/2016/01/13.png" alt="1" width="704" height="596" /></a></div>
<div>看这个图，就明白了，网络图，<span style="color: #ff0000;"><strong>就是在画布上给感兴趣的点一个坐标</strong></span>，通过统计方法，有两个：Two of the most prominente algorithms (<a href="http://en.wikipedia.org/wiki/Force-based_algorithms_%28graph_drawing%29">Fruchterman &amp; Reingold’s</a> force-directed placement algorithm and <a href="http://cs.wellesley.edu/~cs315/Papers/Kamada-Graph%20Drawing.pdf">Kamada-Kawai’s</a>)</div>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.bio-info-trainee.com/2053.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>R语言画网络图三部曲之sna</title>
		<link>http://www.bio-info-trainee.com/1355.html</link>
		<comments>http://www.bio-info-trainee.com/1355.html#comments</comments>
		<pubDate>Thu, 14 Jan 2016 12:59:07 +0000</pubDate>
		<dc:creator><![CDATA[ulwvfje]]></dc:creator>
				<category><![CDATA[R]]></category>
		<category><![CDATA[sna]]></category>
		<category><![CDATA[网络图]]></category>

		<guid isPermaLink="false">http://www.bio-info-trainee.com/?p=1355</guid>
		<description><![CDATA[如果只是画网络图，那么只需要把所有的点，按照算好的坐标画出来，然后把所有的连线也 &#8230; <a href="http://www.bio-info-trainee.com/1355.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>如果只是画网络图，那么只需要把所有的点，按照算好的坐标画出来，然后把所有的连线也画出即可！</p>
<div><span style="font-family: Times New Roman;">其中算法就是，点的坐标该如何确定？Two of the most prominente algorithms (<a href="http://en.wikipedia.org/wiki/Force-based_algorithms_%28graph_drawing%29">Fruchterman &amp; Reingold’s</a> force-directed placement algorithm and <a href="http://cs.wellesley.edu/~cs315/Papers/Kamada-Graph%20Drawing.pdf">Kamada-Kawai’s</a>)</span></div>
<div><span style="font-family: Times New Roman;">有一个networkD3的包可以直接画图，但是跳过了确定点的坐标这个步骤，我重新找了一包，可以做到！</span></div>
<div><span style="font-family: Times New Roman;">来自于一个博客：<b><a href="https://sumtxt.wordpress.com/2011/07/02/visualizing-networks-with-ggplot2-in-r/" target="_blank">https://sumtxt.wordpress.com/2011/07/02/visualizing-networks-with-ggplot2-in-r/</a></b></span></div>
<div>
<div><span style="color: #000000; font-family: Helvetica Neue,Helvetica,Arial,sans-serif;">作者只是用sna包来得到数据，其实用的是ggplot来画网络图！</span></div>
<div><span style="color: #000000; font-family: Helvetica Neue,Helvetica,Arial,sans-serif;">需要熟悉network包里面的network对象的具体东西，如何自己构造一个，然后数学sna包如何计算layout即可</span></div>
<div><span style="color: #ff00ff; font-family: Helvetica Neue,Helvetica,Arial,sans-serif;"><a href="https://cran.r-project.org/web/packages/network/network.pdf">https://cran.r-project.org/web/packages/network/network.pdf</a><br />
</span></div>
<div><span style="font-family: Helvetica Neue,Helvetica,Arial,sans-serif;"><span style="color: #ff00ff;"><a href="https://cran.r-project.org/web/packages/sna/sna.pdf">https://cran.r-project.org/web/packages/sna/sna.pdf</a></span></span></div>
<div><span style="font-family: Helvetica Neue,Helvetica,Arial,sans-serif;">解读这个包，也可以自己画网络图，代码如下：</span></div>
<div><span style="font-family: Helvetica Neue,Helvetica,Arial,sans-serif;">plot(plotcord)</span></div>
<div><span style="font-family: Helvetica Neue,Helvetica,Arial,sans-serif;">text(x=plotcord$X1+0.2,y=plotcord$X2,labels = LETTERS[1:10])</span></div>
<div><span style="font-family: Helvetica Neue,Helvetica,Arial,sans-serif;">for (i in 1:10){</span></div>
<div><span style="font-family: Helvetica Neue,Helvetica,Arial,sans-serif;">  for (j in 1:10){</span></div>
<div><span style="font-family: Helvetica Neue,Helvetica,Arial,sans-serif;">    if(tmp[i,j]) lines(plotcord[c language="(i,j),1"][/c],plotcord[c language="(i,j),2"][/c])</span></div>
<div><span style="font-family: Helvetica Neue,Helvetica,Arial,sans-serif;">  }</span></div>
<div><span style="font-family: Helvetica Neue,Helvetica,Arial,sans-serif;">}</span></div>
<div><span style="font-family: Helvetica Neue,Helvetica,Arial,sans-serif;">当然，我们还没有涉及到算法，就是如何生成plotcord这个坐标矩阵的！</span></div>
<div><span style="font-family: Helvetica Neue,Helvetica,Arial,sans-serif;">大家看下面这个示意图就知道网络图是怎么样画出来的了，首先我们有一些点，它们之间有联系，都存储在networData这个数据里面，是10个点，共9个连接，然后我用reshape包把它转换成连接矩阵，理论上10个点的两两相互作用应该有100条线，但是我们的数据清楚的说明只有9条，所以只有9个1，其余的0代表点之间没有关系。接下来我们用sna这个包对这个连接矩阵生成了这10个点的坐标（<b>这个是重点），最后很简单了，把点和线画出来即可！</b></span></div>
<p><a href="http://www.bio-info-trainee.com/wp-content/uploads/2016/01/13.png"><img class="alignnone size-full wp-image-1361" src="http://www.bio-info-trainee.com/wp-content/uploads/2016/01/13.png" alt="1" width="704" height="596" /></a></div>
<div>另外一个例子：</div>
<div>
<div><b>net=network(150, directed=FALSE, density=0.03)</b></div>
<div><b>m &lt;- as.matrix.network.adjacency(net) # get sociomatrix  </b></div>
<div><b># get coordinates from Fruchterman and Reingold's force-directed placement algorithm.</b></div>
<div><b>plotcord &lt;- data.frame(gplot.layout.fruchtermanreingold(m, NULL)) </b></div>
<div><b># or get it them from Kamada-Kawai's algorithm: </b></div>
<div><b># plotcord &lt;- data.frame(gplot.layout.kamadakawai(m, NULL)) </b></div>
<div><b>colnames(plotcord) = c("X1","X2")  ###所有点的坐标，共150个点</b></div>
<div><b>edglist &lt;- as.matrix.network.edgelist(net) ##所有点之间的关系-edge ##共335条线</b></div>
<div><b>edges &lt;- data.frame(plotcord[edglist[,1],], plotcord[edglist[,2],]) ##两点之间的连线的具体坐标，335条线的起始终止点点坐标</b></div>
</div>
<div><span style="font-family: Times New Roman;">原始代码如下：</span></div>
<div><span style="font-family: Times New Roman;">library(network)</span></div>
<div><span style="font-family: Times New Roman;">library(ggplot2)</span></div>
<div><span style="font-family: Times New Roman;">library(sna)</span></div>
<div><span style="font-family: Times New Roman;">library(ergm)</span></div>
<div><a href="http://www.bio-info-trainee.com/wp-content/uploads/2016/01/clipboard11.png"><img class="alignnone size-full wp-image-1362" src="http://www.bio-info-trainee.com/wp-content/uploads/2016/01/clipboard11.png" alt="clipboard" width="823" height="596" /></a></div>
<div><span style="font-family: Times New Roman;">大家可以试用这个代码，因为它用的ggplot，肯定比我那个简单R作图要好看多了<br />
</span></div>
<div><span style="font-family: Times New Roman;">参考算法文献：</span></div>
<div><span style="font-family: Times New Roman;"><a href="http://www.jstatsoft.org/article/view/v024i02/v24i02.pdf" target="_blank">http://www.jstatsoft.org/article/view/v024i02/v24i02.pdf</a><br />
</span></div>
<div><span style="font-family: Times New Roman;"><a href="http://www.jstatsoft.org/article/view/v024i06/v24i06.pdf" target="_blank">http://www.jstatsoft.org/article/view/v024i06/v24i06.pdf</a><br />
</span></div>
<div><span style="font-family: Times New Roman;"><span style="color: #000000; font-family: Helvetica Neue,Helvetica,Arial,sans-serif;"><a href="http://web.stanford.edu/~messing/RforSNA.html" target="_blank">http://web.stanford.edu/~messing/RforSNA.html</a></span><br />
</span></div>
<div><span style="font-family: Times New Roman;"> </span></div>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bio-info-trainee.com/1355.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>R语言画网络图三部曲之networkD3</title>
		<link>http://www.bio-info-trainee.com/1357.html</link>
		<comments>http://www.bio-info-trainee.com/1357.html#comments</comments>
		<pubDate>Thu, 14 Jan 2016 12:51:19 +0000</pubDate>
		<dc:creator><![CDATA[ulwvfje]]></dc:creator>
				<category><![CDATA[R]]></category>
		<category><![CDATA[networkD3]]></category>
		<category><![CDATA[网络图]]></category>

		<guid isPermaLink="false">http://www.bio-info-trainee.com/?p=1357</guid>
		<description><![CDATA[首先，我们需要了解一下基础知识： 网络图是为了展示数据与数据之间的联系，在生物信 &#8230; <a href="http://www.bio-info-trainee.com/1357.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div>首先，我们需要了解一下基础知识：</div>
<div>网络图是为了展示数据与数据之间的联系，在生物信息学领域，一般是基因直接的相互作用关系，或者通路之间的联系！</div>
<div>通俗点说，就是我有一些点，它们之间并不是两两相互联系，而是有部分是有连接的，那么我应该如何把这些点画在图片上面呢？因为这些都并没有X,Y坐标，只有连接关系，所以我们要根据一个理论来给它们分配坐标，这样就可以把它们画出来了，然后也可以对这些点进行连线，连完线后，就是网络图啦！！！</div>
<div>而给它们分配坐标的理论有点复杂，大概类似于物理里面的万有引力和洛仑磁力相结合来给它们分配一个位置，使得总体的能量最小，就是最稳定状态！而通常这个状态是逼近，而不是精确，所以我们其实对同样的数据可以画出无数个网络图，只需使得网络图合理即可！</div>
<div></div>
<div>看这个ppt：<a href="http://statmath.wu.ac.at/research/friday/resources_WS0708_SS08/igraph.pdf">http://statmath.wu.ac.at/research/friday/resources_WS0708_SS08/igraph.pdf</a></p>
<div>再看这个博客：<a href="http://kateto.net/network-visualization">http://kateto.net/network-visualization</a></div>
<div>基本上就都理解了</div>
<div>画网络图真的好复杂呀！！！</div>
<div>大部分人都是用D3JS来画图：<a href="http://bl.ocks.org/mbostock/2706022">http://bl.ocks.org/mbostock/2706022</a></div>
<div>理论paper特别复杂：<a href="http://yifanhu.net/PUB/graph_draw_small.pdf">http://yifanhu.net/PUB/graph_draw_small.pdf</a></div>
<div>算法的paper：<a href="http://cs.brown.edu/~rt/gdhandbook/chapters/force-directed.pdf">http://cs.brown.edu/~rt/gdhandbook/chapters/force-directed.pdf</a></div>
<div>一步步讲受力分析图是如何画的：<a href="https://github.com/mbostock/d3/wiki/Force-Layout">https://github.com/mbostock/d3/wiki/Force-Layout</a></div>
<div><b><a href="http://www.coppelia.io/2014/07/an-a-to-z-of-extra-features-for-the-d3-force-layout/">http://www.coppelia.io/2014/07/an-a-to-z-of-extra-features-for-the-d3-force-layout/</a></b></div>
<p>接下来， 我们直接看看R里面是如何画网络图的，我们首推一个包：<a href="http://christophergandrud.github.io/networkD3/">networkD3/</a></div>
<div>它的github主页是：<a href="http://christophergandrud.github.io/networkD3/">http://christophergandrud.github.io/networkD3/</a></div>
<div>这个包非常好用，只需要做好data，然后用它提供的几个函数即可！</div>
<div>
<div>重要的是熟悉输入数据是什么，还可以结合shinny包来展示数据，非常好用！！！</div>
<div>具体还可以看包的说明书：<a href="https://cran.r-project.org/web/packages/networkD3/networkD3.pdf">https://cran.r-project.org/web/packages/networkD3/networkD3.pdf</a></div>
<div>具体怎么安装这个R包，我就不讲了，它的github主页上面其实也有说明书，很容易看懂的</div>
<div>最简单的用法，就是构造一个联结矩阵，把所有的连接关系都存储起来，然后直接用一个函数就可以画图啦！</div>
<div><span style="font-family: Times New Roman;"># Plot</span></div>
<div><span style="font-family: Times New Roman;">library(networkD3)</span></div>
<div><span style="font-family: Times New Roman;">simpleNetwork(networkData,fontSize=25)</span></div>
<div><span style="font-family: Times New Roman;">可以看出网络图，就是把所有的点，按照算好的坐标画出来，然后把所有的连线也画出即可！</span></div>
<div><span style="font-family: Times New Roman;">其中算法就是，点的坐标该如何确定？Two of the most prominente algorithms (<a href="http://en.wikipedia.org/wiki/Force-based_algorithms_%28graph_drawing%29">Fruchterman &amp; Reingold’s</a> force-directed placement algorithm and <a href="http://cs.wellesley.edu/~cs315/Papers/Kamada-Graph%20Drawing.pdf">Kamada-Kawai’s</a>)</span></div>
<p><a href="http://www.bio-info-trainee.com/wp-content/uploads/2016/01/clipboard9.png"><img class="alignnone size-full wp-image-1358" src="http://www.bio-info-trainee.com/wp-content/uploads/2016/01/clipboard9.png" alt="clipboard" width="598" height="296" /></a></div>
<div>但是这个软件有一个弊端就是，生成图片之后，并没有给出这些点的坐标，当然，这种坐标基本上也很少有人需要，可视化就够了！</div>
<div>如果这些点还分组了，而且连接还有权重，那么网络图就复杂一点，比如下面这个：</div>
<div>就不仅仅是需要提供所有的link的信息，link还多了一列，是value，而且还需提供所有的node信息，node多了一列是分组。</div>
<div><a href="http://www.bio-info-trainee.com/wp-content/uploads/2016/01/clipboard10.png"><img class="alignnone size-full wp-image-1359" src="http://www.bio-info-trainee.com/wp-content/uploads/2016/01/clipboard10.png" alt="clipboard" width="484" height="392" /></a></div>
<div>当然，还有好几个图，大家可以自己慢慢用，自己体会！</div>
<div>sankeyNetwork</div>
<div>sankeyNetwork</div>
<div>radialNetwork</div>
<div>diagonalNetwork</div>
<div>dendroNetwork</div>
<div>也可以把生成的网络图直接保存成网页，动态显示！</div>
<div></div>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.bio-info-trainee.com/1357.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
