igraph

Draw network and grouped vertices of the same community or partition

混江龙づ霸主 提交于 2019-12-01 20:47:00
I need view (drawn or plot) the communities structure in networks I have this: import igraph from random import randint def _plot(g, membership=None): layout = g.layout("kk") visual_style = {} visual_style["edge_color"] = "gray" visual_style["vertex_size"] = 30 visual_style["layout"] = layout visual_style["bbox"] = (1024, 768) visual_style["margin"] = 40 for vertex in g.vs(): vertex["label"] = vertex.index if membership is not None: colors = [] for i in range(0, max(membership)+1): colors.append('%06X' % randint(0, 0xFFFFFF)) for vertex in g.vs(): vertex["color"] = str('#') + colors[membership

All paths in directed tree graph from root to leaves in igraph R

╄→尐↘猪︶ㄣ 提交于 2019-12-01 17:06:16
Given is a tree: library(igraph) # setup graph g= graph.formula(A -+ B, A -+ C, B -+ C, B -+ D, B -+ E ) plot(g, layout = layout.reingold.tilford(g, root="A")) Vertex "A" is the root of the tree, while vertices "C", "D", "E" are considered as terminal leaves. Problem: The task is to find all paths between root and leaves. I fail with following code, as it only provides the shortest paths: # find root and leaves leaves= which(degree(g, v = V(g), mode = "out")==0, useNames = T) root= which(degree(g, v = V(g), mode = "in")==0, useNames = T) # find all paths paths= lapply(root, function(x) get.all

how to convert list of “vertex sequence” to a vector

一世执手 提交于 2019-12-01 16:32:07
I am using Igraph package in R and when I am accessing the list of vertices names through V(graph), I am getting the following result: Vertex sequence: [1] "d66cp96igcdnt25brjeics9d11" "bovlonq25tmuaiak6do92v9cj0" "simj1u4714pa07p38vhstusf36" "6t6tnkoh4ftbgt787pvpmp1323" [5] "mf987tcmm8u8j3pdo4cts6jml3" The problem that I need a vectors of these names, but this is structure(1:20, class = "igraph.vs", env = <environment>) my ideas to transform it with as.vector(), as.factor did not yield a result. Is there a way how to convert it to a vector of strings? .... Ok, I found a way out: V(graph)$name

All paths in directed tree graph from root to leaves in igraph R

天大地大妈咪最大 提交于 2019-12-01 16:23:59
问题 Given is a tree: library(igraph) # setup graph g= graph.formula(A -+ B, A -+ C, B -+ C, B -+ D, B -+ E ) plot(g, layout = layout.reingold.tilford(g, root="A")) Vertex "A" is the root of the tree, while vertices "C", "D", "E" are considered as terminal leaves. Problem: The task is to find all paths between root and leaves. I fail with following code, as it only provides the shortest paths: # find root and leaves leaves= which(degree(g, v = V(g), mode = "out")==0, useNames = T) root= which

how to convert list of “vertex sequence” to a vector

狂风中的少年 提交于 2019-12-01 15:27:36
问题 I am using Igraph package in R and when I am accessing the list of vertices names through V(graph), I am getting the following result: Vertex sequence: [1] "d66cp96igcdnt25brjeics9d11" "bovlonq25tmuaiak6do92v9cj0" "simj1u4714pa07p38vhstusf36" "6t6tnkoh4ftbgt787pvpmp1323" [5] "mf987tcmm8u8j3pdo4cts6jml3" The problem that I need a vectors of these names, but this is structure(1:20, class = "igraph.vs", env = <environment>) my ideas to transform it with as.vector(), as.factor did not yield a

How to overlay and position a logo over any R plot (igraph, ggplot2, etc) so I can put branding on it automatically?

六月ゝ 毕业季﹏ 提交于 2019-12-01 14:27:10
I am wondering if there is a generic way to overlay any R plot / visualization appearing in the R output window with a logo (as well as position it) so output is always branded? I read this post where they use a stripe banner as part of ggplot, but is there more of a generic way of doing this so I can include it in any output to automatically put the appropriate branding in particular location (realizing it will likely have to be adjusted, but at least so it is always there) so I cna have it be part of say the 'default code template' so whether I or my colleague use generic plot, igraph,

How to overlay and position a logo over any R plot (igraph, ggplot2, etc) so I can put branding on it automatically?

心已入冬 提交于 2019-12-01 13:52:40
问题 I am wondering if there is a generic way to overlay any R plot / visualization appearing in the R output window with a logo (as well as position it) so output is always branded? I read this post where they use a stripe banner as part of ggplot, but is there more of a generic way of doing this so I can include it in any output to automatically put the appropriate branding in particular location (realizing it will likely have to be adjusted, but at least so it is always there) so I cna have it

Loading neo4j query result into python's `igraph` graph

你离开我真会死。 提交于 2019-12-01 13:24:24
How would you load the results of a Cypher query into an igraph in python, keeping all the edge and vertex attributes? This is easy with py2neo and igraph's Graph.TupleList method. You'll need both py2neo and igraph installed. pip install py2neo pip install python-igraph Both of these packages rely on a Graph class so we should alias them as something else on import. from py2neo import Graph as pGraph from igraph import Graph as iGraph First, connect to Neo4j with py2neo's Graph object. neo4j = pGraph() Then write a Cypher query to return an edgelist. Let's say we have the example movie

Building R igraph package in Win7

落爺英雄遲暮 提交于 2019-12-01 12:32:46
I made a small change to the source code of the igraph package because I want to implement the forest fire method based on the breadth first search method . I used Rtools to build the package and followed the steps as this link . But, I got a error message: foreign-graphml.c:38:29: fatal error: libxml/encoding.h: No such file or directory. I tested using the source code, but still had the same error. I also used the install.packages() method. It still showed the same error. Update: I downloaded the Libxml2 and set the bin location to the path. The libxml/encoding.h file is actually in the

Find total of second variable related to the distance of route from get.shortest.paths()

亡梦爱人 提交于 2019-12-01 12:17:41
I found the following question ( Find distance of route from get.shortest.paths() ) very helpful, but would like to take it one step further. I have added one column to the data frame and I would like to get the "total distance" related to the min newcost path. Below the igraph / R code that I used. df2 = rbind(c(234,235,21.6,75), c(234,326,11.0,35), c(235,241,14.5,78), c(326,241,8.2,98), c(241,245,15.3,75), c(234,245,38.46,65)) df2 = as.data.frame(df2) names(df2) = c("start_id","end_id","newcost","distance") df2 require(igraph) g2 <- graph.data.frame(df2, directed=FALSE) tkplot(g2) (tmp2 =