FAQ Database Discussion Community

## Graph.get_adjacency() is slow and the output is strange

python,sparse-matrix,igraph
Consider a graph object G in python-igraph 0.7. If I want the adjacency matrix A of G, I have to write A=G.get_adjacency(), but there are two problems: Even if G is sparse with 3000 nodes, A is generated in a long time on my commercial laptop. Is it possible that...

## Error with subgraph in igraph package

r,igraph,subgraph
I want to get the subgraph of all the cycles in a graph. I tried the code below for (i in 1:length(cycles)){ vids<-as.numeric(unlist(cycles[[i]])) subgraph<- induced.subgraph(graph, vids) } But it throws and error as below: Error in .Call("R_igraph_induced_subgraph", graph, vids - 1, impl, PACKAGE = "igraph") : At iterators.c:759 : Cannot...

## Creating an igraph attribute overview

r,igraph
I'd like to know if there is a possibility to get a data frame from an igraph element which includes all vertex attributes as colnames. This looks like a trivial thing to do but I was not able to get it to work so far. All I could do is...

## Check if 2 vertices are connected in Igraph for R

r,igraph
what are the functions which check if two vertices (specified by their name attribute) are connected by an edge (incoming or outgoing or both) or not? in other words what are the name of the functions get_eid and are_connected of python in igraph in R ? thank you in advance,...

## Why igraph plot warns that “number of items to replace is not a multiple of replacement length”?

r,igraph
I have a graph with many edges between two nodes. When I plot it, I get a warning I don't understand in this context. This works fine: library(igraph) gg <- graph.empty(n=0, directed=TRUE) gg <- gg + vertex("10501") gg <- gg + edge("10501", "10501") gg <- gg + edge("10501", "10501") plot(gg)...

## How can I get a new graph translating the vertices to categories of vertices?

r,igraph
I am not sure of how to phrase this question, which is making it very hard to find a solution. I have a graph of people and their relationships in igraph. I also have the location of this people in a dataframe. > # graph.id is their id in the...

## Failed igraph installation on a Ubuntu box

python-2.7,installation,igraph
I tried installing igraph using easy_install, and received a message to contact the package's author or the easy_install maintainers. Knowing that igraph has a pretty active community in SO, I am pasting the message below: sudo easy_install python-igraph Searching for python-igraph Reading https://pypi.python.org/simple/python-igraph/ Best match: python-igraph 0.7.1-2 Downloading https://pypi.python.org/packages/source/p/python-igraph/python-igraph-0.7.1-2.tar.gz#md5=4b1f4dc621fc938434836e59dea31173 Processing...

## How to study the interaction between a set of nodes when the network is quite dense, using igraph?

r,networking,igraph
I have 4 undirected graph with 1000 vertices and 176672, 150994, 193477, 236060 edges. I am trying to see interaction between a specific set of nodes (16 in number) for each graph. This visualization in tkplot is not feasible as 1000 vertices is already way too much for it. I...

## get connected components using igraph in R

r,graph,igraph,connected-components
I would like to find all the connected components of a graph where the components have more than one element. using the clusters gives the membership to different clusters and using cliques does not give connected components. This is a follow up from multiple intersection of lists in R My...

## Using geo-coordinates as vertex coordinates in the igraph r-package

