<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://teaching.healthtech.dtu.dk/22140/index.php?action=history&amp;feed=atom&amp;title=Ex_handouts_igraph_solution</id>
	<title>Ex handouts igraph solution - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://teaching.healthtech.dtu.dk/22140/index.php?action=history&amp;feed=atom&amp;title=Ex_handouts_igraph_solution"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/22140/index.php?title=Ex_handouts_igraph_solution&amp;action=history"/>
	<updated>2026-07-02T10:39:30Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/22140/index.php?title=Ex_handouts_igraph_solution&amp;diff=42&amp;oldid=prev</id>
		<title>WikiSysop: Created page with &quot;= Part 1 - network from AP/MS data =  Interaction data from exercise 5 and edge scores from exercise 6  &lt;pre style=&quot;overflow:auto;&quot;&gt; library(igraph) library(ggraph) ex5_interactions &lt;- data.frame(from = c(&quot;A&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;D&quot;, &quot;D&quot;, &quot;E&quot;, &quot;F&quot;, &quot;F&quot;),    to = c(&quot;B&quot;, &quot;C&quot;, &quot;D&quot;, &quot;E&quot;, &quot;F&quot;, &quot;H&quot;, &quot;F&quot;, &quot;G&quot;, &quot;H&quot;, &quot;G&quot;, &quot;H&quot;),    score = c(-0.155, -0.234, -0.222, -0.183, -0.183, -0.183, -0.301, -0.194, -0.301, -0.301, -0.301)) g &lt;- graph_from_data_frame(ex5_interactions, d...&quot;</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/22140/index.php?title=Ex_handouts_igraph_solution&amp;diff=42&amp;oldid=prev"/>
		<updated>2024-03-05T14:06:59Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;= Part 1 - network from AP/MS data =  Interaction data from exercise 5 and edge scores from exercise 6  &amp;lt;pre style=&amp;quot;overflow:auto;&amp;quot;&amp;gt; library(igraph) library(ggraph) ex5_interactions &amp;lt;- data.frame(from = c(&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;D&amp;quot;, &amp;quot;D&amp;quot;, &amp;quot;E&amp;quot;, &amp;quot;F&amp;quot;, &amp;quot;F&amp;quot;),    to = c(&amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;D&amp;quot;, &amp;quot;E&amp;quot;, &amp;quot;F&amp;quot;, &amp;quot;H&amp;quot;, &amp;quot;F&amp;quot;, &amp;quot;G&amp;quot;, &amp;quot;H&amp;quot;, &amp;quot;G&amp;quot;, &amp;quot;H&amp;quot;),    score = c(-0.155, -0.234, -0.222, -0.183, -0.183, -0.183, -0.301, -0.194, -0.301, -0.301, -0.301)) g &amp;lt;- graph_from_data_frame(ex5_interactions, d...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Part 1 - network from AP/MS data =&lt;br /&gt;
&lt;br /&gt;
Interaction data from exercise 5 and edge scores from exercise 6&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto;&amp;quot;&amp;gt;&lt;br /&gt;
library(igraph)&lt;br /&gt;
library(ggraph)&lt;br /&gt;
ex5_interactions &amp;lt;- data.frame(from = c(&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;D&amp;quot;, &amp;quot;D&amp;quot;, &amp;quot;E&amp;quot;, &amp;quot;F&amp;quot;, &amp;quot;F&amp;quot;), &lt;br /&gt;
  to = c(&amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;D&amp;quot;, &amp;quot;E&amp;quot;, &amp;quot;F&amp;quot;, &amp;quot;H&amp;quot;, &amp;quot;F&amp;quot;, &amp;quot;G&amp;quot;, &amp;quot;H&amp;quot;, &amp;quot;G&amp;quot;, &amp;quot;H&amp;quot;), &lt;br /&gt;
  score = c(-0.155, -0.234, -0.222, -0.183, -0.183, -0.183, -0.301, -0.194, -0.301, -0.301, -0.301))&lt;br /&gt;
g &amp;lt;- graph_from_data_frame(ex5_interactions, directed = FALSE)&lt;br /&gt;
ggraph(g) + &lt;br /&gt;
  geom_edge_link() + &lt;br /&gt;
  geom_node_point() +&lt;br /&gt;
  geom_node_text(aes(label = names(V(g))), repel = TRUE)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE that since we have not supplied a node attribute table with the &amp;quot;vertices&amp;quot; variable in the &amp;quot;graph_from_data_frame&amp;quot; function, igraph extraxts the names of the nodes from the interactions table. You therefore need to use names(V(g)) to extract names.&lt;br /&gt;
&lt;br /&gt;
NOTE also that if you set &amp;quot;repel = TRUE&amp;quot; in &amp;quot;geom_node_text&amp;quot; when plotting, labels won&amp;#039;t overlap with nodes or each other.&lt;br /&gt;
&lt;br /&gt;
= Part 2 - network from Y2H data =&lt;br /&gt;
&lt;br /&gt;
Interaction data from exercise 7&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto;&amp;quot;&amp;gt;&lt;br /&gt;
ex7_interactions &amp;lt;- data.frame(from = c(&amp;quot;A&amp;quot;, &amp;quot;A&amp;quot;, &amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;E&amp;quot;, &amp;quot;F&amp;quot;, &amp;quot;F&amp;quot;, &amp;quot;G&amp;quot;), to = c(&amp;quot;B&amp;quot;, &amp;quot;D&amp;quot;, &amp;quot;G&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;D&amp;quot;, &amp;quot;G&amp;quot;, &amp;quot;F&amp;quot;, &amp;quot;H&amp;quot;, &amp;quot;G&amp;quot;, &amp;quot;H&amp;quot;, &amp;quot;H&amp;quot;), score = c(-0.301, -0.301, -0.778, -0.903, -0.477, -0.954, -0.778, -0.477, -0.778, -0.602, -0.778))&lt;br /&gt;
g &amp;lt;- graph_from_data_frame(ex7_interactions, directed = FALSE)&lt;br /&gt;
ggraph(g, layout = &amp;quot;linear&amp;quot;, circular = TRUE) + &lt;br /&gt;
  geom_edge_link() + &lt;br /&gt;
  geom_node_point() +&lt;br /&gt;
  geom_node_text(aes(label = names(V(g))), repel = TRUE)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE that I chose a circular layout here, since this layout is independent of which edges the network contains. This enables me to quickly compare with the following.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto;&amp;quot;&amp;gt;&lt;br /&gt;
g2 &amp;lt;- delete_edges(g, which(E(g)$score &amp;lt; -0.4))&lt;br /&gt;
ggraph(g2, layout = &amp;quot;linear&amp;quot;, circular = TRUE) + &lt;br /&gt;
  geom_edge_link() + &lt;br /&gt;
  geom_node_point() +&lt;br /&gt;
  geom_node_text(aes(label = names(V(g))), repel = TRUE)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE instead of making a new graph, manually selecting edges over the threshold score, I simply made a new graph by deleting the edges that does not satisfy the condition &amp;quot;score &amp;gt; -0.4&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
I can then do the same for &amp;quot;score &amp;gt; -0.65&amp;quot;, which speeds things up quite a bit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto;&amp;quot;&amp;gt;&lt;br /&gt;
g3 &amp;lt;- delete_edges(g, which(E(g)$score &amp;lt; -0.65))&lt;br /&gt;
ggraph(g3, layout = &amp;quot;linear&amp;quot;, circular = TRUE) + &lt;br /&gt;
  geom_edge_link() + &lt;br /&gt;
  geom_node_point() +&lt;br /&gt;
  geom_node_text(aes(label = names(V(g))), repel = TRUE)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>