igraph

Generate Random network models with specified number of edges in r

旧巷老猫 提交于 2019-12-11 01:21:32
问题 I want to generate random networks and want to compare the network with my original network that has 16809 nodes and 173393 edges. So for comparing it with different netwok models i will have to generate network model with same number of edges. In the erdos.renyi model i can generate random graph with specifying number of edges. How to generate scale-free and small world networks with same number of edges using igraph library in r. My example script is as follows. library(igraph) g_erdos

Plot vertices at the same position

自闭症网瘾萝莉.ら 提交于 2019-12-10 23:14:16
问题 Is there a method to plot the shared nodes of 2 graphs at the same position? E.g., two graphs g1 = graph.ring(5) V(g1)$name=c('node1','node2','node3','node4','node5') g1 = g1 - V(g1)[1] g2 = graph.ring(5) V(g2)$name=c('node1','node2','node3','node4','node5') g2 = g2 - V(g2)[2] There are 3 nodes are exactly the same for g1 and g2. How can I plot them with the same nodes having same position so that its easy to compare the difference? par(mfrow=c(1,2)) plot(g1, vertex.label=V(g1)$name) plot(g2,

How to rename igraph node id when writing to file

让人想犯罪 __ 提交于 2019-12-10 22:58:10
问题 I'm trying to write a graph to a file but I'm getting a different node labels than I would like. Example Code: g <- graph.star(2) V(g)$name <- c('homer','marge') write.graph(g,file = 'g.graphml',format = 'graphml') Output: <?xml version="1.0" encoding="UTF-8"?> <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd"> <!-- Created

igraph error cannot create empty graph with negative number of vertices

人走茶凉 提交于 2019-12-10 22:29:35
问题 Why do I get an error when I try to create below simple graph? If i replace "a" and "b" with numbers then it works? any solution g1 <- graph(c("a","b"),directed=TRUE) error is Error in graph(c("a", "b"), directed = TRUE) : At type_indexededgelist.c:117 : cannot create empty graph with negative number of vertices, Invalid value In addition: Warning messages: 1: In graph(c("a", "b"), directed = TRUE) : NAs introduced by coercion 2: In graph(c("a", "b"), directed = TRUE) : NAs introduced by

Network: Making Graph Object from Event-Node Data Using igraph

北城以北 提交于 2019-12-10 22:26:59
问题 I want to make a network object for igraph from a event-note data. For example, I have a data looks like this. Event Person 1 Obama 1 Putin 1 Abe 1 Cameron 2 Putin 2 Xi 2 Merkel 3 Obama 3 Abe 3 Xi 3 Merkel I assume everybody in same event has connections. Obama, Putin, Abe, and Cameron have connections, because they are all in event 1. Based on this data, Obama and Abe have two times of connection because they are both in event 1 and 3. With this data, I want to calculate degree / betweenness

python-igraph number of vertices

柔情痞子 提交于 2019-12-10 20:50:03
问题 I am using python-igraph package to create a graph from my edges stored in a file. I use Graph.Read_Edgelist to read the edges and create my desired graph. When I need to get the number of vertices in my graph I use the Graph.vcount() function which is supposed to return number of vertices which is not the case for me. For a file like this: 1 2 5 300 This function returns 301 which is not what I am looking for ! I need it to return 4 which is the actual number of vertices of my graph. Any

Delete unconnected short paths from a graph in igraph

北城以北 提交于 2019-12-10 19:12:27
问题 I am working with networks in igraph, I have a network where there are short connected nodes that overlap eachother and so we donot exaclt see the edge. I want to delete al such short connected nodes as they are not connected to the main network. The degree thing doesnt work here as the nodes are not 0 degree., they are either connected to 1 or more genes but still not in the main network.Even the main network shows some overlapping genes, I want to correct that too. net <- simplify

Issue plotting vertex labels using igraph in ipython

空扰寡人 提交于 2019-12-10 19:08:17
问题 I usually work in a IPython notebook, which I open on Windows with the command ipython qtconsole --matplotlib inline I'm currently using IPython QtConsole 3.0.0, Python 2.7.9 and IPython 3.0.0. I want to plot a graph, together with its labels from igraph import * g = Graph.Lattice([4,4],nei=1,circular=False) g.vs["label"]=[str(i) for i in xrange(16)] plot(g, layout="kk") In this way, I obtain a inline plot of the graph, but there are no labels and I get the following message error for each of

python - igraph plot not available (cairo already installed)

让人想犯罪 __ 提交于 2019-12-10 18:48:57
问题 I've installed py2cairo using brew, but keep getting errors when trying to plot with igraph. I get the following error: >>> import igraph as ig >>> from igraph import * >>> UG = ig.Graph() >>> UG.add_vertex('a') >>> UG.add_vertex('b') >>> UG.add_vertex('c') >>> UG.add_vertex('d') >>> UG.add_edge('a','d') >>> UG.add_edge('a','c') >>> UG.add_edge('b','c') >>> UG.add_edge('b','a') >>> layout = UG.layout_kamada_kawai() >>> plot(UG,layout = layout) Traceback (most recent call last): File "<stdin>"

Combine two graphs and add edge weights in R igraph

别说谁变了你拦得住时间么 提交于 2019-12-10 17:39:03
问题 I'm trying to combine two graphs with the same nodes, but such that the new graph edge weight is the sum of the two original graphs (but of course want the solution to extend to N graphs): g1 <- graph.empty(directed=FALSE) + vertices(letters[1:2]) g1 <- g1 + edge("a", "b") E(g1)$weight <- 1 g2 <- graph.empty(directed=FALSE) + vertices(letters[1:2]) g2 <- g2 + edge("a", "b") E(g2)$weight <- 2 g3 <- g1 %u% g2 E(g3)$weight_1 #this is 1 E(g3)$weight_2 #this is 2 But i want E(g3)$weight to be 3.