Menu
  • HOME
  • TAGS

Can't generate igraph_degree_sequence_game on igraph

c++,c,igraph

I guess the example should be updated, because igraph_vector_init_real is not part of the public API. Anyway, the problem is, that (as the name suggests), this function expects real (i.e. double) literals. I.e. the correct way to use it is igraph_vector_init_real(&outdeg, 4, 3.0, 3.0, 3.0, 3.0); Btw. another error in...

Failed igraph installation on a Ubuntu box

python-2.7,installation,igraph

I found one workaround here: https://github.com/igraph/igraph/issues/680. Try installing the C library directly; easy_install worked following this. In case you encounter import error for igraph, update the LD_LIBRARY_PATH env variable to include the location with igraph executable (usually /usr/local/bin).

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

python,linux,ubuntu,igraph

To install pyhton-igraph on Ubuntu try following steps: sudo add-apt-repository ppa:igraph/ppa sudo apt-get update sudo apt-get install python-igraph p.s There is no package python-igraph available for 12.04 version....

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

r,label,igraph

Here's one way to do so: names <- c("114" = "Lisa", "115" = "Joe", "113" = "Peter", "112" = "Barbara", "113" = "Bart") V(g)$label <- names[V(g)$name] plot(g) ...

get connected components using igraph in R

r,graph,igraph,connected-components

You can use the results from clusters to subset your nodes according to the cluster size. library(igraph) # example graph set.seed(1) g <- erdos.renyi.game(20, 1/20) V(g)$name <- letters[1:20] par(mar=rep(0,4)) plot(g) # get cluster cl <- clusters(g) cl # $membership # [1] 1 2 3 4 5 4 5 5 6...

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

python,igraph

graph_like.delete_edges("weight"==0) does not work because it evaluates as follows: Python evaluates "weight" == 0, which is a comparison of the string "weight" with the number zero. The result of this comparison is False, a value of type bool. The result of the above expression is then fed into graph_like.delete_edges(), which...

Changing node/vertice opacity in iGraph in R

r,opacity,igraph,network-analysis

You might wanna try e.g. this: library(igraph) set.seed(1) g <- barabasi.game(200) plot(g, vertex.color = adjustcolor("SkyBlue2", alpha.f = .5), vertex.label.color = adjustcolor("black", .5)) ...

Unable to use python-igraph, no method or attribute available after installation (Ubuntu 14.04.)

python,ubuntu,import,igraph

You called your file /home/everdream/Downloads/igraph.py, rename it and remove the igraph.pyc file. You are trying to import from this file not the actual igraph module. import igraph;print igraph.__file__ will show you which file you have imported....

igraph layout.fruchterman.reingold outliers (example image included)

r,igraph

There is no built-in functionality for that in the Fruchterman-Reingold algorithm (and I suspect that using xmin, ymin, xmax and ymax would not work because it might simply "compress" the non-outlier part of the network to make more space for the outliers), but you can probably experiment with edge weights....

How to display the sum of weighted edges of a graph in R (igraph package)?

r,igraph

If the Pajek graph spec from your example is in an a file called, say, graph.txt, then: library(igraph) g <- read.graph("graph.txt", format="pajek") sum(E(g)$weight) ## [1] 6 is probably what you're looking for....

Get node descendants in a tree graph

r,graph,igraph,counting

Take a punt at what you want - it would be good if you could add a reproducible example to your question. I think what you want is to count the descendents of a node. You can do this with neighborhood.size and mode="out" argument. library(igraph) # create a random graph...

Efficiently generating random graphs with a user-specified global clustering coefficient

python,numpy,random,graph-theory,igraph

Having done a bit of reading, it looks as though the best solution might be the generalized version of Gleeson's algorithm presented in this paper. However, I still don't really understand how to implement it, so for the time being I've been working on Bansal et al's algorithm. Like my...

How to create self loop in igraph R?

r,igraph

To add a self-loop for each vertex in the karate example, just do karate[from=V(karate), to=V(karate)] <- 1 This will give you ...

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

python,igraph,vertex,edges

These are the very basic functionalities of igraph, described here thoroughly. If you iterate the <EdgeSeq> object (graph.es), you will go through all <Edge> objects (here edge). <Edge> has properties source and target. These are vertex ids, simply integers. You can get the corresponding <Vertex> object by graph.vs[]: for edge...

