igraph

R color vertex igraph

自闭症网瘾萝莉.ら 提交于 2019-12-02 07:43:10
I have a database with all the users and their roles, i've made a table that has usera, role, userb. i'm trying to give each user a color based on their team. the SQL code below can be used to create a similar dataset select concat('H',ABS(Checksum(NewID()) % 999999)) acentralacc, CONCAT('Role_',CHAR( FLOOR(65 + (RAND() * 25))))role,concat('H',ABS(Checksum(NewID()) % 999999))bcentralacc select concat('H',ABS(Checksum(NewID()) % 999999)) centralaccountname, CONCAT('Team_',CHAR( FLOOR(65 + (RAND() * 25))))team ' #get library's install.packages("igraph") library("igraph") #edges (connection

Cumulative value of an edge or node attribute while descending an igraph object

点点圈 提交于 2019-12-02 06:51:23
I have an igraph object g made from dataframe df : df <- data.frame(c(0,1,2,2,4), c(1,2,3,4,5), c(0.01, 0.03, 0.05, 0.01, 0.02)) colnames(df) <- c('parent_id', 'id', 'dt') g <- graph_from_data_frame(df) Edges are made between parent_id and id . > g IGRAPH DN-- 6 5 -- + attr: name (v/c), dt (e/n) + edges (vertex names): [1] 0->1 1->2 2->3 2->4 4->5 Change in thickness dt is the edge attribute. This can be thought of as the change in thickness between a 'parent' and 'child' iceberg (this is my problem/project). list.edge.attributes(g) [1] "dt" to visualize: plot(g, edge.label=E(g)$dt) Example of

Plot a tree-like graph with root node at the top

自闭症网瘾萝莉.ら 提交于 2019-12-02 06:46:02
问题 I have the following toy graph that represents, for instance, a forum thread: import igraph as ig g = ig.Graph(n = 12, directed=True) g.add_edges([(1,0),(2,1), (3,2), (4,3), (5,1), (6,2), (7,6), (8,7), (9,0), (10,0), (11,10)]) g.vs["label"] = ["A", "B", "A", "B", "C", "F", "C", "B", "D", "C", "D", "F"] ig.plot(g, layout="kk") However, there seems to be no layout that places the root vertex (id 0, label A) into the top and grows downwards. Am I missing something? 回答1: OK, I'll just add this as

How to assign edge weights to certain edges in R igraph

萝らか妹 提交于 2019-12-02 05:52:19
问题 I'd like to assign a small, non-negative edge weights to certain edges used in a shortest path. Here is an example graph: library(igraph) data <- read.table(text=" 1 2 1 4 1 5 2 3 2 4 3 4 5 7 5 8 3 6", header=FALSE) gmatrix <- data.matrix(data, rownames.force = NA) #convert into a matrix to use in igraph g <- graph_from_edgelist(gmatrix, directed = FALSE) If I find the shortest path between node 1 and node 3, the edges used are 1-2 and 1-3. get.shortest.paths(g, 1,3) $vpath $vpath[[1]] + 3/9

R is not taking the parameter hgap in layout_with_sugiyama

妖精的绣舞 提交于 2019-12-02 04:30:31
I'm working on R on a graph and I'd like to have a hierarchical plot, based on the values in the vector S (a value for each node). lay2 <- layout_with_sugiyama(grafo, attributes="all", layers = S, hgap=10, vgap=10) plot(lay2$extd_graph, vertex.label.cex=0.5) However, the paramaters hgap e vgap are not taken and the graph is really confused (even because I've got 162 nodes). I'm doing something wrong or there is another way in which I can do a hierarchical graph? I believe that layout_with_sugiyama is working just fine, but you may be misinterpreting the output. Since you do not provide any

How to get the a list of the edge attributes when performing shortest.paths in igraph (R)

只谈情不闲聊 提交于 2019-12-02 03:06:29
问题 I need to calculate the product of the edges attributes of the shortest path between two vertices in my graph. For example: data<-as.data.frame(cbind(c(1,2,3,4,5,1),c(4,3,4,5,6,5),c(0.2,0.1,0.5,0.7,0.8,0.2))) G<-graph.data.frame(data, directed=FALSE) set.edge.attribute(G, "V3", index=E(G), data$V3) If I calculate the shortest path according to the attribute I have two posibilities, the first tell me the steps: get.shortest.paths (G, 2, 6, weights=E(G)$V3) 2 3 4 1 5 6 The second tell me the

Plot a tree-like graph with root node at the top

荒凉一梦 提交于 2019-12-02 01:19:24
I have the following toy graph that represents, for instance, a forum thread: import igraph as ig g = ig.Graph(n = 12, directed=True) g.add_edges([(1,0),(2,1), (3,2), (4,3), (5,1), (6,2), (7,6), (8,7), (9,0), (10,0), (11,10)]) g.vs["label"] = ["A", "B", "A", "B", "C", "F", "C", "B", "D", "C", "D", "F"] ig.plot(g, layout="kk") However, there seems to be no layout that places the root vertex (id 0, label A) into the top and grows downwards. Am I missing something? OK, I'll just add this as an answer, for the comments. So the Reingold-Tilford layout works: http://igraph.sourceforge.net/doc/python

Package igraph0 deprecated and hence not able to access gspan package

北战南征 提交于 2019-12-02 01:18:03
问题 Hi am trying some examples from the book: Practical Graph mining with R for subgraph mining: library(subgraphMining) library(igraph) graph1 = graph.ring(5) graph2 = graph.ring(6) database <- array(dim=2) database[1] <- list(graph1) database[2] <- list(graph2) result <- gspan(database, support= "80%") Getting the following error: Error in library(igraph0) : there is no package called ‘igraph0’ This is probably because igraph0 is deprecated. So, do we need to tweak the functions in the

forceNetwork is not zero indexed

混江龙づ霸主 提交于 2019-12-02 00:12:20
I am trying to create a simple forceNetwork , but the plot won't render. I keep getting the following warning: Warning message: It looks like Source/Target is not zero-indexed. This is required in JavaScript and so your plot may not render. How do I fix this? Note that simpleNetwork works fine so the problem seems to be in how I am specifying my data. library(igraph) library(networkD3) set.seed(42) temp<-data.frame(source=c(1,2,3,4),target=c(2,3,4,4))#csv[1:500,] links<-data.frame(source=temp$source,target=temp$target) g<-graph.data.frame(cbind(temp$source,temp$target), directed=T) nodes<-data

Draw network and grouped vertices of the same community or partition

杀马特。学长 韩版系。学妹 提交于 2019-12-01 23:36:11
问题 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