{"id":3731,"date":"2017-10-06T16:34:07","date_gmt":"2017-10-06T15:34:07","guid":{"rendered":"http:\/\/www.blopig.com\/blog\/?p=3731"},"modified":"2017-10-06T16:34:07","modified_gmt":"2017-10-06T15:34:07","slug":"drawing-networks-in-latex-with-tikz-network","status":"publish","type":"post","link":"https:\/\/www.blopig.com\/blog\/2017\/10\/drawing-networks-in-latex-with-tikz-network\/","title":{"rendered":"Drawing Networks in LaTeX with tikz-network"},"content":{"rendered":"<p><a href=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2017\/10\/klimm_aims_image.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" loading=\"lazy\" class=\"alignleft size-medium wp-image-3741\" src=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2017\/10\/klimm_aims_image.png?resize=300%2C213&#038;ssl=1\" alt=\"\" width=\"300\" height=\"213\" srcset=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2017\/10\/klimm_aims_image.png?resize=300%2C213&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2017\/10\/klimm_aims_image.png?resize=768%2C546&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2017\/10\/klimm_aims_image.png?resize=624%2C444&amp;ssl=1 624w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2017\/10\/klimm_aims_image.png?w=989&amp;ssl=1 989w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>While researching on protein interaction networks it is often important to illustrate networks. For this many different tools are available, for example, Python&#8217;s NetworkX and Matlab, that\u00a0allow the export of figures as pixelated images or vector graphics. Usually, these figures are then incorporated in\u00a0the papers, which are commonly written in LaTeX. In this post, I want to present `tikz-network&#8217;, which is a novel tool to code and illustrate networks directly in LaTeX.<\/p>\n<p>To create an illustration you define the network&#8217;s nodes with their positions and edges between these nodes. An example of a simple network is<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">\\begin{tikzpicture}\r\n   \\Vertex[color = blue]{A}\r\n   \\Vertex[x=3,y=1,color=red]{B}\r\n   \\Vertex[x=0,y=2,color=orange]{C}\r\n   \\Edge[lw=5pt](A)(B)\r\n   \\Edge[lw=3pt,bend=15,Direct](A)(C)\r\n\\end{tikzpicture}<\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2017\/10\/blopig_simple.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" loading=\"lazy\" class=\"alignright size-medium wp-image-3745\" src=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2017\/10\/blopig_simple.png?resize=300%2C213&#038;ssl=1\" alt=\"\" width=\"300\" height=\"213\" srcset=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2017\/10\/blopig_simple.png?resize=300%2C213&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2017\/10\/blopig_simple.png?resize=624%2C444&amp;ssl=1 624w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2017\/10\/blopig_simple.png?w=682&amp;ssl=1 682w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>The illustrations can be much more complex and allow dashed lines, opacity, and many other features. Importantly, the properties do not need to be specified in the LaTeX file itself but can also be saved in an external file and imported with the\u00a0 <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\"> \\Vertices{data\/vertices.csv}<\/code>command. This allows the representation of more complex networks, for example the multilayer network below is created from the two files, the first representing the nodes<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">id, x, y ,size, color,opacity,label,layer \r\nA, 0, 0, .4 , green, .9 , a , 1\r\nB, 1, .7, .6 , , .5 , b , 1\r\nC, 2, 1, .8 ,orange, .3 , c , 1\r\nD, 2, 0, .5 , red, .7 , d , 2\r\nE,.2,1.5, .5 , gray, , e , 1\r\nF,.1, .5, .7 , blue, .3 , f , 2\r\nG, 2, 1, .4 , cyan, .7 , g , 2\r\nH, 1, 1, .4 ,yellow, .7 , h , 2<\/pre>\n<p>and the second having the edge information:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">u,v,label,lw,color ,opacity,bend,Direct\r\nA,B, ab  ,.5,red   ,   1   ,  30,false\r\nB,C, bc  ,.7,blue  ,   1   , -60,false\r\nA,E, ae  , 1,green ,   1   ,  45,true\r\nC,E, ce  , 2,orange,   1   ,   0,false\r\nA,A, aa  ,.3,black ,  .5   ,  75,false\r\nC,G, cg  , 1,blue  ,  .5   ,   0,false\r\nE,H, eh  , 1,gray  ,  .5   ,   0,false\r\nF,A, fa  ,.7,red   ,  .7   ,   0,true\r\nD,F, df  ,.7,cyan  ,   1   ,   30,true\r\nF,H, fh  ,.7,purple,   1   ,   60,false\r\nD,G, dg  ,.7,blue  ,  .7   ,   60,false<\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2017\/10\/blopig_multilayer.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-3749 alignright\" src=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2017\/10\/blopig_multilayer.png?resize=300%2C300&#038;ssl=1\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2017\/10\/blopig_multilayer.png?resize=300%2C300&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2017\/10\/blopig_multilayer.png?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2017\/10\/blopig_multilayer.png?w=624&amp;ssl=1 624w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>For details, please see the extensive manual on the <a href=\"https:\/\/github.com\/hackl\/tikz-network\">GitHub<\/a> page of the project. It is a very new project and I only started using it but I like it so far for a couple of reasons:<\/p>\n<ul>\n<li>it is easy to use, especially for small example graphs<\/li>\n<li>the multilayer functionality is very convenient<\/li>\n<li>included texts are automatically in the correct size and font with the rest of the LaTeX document<\/li>\n<li>it can be combined with regular\u00a0tikz\u00a0commands to create more complex illustrations<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>While researching on protein interaction networks it is often important to illustrate networks. For this many different tools are available, for example, Python&#8217;s NetworkX and Matlab, that\u00a0allow the export of figures as pixelated images or vector graphics. Usually, these figures are then incorporated in\u00a0the papers, which are commonly written in LaTeX. In this post, I [&hellip;]<\/p>\n","protected":false},"author":34,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","wikipediapreview_detectlinks":true,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"ngg_post_thumbnail":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[10,14],"tags":[],"ppma_author":[522],"class_list":["post-3731","post","type-post","status-publish","format-standard","hentry","category-groupmeetings","category-howto"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"authors":[{"term_id":522,"user_id":34,"is_guest":0,"slug":"florian-klimm","display_name":"Florian Klimm","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/c2e8e4c8d07250c3ec24ccfbc4670526fc7e55bbbb1ee1b52cae024f5c858171?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/3731","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/comments?post=3731"}],"version-history":[{"count":14,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/3731\/revisions"}],"predecessor-version":[{"id":3756,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/3731\/revisions\/3756"}],"wp:attachment":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/media?parent=3731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/categories?post=3731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/tags?post=3731"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=3731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}