Using write.graph in igraph to output a .net file

r,igraph

From the docs at http://igraph.org/r/doc/write.graph.html: The Pajek format is a text file, see read.graph for details. Appropriate vertex and edge attributes are also written to the file. This format has no additional arguments. And http://igraph.org/r/doc/read.graph.html shows that edge weights are supported, and vertex ids are supported as well. So if...

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

python,igraph

These are just aliases: >>> from igraph import Graph >>> Graph.adhesion == Graph.edge_connectivity == Graph.edge_disjoint_paths True >>> Graph.cohesion == Graph.vertex_connectivity == Graph.vertex_disjoint_paths True ...

How to compare vertices of two graphs and assign community membership of the first graph to the second graph, in igraph?

r,graph,igraph

I think the simplest is V(g)$comm <- V(karate)[ V(g)$name ]$comm This solution assumes that the vertices of g are all included in karate. What happens here is that you can index a vertex sequence of a named graph with a character vector, and then the specified vertices are selected: V(karate)[...

Creating an igraph attribute overview

r,igraph

To whom it may concern - I just found the answer myself. It indeed is really simple and streightforward: df <- as.data.frame(vertex.attributes(test_graph)) ...

Edges of the graph being created incorrectly

r,igraph

I think the problem you're facing is that the graph you're trying to create is by its nature undirected. Also, when creating your question (it's much better now than when it was first posted, thank you) it's very nice to supply the code to recreate the data that you're using...

Visualizing graph/network with 3 layeres (tripartite) igraph

r,igraph

For example, you could do: library(igraph) coords <- matrix(c(rep(1:3, each = 3), rep(3:1, 3)), ncol = 2, dimnames = list(LETTERS[1:9], c("x", "y"))) g <- graph.formula(A--E, B--F, C--D, D-- H, E--G, F--I) plot(g, layout = coords[V(g)$name, ]) ...

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

igraph,measure

Please read the documentation of the closeness function; it clearly states how igraph treats disconnected graphs: If there is no (directed) path between vertex v and i then the total number of vertices is used in the formula instead of the path length. The calculation then seems to be correct...

Index of the community from iGraph community algorithms

igraph

There is no ordering; the community IDs that igraph uses are only arbitrary numbers.

Failing to install python-igraph

linux,python-2.7,igraph

You need igraph libraries before compiling python-igraph. Try sudo apt-get install -y libigraph0-dev and try install python-igraph again....

Multicolored nodes using igraph and vertex.pie

r,pie-chart,igraph,graph-coloring

vertex.pie requires a list of values/proportions that each color will have in the pie. You need to convert your color_* variables to that. To do so, you can first bind them together: v<-cbind(V(test_graph)$color_1,V(test_graph)$color_2,V(test_graph)$color_3,V(test_graph)$color_4) Then for each vertex, make a vector of 6 values (one for each color) containing 0 and...

Cannot get igraph edgelist working, ncol for matrix returns NULL

r,igraph

It was necessary to set the drop=F g = graph.edgelist(network_matrix[,1:2, drop=F], directed = TRUE) thanks @user20650 case closed...

Kou algoritm to find steiner tree using igraph

r,igraph

If I'm understanding the algorithm as you've written it, I think this gets you through step 3, but please clarify if that's not the case: library(igraph) set.seed(2002) g <- erdos.renyi.game(100, 1/10) # graph V(g)$name <- as.character(1:100) ## Some steiner nodes: steiner.points <- sample(1:100, 5) ## Complete distance graph G' Gi...

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

r,networking,igraph

In such a dense graph, if you only take the shortest paths connecting each pair of these 16 vertices, you will still get a graph too large for tkplot, or even to see any meaningful on a cairo pdf plot. However, if you aim to do it, this is one...

turning igraph adjacency matrix into numpy array

python,numpy,igraph

According to the documentation of iGraph's matrix class, you could retrieve the data as a list of lists and then convert easily to a numpy ndarray: A = g.get_adjacency() A = np.array(A.data) ...

Using IGRAPH object oriented programming

c++,c,igraph

Just do this extern "C" { #include <igraph.h> } c++ compiler mangles function names so when searching the library for that function it will not be found, if you do this, then every function declared in igraph.h will have c linkage preventing name mangling....

Creating Variables with Group in R igraph2

r,legend,igraph

Use appropriate values for edge.arrow.size. For me 1 works, but you may have to reduce it to 0.5 or less. with(message, plot(graph.data.frame(message), vertex.color = sender_country, vertex.label.color = "white", edge.color = sender_country, edge.arrow.width = 1, edge.arrow.size = 1) ) To add a legend just use legend and fill in the appropriate...

Cannot run the osmar navigation demo in R. Probably because the demo expects igraph0, which is deprecated

r,openstreetmap,igraph

There are some one-way streets that prevent the start and end node being connected. Here's some scrappy code that plots the nodes reachable from the hway_start node: plot(hways_muc) hway_start # osmar object plot_nodes(hway_start, add = TRUE, col = "red", pch = 19, cex = 2) # get reachable nodes, return...

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

r,igraph

1. Term I think you could say it is a tripartite graph but I am not sure if the term is used for directed graphs. 2. Create graph To create a graph object (with igraph package) just rbind all the edges and create it with igraph.data.frame. Before binding the column...

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

python,sparse-matrix,igraph

It does not matter whether the graph is sparse or not because igraph will still create a dense matrix so it's an O(n2) operation. (Technically, the matrix itself is created in the C layer where the initialization of the matrix to all zeroes takes O(n2) and then it is...

Permission denied error near end of python module (igraph) install

python,install,igraph

You can safely ignore the message. python-igraph tries to add a header file named igraphmodule_api.h to the list of Python headers to make it possible for other extension written in C to use some of igraph's internal API. You won't need this unless you want to develop another Python extension...

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

r,igraph

Use write.graph(sub.fg, "lc_edgelist.txt", "ncol"). The NCOL format uses the symbolic vertex names from the $name vertex attribute instead of the node IDs. It is your responsibility to ensure the uniqueness of the names before saving.

How to add edges in an igraph object from a dictionary

python,time-complexity,igraph,edges

What you do is perfectly fine; maybe the for loop could be replaced with a zip call. If you are using Python 2.x:: from itertools import izip edges, weights = izip(*dict_edges.iteritems()) g = Graph(edges, edge_attrs={"weight": weights}) If you are using Python 3.x:: edges, weights = zip(*dict_edges.items()) g = Graph(edges, edge_attrs={"weight":...

Get all disconnected pairs of nodes in a network

python,social-networking,igraph

Re the first question (listing pairs of disconnected nodes): yes, you have to do this manually, but it is fairly easy: from itertools import product all_nodes = set(range(g.vcount()) disconnected_pairs = [list(product(cluster, all_nodes.difference(cluster))) \ for cluster in g.clusters()] But beware, this could be a fairly large list if your graph is...

Error with subgraph in igraph package

r,igraph,subgraph

If you pass a number as a vertex id to the induced.subgraph function, it will be accessing the vertices by number (in your graph numbers 1 through 23), leading to the "Invalid vertex ID" error due to indices like 26, 29, and 30. You want to actually refer to vertices...

Install python-igraph with the anaconda distribution (windows)

python,igraph,anaconda

Check the documentation on their site: http://igraph.org/python/ It says that you need to download the .msi installer, pip does not work under windows. That is probably because you need a C compiler and windows does not supply one by default.

Assigning graph attributes using a function in R

r,attributes,igraph

Two things: Your function is not returning a value. You aren't reassigning the variable when you call the function. Try: toy.graph <- graph.formula(121-221,121-345,121-587,345-587,221-587, 490, 587) deco <- function(x){ V(x)$color <- "red" return(x) } toy.graph <- deco(toy.graph) plot(toy.graph) If you want to avoid reassigning variables and having your function return a...

Weighted Adjacency matrix igraph and R

igraph

What you have is a bipartite graph, and you need the unipartite projection of it. This is easy: ## Sample data data <- " ID Name 1 A 2 B 1 C 1 B 2 C 2 D 3 A 3 B " ## Read it in an edge list...

Smart way to remove mutual edges with python-igraph 0.7

python,graph,igraph

Does l contain the edge list of your graph? In that case, your solution is slow because for every edge to be deleted, igraph has to look up its identifier from the endpoints (since you give the endpoints to delete_edges and not the edge index). Since delete_edges can work with...

Why isn't optimal_count giving the right result?

python,cluster-analysis,igraph

Why do you think the optimal cluster count should be 3? It seems to me that all the nodes have fairly strong connections to each other (they have a weight of 50), except two small groups where the connections are weaker. Note that clustering methods in igraph expect the weights...

A scalable function for get boundary vertices in a graph

python,igraph,hierarchical-clustering

The VertexClustering object returned by cl.as_clustering() has a crossing() method - this gives you a Boolean vector which contains True for edges that are between clusters and False for edges that are within a cluster. You can easily extract the indices of the crossing edges like this: cl = g.community_fastgreedy().as_clustering()...

Python igraph: Fastest way to convert large graph to python-igraph graph

python,algorithm,graph,igraph

The problem is that you add one edge after another, which is very time consuming due to the underlying data structure. It's much faster to first build a list of vertices and a list of edges and then add all edges with one call to add_edges(...). mygraph = {"A" :...

Check if 2 vertices are connected in Igraph for R

r,igraph

There is an are.connected() function in R's igraph library g <- graph.ring(10) are.connected(g, 1, 2) # [1] TRUE are.connected(g, 2, 4) # [1] FALSE for a list functions in the package, you can try looking at help(package="igraph") in the future....

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

r,igraph,sna

You could split on the field of interest, compute all pairs (combn can be useful here), and then combine: get.pairs <- function(colname) { spl <- split(df, df[,colname]) do.call(rbind, lapply(spl, function(x) { if (nrow(x) == 1) { return(NULL) # No duplicates for this value } else { combs <- combn(nrow(x), 2)...

Indexing vertex name

python,igraph

When you run g.add_vertex('A'), igraph does not add "A" as a vertex to the graph - it adds a completely new vertex and then assigns "A" to its name attribute, but names are not required to be unique in igraph. Internally vertices are represented by integers from zero to |V|-1,...

invalid byte '?' at position 2 of 2-byte sequence validation/parse error

xml,r,encoding,utf-8,igraph

This line is definitely incorrect: edges[,i] <- gsub("[[:ctrl:]]", "", edges[,i]) I see that its purpose would be to strip away any disallowed control characters from the edge attributes so you don't get any trouble further on with the GraphML writer, but [[:ctrl:]] should be [[:cntrl:]]. (Actually, my R version complains...

Sorting vertex and adding colors to groups in igraph r

r,sorting,igraph,rgl

First, it would be nicer if you had your name/class assignments in a data.frame. (It also would have been nice if they were stored in a list or something). Here I gather all the ClassA/B/C/* varaibles into a list and stack them indclass <- stack(mget(ls(pattern="Class*"))) indclass # values ind #...

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

r,igraph

I have responded to this question on the mailing list recently, but for sake of completeness I'll also include the answer here. igraph layouts are simply matrices with 2 columns and one row for each vertex, so the easiest is probably if you generate such a matrix yourself. If you...

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

r,network-programming,png,igraph

Most video editing software can do this. Photos hop can compile them into a video and or a gif.

(local and global) Efficiency using igraph shortest.paths function

r,graph-theory,igraph,shortest-path

I know that my title doesn't fully account for what my question really was. So I'm answering it myself since I just got it to work. #Mean local efficiency (global efficiency for each node) gn<-graph.neighborhood(my.graph,1) #list with subgraphs of directly connected graphs names(gn)<-V(my.graph)$name local.eff<-numeric(length(gn)) for (i in 1:length(gn)){ gn[[i]]<-gn[[i]] -...

Calculation of betweenness in iGraph

r,social-networking,igraph

Indeed, igraph assumes that the weights of the edges in betweenness calculation are costs, not strengths. This is because (as far as I know) betweenness is defined in terms of shortest paths, and the "length" of a path in graph theory is the sum of the lengths (weights) of the...

Python igraph for windows 64bit

python,igraph,python-3.4

Christoph Gohlke's page contains a Python wheel compiled for Python 3.4 on a 64-bit Windows machine.

Creating edge attributes by combining attributes of incident vertices using igraph (R)

r,attributes,igraph

Here is probably the fastest solution. The key is to vectorize. library(igraph) G <- graph.full(45) set.seed(1) V(G)$prob <- pnorm(vcount(G)) ## Original solution system.time( for (i in E(G)) { ind <- V(G)[inc(i)] p <- get.vertex.attribute(G, name = "prob", index=ind) E(G)[i]$wt.1 <- prod(p) } ) #> user system elapsed #> 1.776 0.011...

Using igraph for read 'ncol' format while preserving labels

python,igraph

The original labels are preserved, but they are stored in the name vertex attribute. Try this after reading your graph as usual: names = g.vs["name"] for edge in g.es: print names[edge.tuple[0]], names[edge.tuple[1]], edge["weight"] Update: If you are absolutely sure that your file contains only continuous numeric IDs from zero (i.e....

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

Thanks to @bergant, I am posting here the answer. -Use igraph::simplify in case there is another package masking the function. -Add the option vertex.label.family="Arial" to override the serif default. ################### ##MWE iref.sub <-...

igraph group vertices based on community

r,igraph

I have implemented such a function in my package NetPathMiner, called layoutVertexByAttribute. library(igraph) library(NetPathMiner) g <- graph.data.frame(message) g <- setAttribute(g, "sender", sender_country) l = layoutVertexByAttr(g, "sender", cluster.strength=10, layout=layout.kamada.kawai) plotNetwork(g, vertex.color="sender",layout=l) You can look at the source code here or view the vignette for more details. EDIT: Since installing the package...

igraph in R - find all accessible vertices

r,graph,igraph

There is subcomponent- example: g1 <- graph.tree(n = 8, children = 2, mode = "out" ) print.igraph(g1,full = TRUE) # IGRAPH D--- 8 7 -- Tree # + attr: name (g/c), children (g/n), mode (g/c) # + edges: # [1] 1->2 1->3 2->4 2->5 3->6 3->7 4->8 subcomponent(g1, 2, mode...

R reading an adjacency list from file

r,igraph,adjacency-list

Your data is not a proper adjacency list, because it is missing the lists for 5-8. So I just removed these vertices from your list. Igraph has a function to create a graph from an adjacency list, so you just need to read in the data, and create the graph...

R: Vertex attributes do not match vertex names in an arc plot

r,plot,igraph

You just need to also explicitly set the vertices= parameter. This is how the function knows what values to keep each of the *.nodes properties assigned to. You can use this in place of the ordering= parameter you have set now since you are not re-ordering the nodes at all....

Remove mirror lines in dataframe

r,dataframes,igraph

If the ultimate goal is to create an undirected igraph object, may be you don't need to remove these lines at all. Simply: library(igraph) # Create an undirected graph, with edges between "Source" and "Target" # Distance is kept as an edge attribute. g <- graph.data.frame(df, directed=FALSE) # Remove multiple...

How to read the pickled igraph graph object from old version by new version igraph

python,igraph

I also have this error message, by me It was caused by install: The first time I've installed igraph pip install igraph It was "successfully" installed, but get this message. The second time I installed so: pip install python-igraph After a much more verbose install-output: It works well, and there...

Computing the un-weighted length of a weighted shortest path

r,algorithm,igraph

I'm not sure whether I completely understand what "edge length" and "weighted edge length" means in your post (I guess that "edge length" is simply "the number of edges along the path" and "weighted edge length" is "the total weights of the edges along the path"), but if I'm right,...

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

r,igraph

Searching the igraph package source for the line giving the warning, it seems that the culprit function is autocurve.edges in plot.common.R: autocurve.edges <- function(graph, start=0.5) { cm <- count.multiple(graph) el <- apply(get.edgelist(graph, names=FALSE), 1, paste, collapse=":") ord <- order(el) res <- numeric(length(ord)) p <- 1 while (p <= length(res)) {...

How to make Networkx produce GML file with sorted nodes

python,graph,igraph,networkx

An ordered graph data structure is available in NetworkX since inclusion on Jan 1 2015. The OrderedGraph class will output nodes and edges from the NetworkX data structure in the order they are added. You'll need to get the latest development version at https://github.com/networkx/networkx/ for the following to work. import...

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

r,networking,igraph

Assuming you read your data into a data.frame named dd, you can get an adjacent matrix with X <- with(dd, table(Event, Person)) adj <- crossprod(X,X) # Person # Person Abe Cameron Merkel Obama Putin Xi # Abe 2 1 1 2 1 1 # Cameron 1 1 0 1 1...

Building and adjacency matrix

r,igraph,adjacency-matrix

Does the following do what you are looking for? # simulate data. d <- data.frame( id=c(2,3,4,5,6,6,8,11,11,12,12), author=c("FN", "VM","VA","FK","VM","SM","FK","FK","VB","FK","VB") ) d id author 1 2 FN 2 3 VM 3 4 VA 4 5 FK 5 6 VM 6 6 SM 7 8 FK 8 11 FK 9 11 VB 10...

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

r,algorithm,graph,cycle,igraph

Assuming that all nodes in each strongly connected component form a cycle and that you're only interested in this large cycle (e.g. in your example you're just interested in the cycle with nodes 1:21 and the cycle with nodes 22:23), then you can extract the node order that forms the...

Creating Variables with Group in R igraph

r,igraph

Try this for a start: library(igraph) with(message, plot(graph.data.frame(message), vertex.color = sender_country, vertex.label.color = "white", edge.color = sender_country) ) More info under ?plot.igraph. ...

IGraph python get neighbour Vetrices from Vertex

python,graph,igraph

g.neighbors("a", mode="out") will give you the vertex indices for the neighbors. You can then get the names as follows: >>> neis = g.neighbors("a", mode="out") >>> g.vs[neis]["name"] But actually, if I were you, I would try to work with vertex indices as much as possible because it's way faster to work...

Weighted Bimodal Bipartite Graph Projection conserving original weights

python-2.7,igraph,networkx,bipartite,sna

There is an example in the documentation you reference at https://networkx.github.io/documentation/latest/reference/generated/networkx.algorithms.bipartite.projection.generic_weighted_projected_graph.html of how to do exactly this. It goes like this: import networkx as nx from networkx.algorithms import bipartite edges = [('A1','B1',3), ('A1','B2',7), ('A2','B1',2), ('A2','B2',4), ] B = nx.Graph() B.add_weighted_edges_from(edges) def my_weight(G, u, v, weight='weight'): w = 0 for nbr...

Setting the number of edges in igraph_erdos_renyi_game c++

c++,social-networking,igraph

m is the total number of edges in erdos_renyi_game(). So just use k_regular_game(), it does exactly what you want.

Calculate number of common neighbors in igraph R

r,igraph

neighborhood() returns a list of integer vectors, one for each source node you passed in. Since you only have a single source node, you have to extract the first element of the list that neighborhood() returns before passing them to intersect(): intersect( neighborhood(graph=TD1, order=1, nodes=714)[[1]], neighborhood(graph=TD1, order=1, nodes=4211)[[1]] ) ...

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

r,switch-statement,igraph,vertex-attributes

This looks like what you want: library(igraph) toy.graph <- graph.formula(121-221,121-345,121-587,345-587,221-587,490,588) deco2 <- function(x, lev){ #make sure you assign switch's output to a variable (e.g. y) y <- switch(lev, one = "red", two = "yellow") V(x)$color <- y x } toy.graph <- deco2(toy.graph, lev="one") > V(toy.graph)$color [1] "red" "red" "red" "red"...

igraph graph.lattice for all combinations (in R)

r,igraph

I don't think the graph.lattice is capable of creating this kind of graph. But you can define a new function: graph.comb <- function(word) { # creates graph objects from character combination in word # example graph.comb("abc") do_layer <- function(words) { do.call( rbind, lapply(words, function(word){ l_vec <- sapply(seq_len(nchar(word)), function(l) substring(word, l,...

building a graph using two sets of nodes in R

r,graph,igraph

One way to accomplish this would be to construct your graph with an edge list passed to the graph.data.frame function. The first column will be all the nodes in your first vector and the second will be all the nodes in your second vector: list1 <- c("A", "B", "C") list2...

Python duplicate a python-igraph

python,reference,duplicates,igraph

Assign statements do not copy objects in Python. You might want to use copy.deepcopy() function. More details about copy.shallow() and copy.deepcopy() can be found in this answer Also Graph objects have inherited copy method which make deep copies. Use this code copy1 = fullGraph.copy() copy2 = fullGraph.copy() ...

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

r,igraph

You can do this with the graph.data.frame function in igraph, creating a new graph based on the region associated with each edge in your current graph. First, here's the setup you're describing: # 654 <-> 11; 123 <-> 11; 123 <-> 771 library(igraph) g <- graph.data.frame(cbind(c(654, 123, 123), c(11, 11,...

Saving the results of each iteration of a for-loop in R as a network object using the filename

r,csv,for-loop,igraph,sna

To open the files, you can use system, e.g.: l.files <- system('ls *.csv'', intern=T) file.objs <- lapply(l.files, read.table) Then you should be able to easily convert the items in file.objs to edgelists....

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

python,igraph

Write a utility function and then use it whenever you need an adjacency list with names: def get_adjlist_with_names(graph): names = graph.vs["name"] result = {} for index, neighbors in enumerate(graph.get_adjlist()): result[names[index]] = [names[nei] for nei in neighbors] return result ...

Graph intersection using igraph in R

r,igraph

You can just use the keep.all.vertices argument to graph.intersection(), see http://igraph.org/r/doc/graph.intersection.html If you use this argument, you'll need to call graph.intersection() directly, instead of using the infix operator, so that you can pass the extra argument. Using the example from the other answer: library(igraph) g1 <- graph.formula(A -- B --...

igraph select function for generic attributes

python,igraph

You could use a dict and str.format: atr = 'age' c = 30 g.vs(**{'{}_lt'.format(atr): c} If you were worried about memory you could also use a gen exp: (v for v in g.vs if v[atr] < c) Both return the same output: In [2]: g = Graph([(0,1), (0,2), (2,3), (3,4),...

Combine two graphs and add edge weights in R igraph

r,igraph

Just add weight_1 and weight_2. igraph does not currently have a way to combine vertex/edge attributes from multiple graphs, except by hand. This is usually not a big issue, because it is just an extra line of code (per attribute). Well, three lines if you want to remove the _1,...

Write Pajek files with node labels using python-igraph

python,igraph

You colleague is kind, but (s)he is still wrong. :) The right attribute to set is called id: g = ig.Graph(vertex_attrs={'id': ['spam', 'eggs', 'ham']}, edges=[(1,0), (1,2)]) (I haven't actually tried this in Python, because I am having a hard time installing python-igraph. But it works fine from R and they...

Calculating transitivity for a specified vertex ids from the list of ego-networks in igraph

r,igraph,sna

Here is the solution, provided by my colleague Benjamin Lind: all_files <- list.files("./edgelists") # reading file names datanames <- strsplit(all_files, split = "\\.") # removing file extension datanames <- sapply(datanames, "[[", 1) # getting names of egos # Helper function to load data fun1 <- function(x){ pathname <- paste("./edgelists/", x,...

iGraph histogram object

python,r,ggplot2,igraph

list(h.bins()) gives you a list of tuples where each tuple contains the left and right bound of a histogram bin and the number of items in that bin. You can then probably write this into a file and read it from R.

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

r,geolocation,igraph,network-analysis

One element of the solution is no doubt the rescale = FALSE parameter to igraph::plot() as I suggested in comment. OP asked why ey gets an empty plot with this? It's because the plotting area is still limited to the [-1; 1] interval along both x and y axes. This...

visualizing clr network in cytoscape

r,graph,nodes,igraph,edges

You have adjacency matrix in which row.names and col names are your genes. Then you should convert this matrix file to an edge list file: graph_adj=as.data.frame(as.table(as.matrix(net))) write.table(graph_adj, "graph_adj.txt", sep="\t") Now you can open the file in excel, edit it and finally import to cytoscape....

How to get the HITS function in R tool?

r,matrix,igraph

You probably have the sparsematrices option TRUE. Explicitly set it to sparse=FALSE while calling get.adjacency to get a full matrix instead of a sparse matrix. > t(get.adjacency(G, sparse=F)) [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0 1 0 0 0 0 [2,] 1 0 1 0 1 0 [3,] 1...

Get a vector of all edges ids

c++,igraph

igraph's edge IDs are always consecutive integers from zero to igraph_ecount(graph)-1 (inclusive), so you can simply generate a random integer from this range to draw a random edge from the graph. Quoting the igraph manual: The igraph graphs are multisets of ordered (if directed) or unordered (if undirected) labeled pairs....