igraph

Create Weighted Graph from Group Membership Data

折月煮酒 提交于 2019-12-11 03:43:01
问题 Suppose I have a dataset in R indicating the individuals within groups. Here is an example: grp <- c(1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5) ind <- c("A", "C", "D", "B", "C", "D", "E", "A", "D", "E", "B", "F", "E", "A", "F") data.frame(grp, ind) So, the data look like this: grp ind 1 1 A 2 1 C 3 1 D 4 2 B 5 2 C 6 2 D 7 2 E 8 3 A 9 3 D 10 3 E 11 4 B 12 4 F 13 4 E 14 5 A 15 5 F So, group 1 is composed of individuals (A, C, D), group 2 is composed of individuals (B, C, D, E), and so on. I

Calculate local clustering coefficient of a vertex (node) with R (by hand)

杀马特。学长 韩版系。学妹 提交于 2019-12-11 03:22:16
问题 I found an example showing how to calculate LCC by hand (see image). How can I replicate these steps in R? Focus is on finding the "Actual number of links among Neighbors" (middle step) I would preferably have to calculate it by hand *Does the igraph package provide this number? Example adjacency matrix: matrix(data = c(0,1,0,1,1,0,0,1,1,1,0,1,1,0,1,0), ncol = 4) 回答1: All of this can be done in igraph . It is nice that you gave an example, but since the graph is fully connected, all vertices

igraph C compiling link errors in Visual Studio

人盡茶涼 提交于 2019-12-11 03:13:00
问题 I'm trying to compile an igraph C code in the Visual Studio 2013, already got all libraries included in the properties, just as some examples that come with the distribution of igraph C, but i still got the following problems in the output window: 1>igraph.lib(prpack.obj) : error LNK2001: unresolved external symbol "public: __thiscall prpack::prpack_base_graph::~prpack_base_graph(void)" (??1prpack_base_graph@prpack@@QAE@XZ) 1>igraph.lib(prpack.obj) : error LNK2001: unresolved external symbol

Reading adjacency lists with isolated nodes using igraph

本秂侑毒 提交于 2019-12-11 02:51:16
问题 I would like to use igraph to explore some network data. My data have this structure: a <- c(13, 32, NA, NA) b <- c(32, NA, NA, NA) c <- c(34, 13, 32, NA) d <- c(5, NA, NA, NA) net <- rbind(a, b, c, d) First column: focal subject id From 2 to 4 columns: receivers from focal subject In the plot, subject 5 should be isolated. library(reshape) library(igraph) net <- as.data.frame(net) mdata <- melt(net, id=c("V1")) g <- graph.data.frame(mdata[,c(1,3)]) Warning message: In graph.data.frame(mdata[

Identifying cliques in R

一笑奈何 提交于 2019-12-11 02:28:55
问题 I have a dataframe like this: 1 2 2 3 4 5 .... Now, I plot this graph in R using the library igraph using the following code: wt=read.table("NP7.txt") wt1=matrix(nrow=nrow(wt), ncol=2) wt1=data.frame(wt1) wt1[,1:2]=wt[,1:2] write.table(wt1,"test.txt") library(igraph) wt=read.table("test.txt") wg7 <- graph.edgelist(cbind(as.character(wt$X1), as.character(wt$X2)), directed=F) sum(clusters(wg7)$csize>2) plot(wg7) a <- largest.clique(wg7) Now, on running this code I get the plot of the graph and

Betweenness centrality for relatively large scale data

核能气质少年 提交于 2019-12-11 02:27:14
问题 Using R,I try to calculate Betweenness centrality for about 1 million nodes and more than 20 million edges. To do so I have a pretty decent machine with 128GB ram and 4*2.40GHz CPU and a 64bit windows. Yet, using betweeness() of Igraph takes ages. I am wondering is there any quick solution? would it be faster, if I use Gephi?! 来源: https://stackoverflow.com/questions/21718078/betweenness-centrality-for-relatively-large-scale-data

R, igraph, is it possible to fill vertex with pattern

此生再无相见时 提交于 2019-12-11 02:13:28
问题 Drawing a graph with R and igraph, I'm using color to label vertex type. See code below. Is it possible to fill vertices with a pattern rather than a color so that the node types are distinguishable when viewed in color AND black and white? I need 4 unique colors/patterns. The only palette from colorbrewer that fits is this one: http://colorbrewer2.org/#type=sequential&scheme=OrRd&n=4 However, for my sparse graph, its still difficult to differentiate the colors. Also, I'm color blind, which

How to plot a ellipse node with igraph?

人走茶凉 提交于 2019-12-11 01:49:48
问题 It seems no such questions has ever been asked in SO. However, the help page of igraph on customizing node shapes is rather vague. Can someone provide a complete example of customizing node shape in igraph ? 回答1: You do not say what language you use, so I am going to respond in R. The shapes that are built-in can be listed with shapes() . Unfortunately, ellipse is not among them. The help page ?shapes gives a few examples of how to add additional node shapes - a triangle, a star and adding an

Adding Color and Hover Options to VisNetwork Igraph

纵饮孤独 提交于 2019-12-11 01:49:37
问题 I have been having trouble with this. I can only get one or the other but not both options in one graph. Below is the code and I received a lot of help from @lukeA to get me to this point. I have the following graph in which I can get the cluster colors into the visNetwork Igraph : library(igraph) library(visNetwork) B = matrix( c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 47, 3, 0, 3, 0, 1, 10, 13, 5, 0, 3, 19, 0, 1, 0, 1, 7, 3, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 3, 1, 0, 32, 0, 0, 3, 2, 1, 0, 0, 0,

R Reshape data by combining common value of two variables

◇◆丶佛笑我妖孽 提交于 2019-12-11 01:47:31
问题 I want to reshape a data frame by combining two variables. For example: Here is a new data: dat = data.frame( var1 = c("a", "a", "a", "Emily", "b", "Bob", "c"), var2 = c("Jhon", "Emily", "Julie", "Angela", "Bob", "Paul", "Paul"), stringsAsFactors = F ) Excepted output: # var1 var2 var3 var4 var5 # 1 a Jhon Emily Julie Angela # 2 b Bob Paul c <NA> 回答1: Using base R you can do: relation=function(dat){ .relation=function(x){ k = unique(sort(c(dat[dat[, 1] %in% x, 2], x, dat[dat[, 2] %in% x, 1]))