igraph

using graph.adjacency() in R

◇◆丶佛笑我妖孽 提交于 2019-11-30 07:30:08
问题 I have a sample code in R as follows: library(igraph) rm(list=ls()) dat=read.csv(file.choose(),header=TRUE,row.names=1,check.names=T) # read .csv file m=as.matrix(dat) net=graph.adjacency(adjmatrix=m,mode="undirected",weighted=TRUE,diag=FALSE) where I used csv file as input which contain following data: 23732 23778 23824 23871 58009 58098 58256 23732 0 8 0 1 0 10 0 23778 8 0 1 15 0 1 0 23824 0 1 0 0 0 0 0 23871 1 15 0 0 1 5 0 58009 0 0 0 1 0 7 0 58098 10 1 0 5 7 0 1 58256 0 0 0 0 0 1 0 After

How to find measures after community detection in igraph (R)?

馋奶兔 提交于 2019-11-30 04:25:43
I am working with Community Detection in graphs. I have been through the different community detection algorithms implemented in igraph and plotting the community structures. Now after getting the communities object for different algorithms, I want to compare the algorithms based on different measures like density,cut ratio, coverage. (I know that modularity is already implemented). I can obtain a subgraph and then calculate the intra-cluster density but to find the inter-cluster density, I dont not know how to proceed. This is the code I have been using to find intra-cluster density: karate <

increasing the distance between igraph nodes

社会主义新天地 提交于 2019-11-30 02:14:15
问题 I have a graph that I have produced using igraph. I'd like to spread out the nodes. The only way I have found so far to do this is to scale the layout and force the plot command to not rescale. png("kmeansColouredNetwork.png", width=1200,height = 1000) col=c("yellow", "saddlebrown", "brown1","chartreuse2", "chocolate1","darkorange" ,"deepskyblue1", "hotpink1","plum2") for(i in 1:9){ V(graph)$cluster[which(V(graph)$name %in% kmeans[,i])]<-col[i] } V(graph)$color=V(graph)$cluster coords <-

igraph Graph from numpy or pandas adjacency matrix

余生长醉 提交于 2019-11-30 00:16:57
I have an adjacency matrix stored as a pandas.DataFrame : node_names = ['A', 'B', 'C'] a = pd.DataFrame([[1,2,3],[3,1,1],[4,0,2]], index=node_names, columns=node_names) a_numpy = a.as_matrix() I'd like to create an igraph.Graph from either the pandas or the numpy adjacency matrices. In an ideal world the nodes would be named as expected. Is this possible? The tutorial seems to be silent on the issue. In igraph you can use igraph.Graph.Adjacency to create a graph from an adjacency matrix without having to use zip . There are some things to be aware of when a weighted adjacency matrix is used

Plot tree with graph.tree function from igraph

拟墨画扇 提交于 2019-11-29 21:15:32
问题 In the docs of igraph package there is an example igraph.options(plot.layout=layout.reingold.tilford) plot(graph.tree(20, 2)) the output should represent data as a tree. But what I get is 回答1: You apparently need to specify the root: library(igraph) g <- graph.tree(20, 2) plot(g, layout = layout.reingold.tilford(g, root=1)) 来源: https://stackoverflow.com/questions/18270370/plot-tree-with-graph-tree-function-from-igraph

igraph: why is add_edge function so slow ompared to add_edges?

给你一囗甜甜゛ 提交于 2019-11-29 20:04:10
问题 i am surprised that: import igraph import random, time start_time = time.time() G = igraph.Graph(directed = True) G.add_vertices(10000) for i in range(30000): G.add_edge(random.randint(0,9999), random.randint(0,9999)) print "done in " + str(int(time.time() - start_time)) + " seconds" returns done in 63 seconds while import igraph import random, time start_time = time.time() G = igraph.Graph(directed = True) G.add_vertices(10000) edges = [] for i in range(30000): edges += [(random.randint(0

igraph - Neighbors as subgraph - make_ego_graph() as single graph

﹥>﹥吖頭↗ 提交于 2019-11-29 19:05:16
问题 I'd like to construct a subgraph of a graph of a directed network with all the vertices sharing a certain vertex attribute (say, V(Grph)$year == "1952") and their first-order (immediate) neighbors, based only on the out-degree. I've tried ego() , make_ego_graph() , neighbors() , and adjacent_vertices() . For instance, CitGraph <- make_ego_graph(Grph, 1, nodes = which(V(Grph)$year=="1952"), mode = "out") yields a list of graphs (and not a single comprehensive one) and surprisingly takes two

Union of igraph objects loses attributes

风格不统一 提交于 2019-11-29 15:54:06
I have two igraph objects, which have different color attributes. Vertices "A" and "B" in first graph are colored red. Vertices "AA" and "BB" in second graph are colored green. After joining the two, the different colors are lost. library(igraph) graph.1= graph.data.frame(data.frame(start=c("a", "b"), end=c("A", "B"))) V(graph.1)[name%in% c("A", "B")]$color= "red" graph.2= graph.data.frame(data.frame(start=c("a", "b"), end=c("AA", "BB"))) V(graph.2)[name%in% c("AA", "BB")]$color= "green" graph= graph.union.by.name(graph.1, graph.2) plot(graph) How can I preserve the distinct colors when

How to fix nodes when plotting a subset over a complete network using igraph R

房东的猫 提交于 2019-11-29 14:45:28
I have a problem concerning network visualization using the igraph package provided in R. Assume that you have a certain network, which contains the total sample of nodes and edges. Let me name this network netX: netX <- structure(c(1, 0.48275862, 0.51724138, 0.48275862, 0.27906977, 0.06896552, 0.34482759, 0.32352941, 0.06896552, 0.34482759, 0.03448276, 0.06896552, 0.20689655, 0.17241379, 0.17241379, 0, 0.23333333, 0.27586207, 0.21621622, 0.24137931, 0.48275862, 1, 0.4137931, 0.35714286, 0.25581395, 0.25, 0.25, 0.38235294, 0.07142857, 0.28571429, 0.21428571, 0.28571429, 0.10714286, 0.07142857,

R reciprocal edges in igraph in R

瘦欲@ 提交于 2019-11-29 14:31:47
I am working with graphs in R. I am currently using igraph and I would like to be able to plot bidirectional edges "reciprocal edges" of a graph. So far I've seen it is possible to plot "bidirectional" graphs but not reciprocal edges, for example: E(1,3) and E(3,1) could potentially be represented as a bidirectional edge <-->, but instead I would like to plot two parallel edges one pointing to the opposite direction of the other || . There exist in Rgraphviz an option when plotting "plot(rEG, recipEdges = "distinct")" that makes this, but I like more how plots look like on igraph. Thanks in