igraph

Can i change the colour of edges containing specific vertices in IGraph-Python

China☆狼群 提交于 2019-12-11 08:24:49
问题 I have created a directed graph and through a program i am finding out all the cycles it contains. After creating the graph i want to change the colour of the edges which contain the vertices involved in the cycle. I am using python igraph. Please Help 回答1: Something like this: vertex_set = set(vertices_in_cycle) g.es["color"] = "black" red_edges = g.es.select(_source_in=vertex_set, _target_in=vertex_set) red_edges["color"] = "red" Explanation: g.es represents the set of all edges in the

R: igraph, matching members of a “known” cluster to members of observed clusters returning a %match

霸气de小男生 提交于 2019-12-11 08:19:18
问题 I'm using the Walktrap community detection method to return a number (19 in this case) of clusters. I have a list of members which belong to one or more of these clusters. I need a method to search each cluster for the presence of the members and return the percentage of matches found. ( e.g cluster[0] = 0%, cluster[1] =Y%.....cluster[18]=Z%) Thus selecting the optimum cluster that represents the members on the list. Once the optimum cluster is found, I need a method to count the number of

issues with R “igraph” package neighbor function

≯℡__Kan透↙ 提交于 2019-12-11 08:18:52
问题 I started using the R "igraph" package recently(version 0.7). I wrote a simple program to understand the basics of the package(reading data into the graph object, getting the neighbours of a node). I am using a graph whose vertices start at 0 . The edges in the graph are populated as I need it, however when I attempt to get the adjacency list/ neighbours of a node, I observed it was not giving the result that I expected. Can someone help me out with this/ or point out if I am missing

Find spanning tree using bfs in igraph

a 夏天 提交于 2019-12-11 07:56:32
问题 I would like to find a spanning tree in a graph using igraph function graph.bfs . Could you show me how? PS: I try to use the $father info of the returned value from graph.bfs , but the result confuses me. Here is an example: g <- graph(c(1,2,2,6,1,4,4,6,5,6,1,5,5,3,3,4), directed=FALSE) plot(g) tmp <- graph.bfs(g, root=1, neimode='all', order=TRUE, father=TRUE,callback=f) The result is : tmp$order = 1 2 4 5 6 3 and tmp$father=0 1 4 1 1 2 Can I use the $father info to find all the spanning

Find unique set of identifiers/groups among several columns

≯℡__Kan透↙ 提交于 2019-12-11 07:49:11
问题 I have data with two (potentially more) columns of identifiers (typically long strings). These differ sometimes, are mistyped, or change over time. I want to identify unique subjects in the data. This requires identifying groups of cases which are connected via their ids at some level. An example df <- data.frame(ida = c("A", "B", "C", "C", "D", "E"), idb = c(1, 1, 3, 4, 4, 7), trueid = c("id1", "id1", "id2", "id2", "id2", "id3")) > df ida idb trueid 1 A 1 id1 2 B 1 id1 3 C 3 id2 4 C 4 id2 5

how to check if there exists a unique shortest path between two vertices in igraph

时光毁灭记忆、已成空白 提交于 2019-12-11 07:47:38
问题 I'd like to identify if there exist a unique shortest path or multiple shortest paths between two vertices with igraph. If I use length(all_shortest_paths(g, i,j) , that actually helps me, but I feel like there are so many redundant operations. I rather prefer first to get one shortest path with get.shortest.paths(g, i,j) , and then see if there is another. However, I could not figure out how to do this. Can someone help me how to identify whether there is another shortest path different than

lapply function to look up neighbors in igraph (when not all nodes are found)

佐手、 提交于 2019-12-11 07:39:28
问题 I am trying to create a data set of network neighbors for a list of nodes. I though I could do this with an lapply function where I use the neighbors command. As an added complication, some of my lookup nodes aren't in the graph, but I can't get it to work regardless. Here is an example: edgelist <- read.table(text = " A B B C C D D E C F F G") testlist <- read.table(text = " A H C D J") testlist2 <- read.table(text = " A C B D E") library(igraph) graph <- graph.data.frame(edgelist) str(graph

iGraph + Plotly creates random connections

你说的曾经没有我的故事 提交于 2019-12-11 07:36:26
问题 I'm trying to use the example code here for doing iGraph network graphs in plotly and shoehorn in my own data.frames instead of using the example karate club data. When the graph is plotted, it seems to ignore the edge list and a bunch of random connections are being made. I think either the labels or edges are wrong but I can't tell. library(igraph) library(plotly) setwd('C:/Users/Andrew Riffle/Documents/MEGAsync/code/R/link_analysis') ID <- c(1:50) nodes <- data.frame(ID) Source <- c(23, 24

PNG images as vertices in R (igraph) [duplicate]

泄露秘密 提交于 2019-12-11 07:14:38
问题 This question already has answers here : R: Creating graphs where the nodes are images (2 answers) Closed 5 years ago . [R help] Hello, is there any way to use png images as vertices in R? Specifically while still using the igraph package? For example I have some PNG images 1.png 2.png 3.png Can I replace certain vertices with 1.png, others with 2.png, and the rest with 3.png? 回答1: This is simple with the new raster vertex shape: library(png) library(igraph) # To get an image to plot

igraph get ids of connected components

别等时光非礼了梦想. 提交于 2019-12-11 07:04:03
问题 How can I access the ids of the top3 connected components of a graph in igraph ? c <- igraph::components(g, mode = 'weak') which(c$membership == which.max(c$csize)) will give the largest and which(c$membership == which.max(c$csize-1)) the same result as c$csize-1 will just subtract -1 from all values. 回答1: You can use order to sort and find out the memberships of the top 3 largest clusters and use %in% to check if vertices are within one of them: which(c$membership %in% order(c$csize,