r,geolocation,igraph,network-analysis
In the igraph package for R, I am struggling to plot a social network using latitude/longitude coordinates as the layout of the graph. Imagine this simple example: a network with 4 nodes of which you know the geographical location and the connections: df<-data.frame("from" = c("Bob", "Klaus", "Edith", "Liu"), "to"= c("Edith",...

## Index of the community from iGraph community algorithms

igraph
Does the index of the community from any of the iGraph community algorithms have a meaning? e.g., if I use fc <- fastgreedy.community(g) and I get communities 1,2,3: does community 1 mean it was the strongest community because it merged first in the algorithm or are they just labels?

## How to make Networkx produce GML file with sorted nodes

python,graph,igraph,networkx
I have the following codes: #!/usr/bin/env python import networkx as nx def main(): """docstring for main""" outerdict = {"A":["a1","a2","a3"], "B":["b1","b2","b3","b5","b6", "b7"], "C":["c2","c3"], "D":["d1","d2","d3"]} keynode = "Z" colorlist = [ "#beaed4", "#fdc086", "#ffff99", "#386cb0","#f0027f"] G = nx.Graph() G.add_node(keynode,graphics={"fill":"#7fc97f","w":27,"h":27, "d":27}) for i,ky in enumerate(outerdict): nodes = outerdict[ky] nodecol = colorlist[i] print ky,...

## R - Problems with igraph: Why isn't the option “simplify” working? And how can I generate an EPS of the output?

r,fonts,igraph,eps,simplify
I have the following R MWE making use of igraph (manual). ################### ##MWE iref.sub <-...

## Remove mirror lines in dataframe

r,dataframes,igraph
I'm R begginer and this question may appear quite naive but I try to create a network based on family relationships among a population. I'm working with R package igraph. Preparing my data, I'm ending having this kind of dataframe Source Target Distance Actr22510 Actr22509 1 Actr22511 Actr22509 1 Actr22509...

## how to delete all edges with specific weight in igraph python?

python,igraph
I am new to Python so sorry if this is so simple,I am trying to delete all edges which its weight is zerobut with this code I was just able to delete one edge at a time, How to make it in away that it will delete all the edges...

## Calculation of betweenness in iGraph

r,social-networking,igraph
I've seen some info suggesting that closeness in iGraph weighted graphs is calculated using the weights as costs, rather than strengths. I'm wondering if this is also true for betweenness. i.e, if I have two paths between vertices, one of them (a) with edge weights summing to 100 and the...

## Using igraph for read 'ncol' format while preserving labels

python,igraph
I need an automated way to read 'ncol' format (edge list) while preserving labels. For instance: Given a small-graph.edgelist: 0 1 0.47 0 2 0.67 0 3 0.98 0 4 0.12 0 5 0.82 0 10 0.34 1 2 0.94 1 3 0.05 1 4 0.22 2 3 0.24 2...

## turning igraph adjacency matrix into numpy array

python,numpy,igraph
By writing import igraph g = igraph.Graph() g.add_vertices(6) g.add_edges([(0,1),(0,3),(0,4),(0,5),(1,2),(2,4),(2,5),(3,0),(3,2),(3,5),(4,5),(3,3)]) A=g.get_adjacency() I get the adjacency matrix of graph g, as a Matrix object. I want to calculate its eigenvalues by using, for example, numpy.linalg.eigvals(). This method takes a numpy array object as argument. How do I convert a Matrix object into...

## r igraph - how to add labels to vertices based on vertex id

r,label,igraph
I have an igraph where each vertex has both a vertex ID and a name. I want the vertices to still be identified by their vertex ID's, but to be labeled by their names. It seems like when adding labels to vertices through V(g)\$label <- names, the names have to...

## Assigning graph attributes using a function in R

r,attributes,igraph
I am working on a set of functions that will allow me to plot network data in various ways. Because some procedures are being used in multiple functions, to avoid copying and pasting I try to turn such procedures into mini-function that I can then simply recall whenever necessary. Right...

## Changing node/vertice opacity in iGraph in R

r,opacity,igraph,network-analysis
I have a network that, when I plot it, has a number of overlapping nodes. I want to change the opacity of the colors so that you can see nodes underneath others when they overlap. As an example, see this video: https://vimeo.com/52390053 I'm using iGraph for my plots. Here's a...

## igraph graph.lattice for all combinations (in R)

r,igraph
Greetings: This graph seems like something that should be pretty straightforward using the igraph package for R. I am trying to figure out which arguments I need to pass to obtain the edges between sub-patterns and super-patterns. In this example, a item set of 5 items is represented. I am...

## igraph in R - find all accessible vertices

r,graph,igraph
is there a way to find all accessible vertices of an igraph in R, like the function acc in the graph package? I can only find a function for adjacent vertices in an igraph but not accessible vertices. To give some context, I have a hierarchical graph, and I want...

## igraph - How to claculate closeness method in iGraph to disconnected graphs

igraph,measure
I use igraph in R for calculate graph measure, my graph make in a PIN that not Connected Graph and is Disconnected Graph. closeness method for connected graph is good and right calculate, and for Disconnected graph in not Good! library(igraph) # Create of Graph Matrix for Test Closeness Centrality...

## Visualizing graph/network with 3 layeres (tripartite) in R/igraph

r,igraph
I have a "layered" network, with 3 layers, let's say parents(P), children(C), grandchildren(G). The edges are always directed and towards a younger generation (either patent->child, child->grandchild or parent->grandchild). No edges between vertices in the same generation. The graph is represented by 3 edge lists (P_C, C_G, P_C). A short example...

## Can't generate igraph_degree_sequence_game on igraph

c++,c,igraph
I want to use the igraph_degree_sequence_game igraph graph generator to generate a network. The example on the igraph C library works well on my computer, but if I change to some other simple degree distributions (see the code below), I got this error: Error at games.c:830 :degree sequence game (simple),...

## How to get the HITS function in R tool?

r,matrix,igraph
I want to know how to find HITS function in R. Here is my code: library(igraph) library(proxy) A <- matrix(c(0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0,...

## Why isn't optimal_count giving the right result?

python,cluster-analysis,igraph
I'm trying to understand python-igraph and specifically the community_walktrap function. I created the following example: import numpy as np import igraph mat = np.zeros((200,200)) + 50 mat[20:30,20:30] = 2 mat[80:90,80:90] = 2 g = igraph.Graph.Weighted_Adjacency(mat.tolist(), mode=igraph.ADJ_DIRECTED) wl = g.community_walktrap(weights=g.es['weight']) I would have assumed the optimal count of communities to be...

## Creating Variables with Group in R igraph

r,igraph
below are my reproductive sample codes. sender_code <- c(12 ,1 ,6 ,19 ,7 ,8 ,3 ,17 ,13 ,10 ,4 ,9 ,2 ,5 ,15 ,11 ,16 ,20 ,14 ,18) receiver_code <- c( 20 ,16 ,7 ,3 ,4 ,11 ,8 ,2 ,10 ,12 ,17 ,5 ,1 ,18 ,13 ,9 ,6 ,15 ,19...

## How can I create a clip to show the evolution of a network?

r,network-programming,png,igraph
Through R I can generate the topology of a network at each t, where t = 2000. What is generated is a .png file for each t. Do you know a program (or a way) to use these .png files as "frames" to create a video of how the network...

## Smart way to remove mutual edges with python-igraph 0.7

python,graph,igraph
Let L be a directed graph, I have to remove the mutual edges of L. Remember that two edges are mutual if they are of the type a--->b and b---->a. For example L.is_mutual() returns list of booleans, every boolean corresponding to an edge. True is returned for a given edge...

## Error installing python-igraph on Ubuntu (from command line)

python,linux,ubuntu,igraph
I'm trying to install python-igraph from command line. I created a new Ubuntu instance on an AWS server, so I have to do everything from command line. Here is what I have done from a fresh install of Ubuntu: \$sudo apt-get update \$sudo apt-get install build-essential \$sudo apt-get install python-dev...

## igraph group vertices based on community

r,igraph
from my previous question here Creating Variables with Group in R igraph, I want to put the vertices with the same group/color close together in my type of data just like this one https://lists.nongnu.org/archive/html/igraph-help/2012-03/pngFA9V_3yRcA.png. Thanks in advance

## top-down community detection in a network

algorithm,social-networking,igraph
I'm trying to find a way to find network communities in a top-down way. Most of the algorithms available (e.g. in the igraph package) are working bottom up - that is they start by assuming all nodes are singlton communities, and then combine them to larger communities. I want to...

## visualizing clr network in cytoscape

r,graph,nodes,igraph,edges
Does anyone know how I can proceed from generating a clr network to visualizing the network nicely using cystoscape? I used minet package to generate a clr network as follows: source("http://bioconductor.org/biocLite.R") biocLite("minet") library(Rgraphviz) library(minet) data(syn.data) mim <- build.mim(syn.data,estimator="spearman") #net<-minet(syn.data,"mrnet","mi.shrink","equalwidth",10) net <- clr( mim, skipDiagonal=1 ) graph <- as(net, "graphNEL") The...

## Python igraph for windows 64bit

python,igraph,python-3.4
I am looking for python-igraph package for windows 64bits. I have installed python 3.4 and it seems that I can not find proper igraph installation package for it. I have crawled all webpages and still could not find what I am looking for. Can anyone help me please? Thanks...

## Kou algoritm to find steiner tree using igraph

r,igraph
I am trying to implement the Kou's algorithm to identify Steiner Tree(s) in R using igraph. The Kou's algorithm can be described like this: Find the complete distance graph G' (G' has V' = S (steiner nodes) , and for each pair of nodes (u,v) in VxV there is an...

## Setting the number of edges in igraph_erdos_renyi_game c++

c++,social-networking,igraph
I would like to create a directed network graph using igraph c++ in which each node is randomly connected to exactly n other distinct nodes in the network (i.e. excluding connections to itself, and loops/multiple edges to the same loop). I was thinking of using the method igraph_erdos_renyi_game, but for...

## How to get the vertices from an edge using igraph in python?

python,igraph,vertex,edges
I am looping through the edges of a graph with: for es in graph.es: .... # v = [] # v = es.vertices()? ... What method can I use to get the source and the target vertices for each edge?...

## Visualizing graph/network with 3 layeres (tripartite) igraph

r,igraph
There are already a topic about tripartite graphs in igraph, but the way they use layout.sugiyama is not good for me. I would like to impose a order for the nodes. Actually, I would like to visualize edge crossing for the tripartite graph. Suppose I have a tripartite graph with...

## R: Generating network edgelist (igraph) from base table?

r,igraph,sna
I’m trying to write a function that will read in a large base table (example below) and check if any of the unique entities (ID) can be linked via 15+ attributes (bank a/c, phone num, email, zip code…etc). No fuzzy matching required this time. df <- data.frame( id = c('01','02','03','04','05','06','07','08','09','10'),...

## Calculate number of common neighbors in igraph R

r,igraph
Can anyone help me to find the number of common neighbors of two vertices using igraph R. I tried to get this with following command but it returned with list(). intersect(neighborhood(graph=TD1,order=1,nodes=714),neighborhood(graph=TD1,order=1,nodes=4211)) >>>> list() Thanks Anna...

## building a graph using two sets of nodes in R

r,graph,igraph
I am trying to build a graph in R using two sets of nodes with the same size. each list has some numbers in it representing node numbers. I want each node in the first list be connected to the corresponding node in the other list. For example list1 should...

## python igraph - get_adjlist() not returning vertex names, only ids

python,igraph
I'm loading a graphml into igraph from igraph import * wiki = Graph.Read_GraphML("discussion_network.graphml") but when I do g = wiki.get_adjlist() I get id's, while in the graphml file there are actually stored names for every node. >>> g = wiki.get_adjlist() >>> str(g) '[1, 2, 3, 4]' >>> str(g) '[0, 2,...

## Indexing vertex name

python,igraph
I am using python igraph version 0.6.5. I am bit unclear that in a code below: g = igraph.Graph(directed=True) g.add_vertex('A') g.add_vertex('B') g.add_vertex('A') print g.vcount() This gives me the count of vertex as 3 even though the vertex name 'A' is duplicated , why both vertex name 'A' are taken as...

## Edges of the graph being created incorrectly

r,igraph
I have created Term Document matrix from a corpus: x <- TermDocumentMatrix (corpus ) Then I created a matrix: Matrix <- as.matrix ( x ) Matrix [ Matrix >=1 ] <- 1 Matrix <- tcrossprod ( Matrix ) As an output: ` Terms Terms best love fun don’t games best...

## Get a vector of all edges ids

c++,igraph
In igraph's c/c++ library, I am trying to write a function which returns a random edge of a graph. The intention is to write a larger function which "visits" a random edge at each time step, and stops when all edges have been visited. At each some visit, some external...

## Python duplicate a python-igraph

python,reference,duplicates,igraph
I have a python-igraph and need to make two copies of it and change each of the copies without changing the other one. Right now I am doing it like this: copy1 = fullGraph copy2 = fullGraph But it seems that this is not the correct way of doing it...

## How to get the edge list of a strongly connected components in a graph?

r,algorithm,graph,cycle,igraph
I have a weighted directed multigraph with a few cycles. With clusters function in igraph package, I can get the nodes belongs to a strongly connected components. But I need the path/order of the nodes that form a cycle. EDIT after @josilber's response I have a very dense graph, with...

## Two identical methods “vertex_disjoint_paths” and “cohesion” in the library?

python,igraph
I am concerted about the existence of two identical methods of the same functionality in the igraph library for python. The functions are: "vertex_disjoint_paths" and "cohesion" for the \$k-vertex-connectivity\$. And, similarly, "edge_disjoint_paths" and "adhesion" for \$k-edge-connectivity\$.

## Sorting vertex and adding colors to groups in igraph r

r,sorting,igraph,rgl
I have an probably really simple problem. I have a matrix of distances MD (see example below) between a group of 6 people. They are sorted into three groups: ClassA <- c("TOM","EVE","STEVE") ClassB <- c("JANE","HANNAH") ClassC <- c("ADAM") matrix: TOM JANE ADAM EVE STEVE HANNAH TOM 0.0000000 0.8383965 1.1979821 1.186857...

## Creating Variables with Group in R igraph2

r,legend,igraph
in the link is my previous question and codes about igraph in R Creating Variables with Group in R igraph My question now is why the arrow head in the example are small while mine are big like this: How can I reshape the arrow to look like the answer...

## Failing to install python-igraph

linux,python-2.7,igraph
I'm trying to install python-igraph. After I run sudo pip install python-igraph I got the following log: Downloading/unpacking python-igraph Downloading python-igraph-0.7.1-1.tar.gz (375kB): 375kB downloaded Running setup.py egg_info for package python-igraph Installing collected packages: python-igraph Running setup.py install for python-igraph Cannot find the C core of igraph on this system using...

## How to create self loop in igraph R?

r,igraph
How to add self loop to a graph beside changing Adjacency matrix which is changing c(i,i)=1, is there a function to do that in igraph R package? Edit : graph creation : network=read.csv(file.choose()) network[,1]=as.character(network[,1]) network[,2]=as.character(network[,2]) mygraph=graph.data.frame(network,directed=TRUE) E(mygraph)\$weight=as.numeric(network[,3]) reproducible example : karate <- graph.famous("Zachary") E(karate)\$weight <- 2 adjacency<-get.adjacency(karate, attr="weight", edges=FALSE, names=TRUE)...

## How to create a polar network graph (multiple rings) in igraph & R

r,igraph
I have a graph with <100 nodes, with several categories. I would like the nodes belonging to one category to be in the center, with the other nodes arranged evenly in a circle around the outside - like a star graph, but with multiple nodes in the center. NodeXL calls...

## Multicolored nodes using igraph and vertex.pie

r,pie-chart,igraph,graph-coloring
I'd like to create multicolored nodes. I'd like to stay with igraph. I already found the vertex.shape.pie option. Here is some example data: test_fun <- function(color1,color2,len){ vec <- replicate(len,sample(c(color1,color2,NA),1)) return(vec) } set.seed(50) num_nodes<- 20 test_graph <- erdos.renyi.game(num_nodes, 1/6) V(test_graph)\$color_1 <- test_fun("darkgreen","blue",num_nodes) V(test_graph)\$color_2 <- test_fun("brown","blueviolet",num_nodes) V(test_graph)\$color_3 <- test_fun("red","green",num_nodes)...

## Assigning graph attributes using a function in R using switch()

r,switch-statement,igraph,vertex-attributes
I have a follow up question to the one I asked here. I want to build a function that will assign attributes to a graph based on a certain parameter (called lev in the example below). Here is my toy graph: toy.graph <- graph.formula(121-221,121-345,121-587,345-587,221-587,490,588) and here is a sample function:...

## Clustering network nodes by attributes

r,graph,plot,igraph,edges
I have a data.frame similar to d as follows. d <- structure(list(ID = c("KP1009", "GP3040", "KP1757", "GP2243", "KP682", "KP1789", "KP1933", "KP1662", "KP1718", "GP3339", "GP4007", "GP3398", "GP6720", "KP808", "KP1154", "KP748", "GP4263", "GP1132", "GP5881", "GP6291", "KP1004", "KP1998", "GP4123", "GP5930", "KP1070", "KP905", "KP579", "KP1100", "KP587", "GP913", "GP4864", "KP1513", "GP5979", "KP730", "KP1412", "KP615", "KP1315",...

## Find all vertices that can reach a set of other vertices [igraph package in R]

r,igraph
How can I find, in a directed graph, all vertices that can reach a set of other vertices with the igraph package in R? I'm able to find them for a single vertex using (e.g. for all vertices that can reach vertex 4): subcomponent(g, 4, mode="in") However, how can I...

## writing edgelist from igraph to file in R; how to write vertex names not vertex ids

r,igraph
I have taken a graph, and pulled out a subgraph from it, using FlashGraphs, which gives me an igraph with vertex names spread out throughout the range of vertices. I attempt to write the edgelist using write.graph(sub.fg,"lc_edgelist.txt", "edgelist") but when I do so, I get a file that looks like...

## iGraph histogram object

python,r,ggplot2,igraph
I have a graph G of which I what to calculate the degree distribution. For this, using Python iGraph's "degree_distribution()" seems obvious. However, the function returns an "histogram objects" which I find difficult to deal with. I use the following code: dD = G.degree_distribution(bin_width=1) print(dD) Which returns: N = 104,...

## Write Pajek files with node labels using python-igraph

python,igraph
I am constructing graphs using igraph and writing them out as Pajek (.net) files to use them with another program. The Pajek files are written with numerical indices for vertices rather than vertex labels, so when I read the files into the other program, the labels are gone. Here's a...