igraph

Count how many vertices in a vertex's neighbourhood have an attribute in igraph for R

最后都变了- 提交于 2020-01-15 10:39:28
问题 I have a large graph (several, actually) in igraph—on the order of 100,000 vertices—and each vertex has an attribute which is either true or false . For each vertex, I would like to count how many of the vertices directly connected to it have the attribute. My current solution is the following function, which takes as its argument a graph. attrcount <- function(g) { nb <- neighborhood(g,order=1) return(sapply(nb,function(x) {sum(V(g)$attr[x]})) } This returns a vector of counts which is off

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

二次信任 提交于 2020-01-15 03:47:05
问题 For each edge in a graph I would like to add an numeric attribute (weight) that is the product of an attribute (probability) of the incident vertices. I can do it by looping over the edges; that is: for (i in E(G)) { ind <- V(G)[inc(i)] p <- get.vertex.attribute(G, name = "prob", index=ind) E(G)[i]$weight <- prod(p) } However, this is qute slow for my graph (|V| ~= 20,000 and |E| ~= 200,000). Is there a faster way to do this operation? 回答1: Here is probably the fastest solution. The key is to

Find shortest path from X,Y coordinates (with start ≠ end)

别来无恙 提交于 2020-01-14 03:17:32
问题 I have a dataframe with X and Y coordinates of points like this: structure(list(X = c(666L, 779L, 176L, 272L, 232L, 74L, 928L, 667L, 1126L, 919L), Y = c(807, 518, 724, 221, 182, 807, 604, 384, 142, 728)), .Names = c("X", "Y"), row.names = c(NA, 10L), class = "data.frame") I just want to find out the shortest path connecting all these points, and also return its total distance. There are no other conditions: every point can be connected to any other, no specific point to start or end, no

Mapping a specific column of values to the scale color of vertexs in R

主宰稳场 提交于 2020-01-14 03:06:06
问题 Now I have a data frame df1 : v1 v2 a 10 b 1 c 3 d 7 ....... And another data frame df2 : v1 v2 d a c a b c c d ... I'd like to plot a network based on df2 with igraph : plot(g, layout = layout_in_circle(g)) And the color of vertexes( a,b,c,d... ) should be in range of red to blue and the bigger the value in v2, the color of that vertex should be more closer to red. I have tried: require(igraph) g = graph.data.frame(df) plot(g, layout = layout_in_circle(g), vertex.color = color.scale(mention

Modularity calculation for weighted graphs in igraph

不打扰是莪最后的温柔 提交于 2020-01-13 13:50:11
问题 I used the fastgreedy algorithm in igraph for my community detection in a weighted, undirected graph. Afterwards I wanted to have a look at the modularity and I got different values for different methods and I am wondering why. I included a short example, which demonstrates my problem: library(igraph) d<-matrix(c(1, 0.2, 0.3, 0.9, 0.9, 0.2, 1, 0.6, 0.4, 0.5, 0.3, 0.6, 1, 0.1, 0.8, 0.9, 0.4, 0.1, 1, 0.5, 0.9, 0.5, 0.8, 0.5, 1), byrow=T, nrow=5) g<-graph.adjacency(d, weighted=T, mode="lower"

Modularity calculation for weighted graphs in igraph

核能气质少年 提交于 2020-01-13 13:49:32
问题 I used the fastgreedy algorithm in igraph for my community detection in a weighted, undirected graph. Afterwards I wanted to have a look at the modularity and I got different values for different methods and I am wondering why. I included a short example, which demonstrates my problem: library(igraph) d<-matrix(c(1, 0.2, 0.3, 0.9, 0.9, 0.2, 1, 0.6, 0.4, 0.5, 0.3, 0.6, 1, 0.1, 0.8, 0.9, 0.4, 0.1, 1, 0.5, 0.9, 0.5, 0.8, 0.5, 1), byrow=T, nrow=5) g<-graph.adjacency(d, weighted=T, mode="lower"

How to set edge colors and vertex spacing with R / igraph

喜欢而已 提交于 2020-01-13 11:53:12
问题 I am new to R and trying to figure out how to make a social network map of a system that I have data for. I have managed to figure out most of what I want to do from the FAQ and tutorials, but I am stuck on two things. How do I make the canvas larger / the graph more spaced out? Right now it's way too squashed. At the moment the edge thickness is set based on the weight. The weights represent different statuses (8 = Active, 3 = Requested, 2 = Hidden, 1 = Blocked) and I would like to style the

assign multiple color to each vertex in igraph

元气小坏坏 提交于 2020-01-13 05:36:18
问题 I have a dataframe d : d<-structure(list(V1 = c(1L, 3L, 3L, 2L, 1L, 1L, 7L, 9L, 10L, 9L, 7L), V2 = c(2L, 4L, 5L, 5L, 4L, 6L, 8L, 3L, 1L, 8L, 5L)), .Names = c("V1", "V2"), class ="data.frame", row.names = c(NA, -11L)) g<-graph.data.frame(d,directed = F) I would assign to each vertex one or more colors depending on its affiliation variable given in a dataframe m m<-structure(list(vertex = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 9L, 9L, 10L, 1L, 1L, 6L, 6L), affilation = c(1L, 1L, 1L, 2L, 2L, 1L,

assign multiple color to each vertex in igraph

那年仲夏 提交于 2020-01-13 05:36:09
问题 I have a dataframe d : d<-structure(list(V1 = c(1L, 3L, 3L, 2L, 1L, 1L, 7L, 9L, 10L, 9L, 7L), V2 = c(2L, 4L, 5L, 5L, 4L, 6L, 8L, 3L, 1L, 8L, 5L)), .Names = c("V1", "V2"), class ="data.frame", row.names = c(NA, -11L)) g<-graph.data.frame(d,directed = F) I would assign to each vertex one or more colors depending on its affiliation variable given in a dataframe m m<-structure(list(vertex = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 9L, 9L, 10L, 1L, 1L, 6L, 6L), affilation = c(1L, 1L, 1L, 2L, 2L, 1L,

How to identify fully connected node clusters with igraph?

拟墨画扇 提交于 2020-01-12 08:21:54
问题 I'm trying to calculate the clusters of a network using igraph in R, where all nodes are connected. The plot seems to work OK, but then I'm not able to return the correct groupings from my clusters. In this example, the plot shows 4 main clusters, but in the largest cluster, not all nodes are connected: I would like to be able to return the following list of clusters from this graph object: [[1]] [1] 8 9 [[2]] [1] 7 10 [[3]] [1] 4 6 11 [[4]] [1] 2 3 5 [[5]] [1] 1 3 5 12 Example code: library