igraph

R igraph ancestors python

ε祈祈猫儿з 提交于 2019-12-11 06:38:43
问题 I have a network like in the diagram. In python there is the ancestors function. When i use it on node 5, it will provide list of nodes 1,2 and 3. what is an equivalent function in igraph R? I tried subcomponent but it didn't work for me. Also my actual network is quiet long and I don't want to use parent or child function as I don't know degree in every case 回答1: The R function is neighborhood with mode="in" : http://igraph.org/r/doc/neighborhood.html E.g. g1 <- graph(c(1,4, 1,2, 1,3, 3,2, 2

igraph, POSIX, and data.table

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 06:27:29
问题 In an earlier question, I learned that graphs are useful to collapse these data require(data.table) set.seed(333) t <- data.table(old=1002:2001, dif=sample(1:10,1000, replace=TRUE)) t$new <- t$old + t$dif; t$foo <- rnorm(1000); t$dif <- NULL > head(t) old new foo 1: 1002 1007 -0.7889534 2: 1003 1004 0.3901869 3: 1004 1014 0.7907947 4: 1005 1011 2.0964612 5: 1006 1007 1.1834171 6: 1007 1015 1.1397910 to obtain only those rows such that new[i] = old[i-1] . The result could then be joined into a

Count the nodes with most connection in a network in R igraph

泪湿孤枕 提交于 2019-12-11 05:58:06
问题 I want to count the number nodes with more received connections in a unidirectional network. For example in a network like this: g <- graph( c('A',1,'A',2,'A',3,'B',4,'B',5,'B',6,'C',7,'C',8,'D',7,'D',8)) We would have 3 independent components Loading the data in a file (test), I can upload it and represent it as follows: plot(g) How can I get the destination nodes with more connections? In this case will be node 7 and 8. Following another question (r igraph most connected nodes) I tried the

Freely placing vertex labels outside of vertices for a circle graph in R

ぐ巨炮叔叔 提交于 2019-12-11 05:53:02
问题 I'm currently trying to display a circle graph in R with the ability to place the labels of each node right next to, but outside of, the node itself. I looked at a few answers, and tried one which suggested that I specify locations given in radians for each node itself via: radian.rescale <- function(x, start=0, direction=1) { c.rotate <- function(x) (x + start) %% (2 * pi) * direction c.rotate(scales::rescale(x, c(0, 2 * pi), range(x))) } lab.locs <- radian.rescale(x=1:n, direction=-1, start

How to find the neighborhood for certain vertices only?

北城余情 提交于 2019-12-11 04:57:19
问题 The question was started here. I have an undirected graph g with n<100 vertices. The graph is simple. The coordinates of all vertices are integer (x_i, y_i), i=1, 2,..., n , the set of edges is predefinded, they are line segments with the length 1 unit. The degree of vertices can be 2 , 3 or 4 . library(igraph) g <- graph_from_literal(1-2-3-4-5-6-7-8-1, 8-9-4) B <- t(matrix(c(0,0, 0,1, 0,2, -1,2, -2,2, -2,1, -2,0, -1,0, -1,1), nrow =2)); V(g)$id <- seq_len(vcount(g)) V(g)$x <- B[,1]; V(g)$y <

choosing nodes color according to their name

主宰稳场 提交于 2019-12-11 04:56:03
问题 I have many igraph objects representing connections among member of different groups. A simple example of my graph data sets is like as follows: library(igraph) m<-matrix(data = c("a1_ghj", "a1_phj", "b2_ghj", "c1_pht", "c1_ght", "a1_ghi", "g5_pht", "d2_phj", "r5_phj", "u6_pht"), ncol = 2) )) g<-graph_from_edgelist(m) g In the first case, I want to plot this graph regarding that each vertex name that have similar characters after the _ it means that they are in a same group and they should

read a graph by vertices not as an edge list in R

爱⌒轻易说出口 提交于 2019-12-11 04:47:46
问题 To explain: I have an undirected graph stored in a text file as edges where each line consist of two values represent an edge, like: 5 10 1000 2 212 420 . . . Normally when reading a graph in R from a file (using igraph ), it will be read as edges so to call the edges of the graph "g" we write E(g) and to call the vertices of "g" we write V(g) and to call both vertices of a certain edge (i.e to call a certain edge (edge i)) we write E(g)[i] . My question: Is there a similar way to call one

Colour specific node in igraph

感情迁移 提交于 2019-12-11 04:39:01
问题 I am trying to colour node 6 and 7 regardless of whatever letter is selected from object 'd'. g <- graph_from_literal(1:2:3:4:5 -- 6:7) # Rename (sum up all the vertices) d <- c("a", "b", "c", "d", "e", "f", "g","h", "i", "j") V(g)$name <- sample(d, 7, replace=TRUE) colours <- c("red") V(g)$color <- ifelse(V(g)$name == c('a','e'), "white", colours) plot.igraph(g, layout=layout_with_dh, vertex.label=V(g)$name, vertex.size=35, vertex.color=V(g)$color, #colors.r vertex.label.cex=0.7, ) I tried

Obtain weight of a path with iGraph in R

為{幸葍}努か 提交于 2019-12-11 04:14:13
问题 I have a graph I created from a data frame, in the form of from, to, cost columns. I also have a path (as a succession of vertexes, in the vpath format of igraph ) which is valid (my graph is directed). Is there any function that, given my graph and my path, would give me the cost of that path? I'm not asking for the shortest path, as I obtained the path from all_shortest_paths . However, I only get the node succession and not the weight of the path, which I also need. Edit: Data This is my

Cannot add edges, Invalid vertex ID in IGraph

血红的双手。 提交于 2019-12-11 03:54:59
问题 I was trying to write the code in python using igraph and when i tried to add edges using a while loop this error came up while(i<k) g.add_vertices(theInts[i]) i=i+1 g.add_edges([(theInts[i-1],theInts[i])]) I thought that indexing might be a problem so i also included a if statement but that doesnt seems to be the problem. Please Help!!! 回答1: I think this all depends on what g has for vertices. If you start off with an empty g , you only have the vertex 0 , so if you're trying to call add