igraph

Color pallette for vertices in igraph network in R

二次信任 提交于 2019-12-14 01:16:18
问题 I'm plotting network graph in R using `igraph1. The network has 1,380 nodes and about 150k edges. Here's the summary from igraph: IGRAPH UN-- 1380 159718 -- + attr: name (v/c), rels (v/n), label (v/n), degree (v/n), btw (v/n), color (v/c), rels (e/n) I'm trying to add a color gradient that colors the nodes based on their centrality. I've tried a couple of different versions code, first from this example: # calculate betweenness V(g_yearly)$btw <- betweenness(g_yearly) # construct color

Calculating ratio of reciprocated ties for each node in igraph

落爺英雄遲暮 提交于 2019-12-13 16:24:11
问题 I am calculating the ratio of reciprocated friendships for students in a classroom. I have created the network, called SA1Pref.net, and identified the number of reciprocated ties for each student, using the following code: recip<-is.mutual(SA1Pref.net) recip<-as.data.frame(recip) This gives me the following data frame: head(recip) recip 1 FALSE 2 TRUE 3 FALSE 4 TRUE 5 TRUE 6 TRUE So far so good. Then I create an edge list from my network, and merge that with the list of reciprocated ties. So

Getting error “recursive indexing failed at level 2” in R when trying to recurse through list

佐手、 提交于 2019-12-13 16:01:19
问题 I am getting an error "recursive indexing failed at level 2" when I try to recurse through a list of graph vertices, matching their value with a set of colors in a list. My list of colors is as follows: colrs <- list(l = "blue, c = "red", n = "gray50") Then I have a list of vertices in an igraph vs object that have the values "l", "c", or "n" on a "value" attribute (i.e. V(g)$value). The simple access that I'm trying to do is something like this: colrs[[V(g)[1]$value]] And the above works as

Get contagion chain from adjacency matrix, r, igraph

[亡魂溺海] 提交于 2019-12-13 15:51:22
问题 Q.I have a erdos.reyni graph. I infect a vertex and want to see what sequence of vertices the disease would follow? igraph has helful functions like get.adjacency(), neighbors(). Details. This is the adjacency matrix with vertex names instead of 0,1 flags and i'm trying to get the contagion chain out of it. Like the flow/sequence of an epidemic through a graph if a certain vertex is infected. Let's not worry about infection probabilities here (assume all vertices hit are infected with

No module named 'igraph._igraph'

房东的猫 提交于 2019-12-13 14:53:52
问题 I just installed python-igraph 0.7.1 from source with no problems. I didn't already have the C library installed because using the repository version caused errors while building, but setup.py successfully compiled it. However, now I can't import it. I get the following error: >>> import igraph Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/jeffcollins/Downloads/python-igraph-0.7.1/igraph/__init__.py", line 34, in <module> from igraph._igraph import *

How to create self loop in igraph R?

大兔子大兔子 提交于 2019-12-13 13:54:04
问题 How to add self loop to a graph beside changing Adjacency matrix which is changing c(i,i)=1 , is there a function to do that in igraph R package? Edit : graph creation : network=read.csv(file.choose()) network[,1]=as.character(network[,1]) network[,2]=as.character(network[,2]) mygraph=graph.data.frame(network,directed=TRUE) E(mygraph)$weight=as.numeric(network[,3]) reproducible example : karate <- graph.famous("Zachary") E(karate)$weight <- 2 adjacency<-get.adjacency(karate, attr="weight",

How to save a adjacency matrix with “get.adjacency()” in R, with iGraph and RStudio?

只谈情不闲聊 提交于 2019-12-13 13:47:01
问题 is it possible to save an adjacency matrix after "get.adjacency()" as an adjacency matrix in R? I tried test <- get.adjacency(network) but I´m getting the error Error in View : cannot coerce class "structure("dgCMatrix", package = "Matrix")" to a data.frame. I´m using RStudio and the package iGraph. 回答1: Try using sparse=FALSE in the call to get.adjacency(...) g <- graph.full(5) test <- get.adjacency(g) class(test) # [1] "dgCMatrix" # attr(,"package") # [1] "Matrix" test <- get.adjacency(g

How do you rewire a weighted network using igraph in R?

早过忘川 提交于 2019-12-13 10:15:05
问题 I have tried using 'rewire' in igraph in R, but it works only for unweighted networks. Any help??? 回答1: My version of igraph will happily rewire a weighted graph: g <- graph.ring(10) E(g)$weight <- seq_len(ecount(g)) E(g)$weight # [1] 1 2 3 4 5 6 7 8 9 10 is.weighted(g) # [1] TRUE g2 <- rewire(g,niter=3) plot(g2) is.weighted(g2) # [1] TRUE Version is: packageDescription("igraph")$Version # [1] "0.6.6" 回答2: Using version 1.0.1 of igraph, try the following: # SAME EXAMPLE AS IN PREVIOUS ANSWER

How do I load a graph in neighborhood list format?

南笙酒味 提交于 2019-12-13 07:43:33
问题 I have a file of neighborhood lists describing a directed graph: 1 2 5 2 4 which is equivalent to the edge list format: 1 2 1 5 2 4 How do I load it into igraph? I can use read.lines and strsplit but I have a feeling that this has been done before by someone else. 回答1: If you are open to using a package still in development, I would suggest exploring the "iotools" package. It's file reader is fast (think along the lines of fread from "data.table") and it includes some splitting features. Use

Plotting career path in graph

戏子无情 提交于 2019-12-13 07:32:49
问题 I have the dataframe test <- structure(list( y2002 = c("freshman","freshman","freshman","sophomore","sophomore","senior"), y2003 = c("freshman","junior","junior","sophomore","sophomore","senior"), y2004 = c("junior","sophomore","sophomore","senior","senior",NA), y2005 = c("senior","senior","senior",NA, NA, NA)), .Names = c("2002","2003","2004","2005"), row.names = c(c(1:6)), class = "data.frame") > test 2002 2003 2004 2005 1 freshman freshman junior senior 2 freshman junior sophomore senior 3