igraph

How can I rearrange the order of edges in an igraph plot?

感情迁移 提交于 2020-03-01 06:48:29
问题 I'm trying to make a network plot in igraph that highlights certain important edges by coloring them differently than the others. For large graphs, they often get buried under the others. For example: library(igraph) test <- barabasi.game(200,m=2) E(test)$color <- "gray" E(test)[1]$color <- "red" sort(order(E(test)$color)[E(test)],decreasing=TRUE) plot(test, vertex.label=NA, vertex.shape="none", vertex.size=0, edge.arrow.mode=0, edge.width=2) gives me a plot where the single red edge is at

Remove self loops and vertex with no edges

旧时模样 提交于 2020-02-29 18:15:54
问题 I am constructing a gene network. I have a two column data frame which i converted into and adjacency matrix and use it in igraph. The problem is i have genes that have self loops, I want to get rid of self loops and then get rid of the vertices that have no edge (isolated maybe) from the network. I have tried a few things but somehow they do not work. My code is InnatedGraph <- graph.data.frame(innate,directed=FALSE) V(InnatedGraph)$label.cex = 0.4 plot(InnatedGraph,vertex.label=V

Remove self loops and vertex with no edges

感情迁移 提交于 2020-02-29 18:14:45
问题 I am constructing a gene network. I have a two column data frame which i converted into and adjacency matrix and use it in igraph. The problem is i have genes that have self loops, I want to get rid of self loops and then get rid of the vertices that have no edge (isolated maybe) from the network. I have tried a few things but somehow they do not work. My code is InnatedGraph <- graph.data.frame(innate,directed=FALSE) V(InnatedGraph)$label.cex = 0.4 plot(InnatedGraph,vertex.label=V

delete vertices while preserving nodes IDs

浪尽此生 提交于 2020-02-23 04:27:21
问题 I am using the function "delete vertices", and I found a strange behavior on my networks. After reading the documentation of igraph, I found that: "delete.vertices removes the specified vertices from the graph together with their adjacent edges. The ids of the vertices are not preserved." is there any work-around to preserve the ids of the original network? 回答1: Yes, assign a vertex attribute to the graph, probably the name attribute is best. These are kept after deletion. g <- graph.ring(10)

How to cluster a graph using python igraph

时光毁灭记忆、已成空白 提交于 2020-02-02 13:33:47
问题 I've been using python igraph to try to make an easier time of generating and analyzing graphs. My code below generates a random graph of 50 nodes and clusters it: from igraph import * import random as rn g = Graph() size = 50 g.add_vertices(size) vert = [] for i in range(size): for j in range(size): test = rn.randint(0,5) if j >= i or test is not 0: continue g.add_edges([(i,j)]) #layout = g.layout("kk") #plot(g, layout = layout) #dend = VertexDendrogram(graph=g, optimal_count=10) clust =

How to cluster a graph using python igraph

≡放荡痞女 提交于 2020-02-02 13:29:46
问题 I've been using python igraph to try to make an easier time of generating and analyzing graphs. My code below generates a random graph of 50 nodes and clusters it: from igraph import * import random as rn g = Graph() size = 50 g.add_vertices(size) vert = [] for i in range(size): for j in range(size): test = rn.randint(0,5) if j >= i or test is not 0: continue g.add_edges([(i,j)]) #layout = g.layout("kk") #plot(g, layout = layout) #dend = VertexDendrogram(graph=g, optimal_count=10) clust =

Find All Shortest Paths using igraph/R

拈花ヽ惹草 提交于 2020-01-31 05:21:09
问题 First off I am not very proficient with R, but I have a network of 100 nodes I'm doing analysis on. I'm looking to find all the shortest paths between every single pair of nodes in the network (100 calculations), and the trick is to return them as integers, path lengths if you will. #construct a small sample of the graph g = graph.formula('insert graph') #use the function to retrieve shortest paths from a single vertex get.all.shortest.paths(g, 1, to = V(g)) #output $res $res[[1]] [1] 1 $res[

igraph axes xlim ylim plot incorrectly

雨燕双飞 提交于 2020-01-28 05:53:18
问题 if I make a graph g : g <- read.table(text=" A B W 1 55 3 2 55 5 3 99 6 ",header=TRUE) library(igraph) g <- graph.data.frame(g) and matrix of coordinates: y<-1:5 x<-c(0.1,0.1,0.2,0.2,0.8) l<-data.frame(x,y) l<-as.matrix(l) I can plot the graph with node positions according to custom coordinates and plot axes. plot(g,layout=l,rescale=F,axes=TRUE,ylim=c(0,6),xlim=c(0,1)) But the xaxis limits do not function properly and I think are altered by yaxis limits. How can I control the xaxis they way i

igraph axes xlim ylim plot incorrectly

你离开我真会死。 提交于 2020-01-28 05:53:17
问题 if I make a graph g : g <- read.table(text=" A B W 1 55 3 2 55 5 3 99 6 ",header=TRUE) library(igraph) g <- graph.data.frame(g) and matrix of coordinates: y<-1:5 x<-c(0.1,0.1,0.2,0.2,0.8) l<-data.frame(x,y) l<-as.matrix(l) I can plot the graph with node positions according to custom coordinates and plot axes. plot(g,layout=l,rescale=F,axes=TRUE,ylim=c(0,6),xlim=c(0,1)) But the xaxis limits do not function properly and I think are altered by yaxis limits. How can I control the xaxis they way i

igraph Error could not find function “hist”

我们两清 提交于 2020-01-25 02:51:09
问题 I am using RStudio Version 0.98.484 and R version 3.0.2 (2013-09-25) -- "Frisbee Sailing" on a Mac OSX 10.6.8. here is an example of a code: a <- "a" b <- "b" c <- "c" d <- "d" e <- "e" f <- "f" model1 <- ug(~a:b, ~a:c:d,~b:c,~a:c:d:f,~d:e:f,~b:f) model1 <- as(model1, "igraph") applying the functions: cluster.distribution() #or degree.distribution() returns the error: Error in cluster.distribution() : could not find function "hist" Error in degree.distribution() : could not find function