igraph

Visualizing graph/network with 3 layeres (tripartite) in R/igraph

拈花ヽ惹草 提交于 2019-12-10 16:16:55
问题 I have a "layered" network, with 3 layers, let's say parents(P), children(C), grandchildren(G). The edges are always directed and towards a younger generation (either patent->child, child->grandchild or parent->grandchild). No edges between vertices in the same generation. The graph is represented by 3 edge lists (P_C, C_G, P_C). A short example is given bellow. 1) What is the proper term for this sort of graph/network? tripartite graph? As such, I suppose it is a particular case because of

How to save an adjacency matrix as a CSV file?

…衆ロ難τιáo~ 提交于 2019-12-10 14:36:19
问题 I created an adjacency matrix in R out of a CSV file that looks like this: Gene1 Gene2 Weight A B 1 A C 0.5 B D -0.5 A D -1 Here's my R code: el=read.csv("~/my.csv", sep="\t") library(igraph) g = graph.data.frame(el) adj = as_adj(g, attr='Weight') The above worked fine, and here's the adjacency matrix. > adj 4 x 4 sparse Matrix of class "dgCMatrix" A B C D A . 1 0.5 -1.0 B . . . -0.5 C . . . . D . . . . How can I export this adjacency matrix to a CSV file? I've been trying write.table to no

igraph/visNetwork with R: How to disable forward linking?

点点圈 提交于 2019-12-10 12:51:28
问题 The following code produces a nice network diagram: library(igraph);library(visNetwork);library(dplyr) set.seed(123) nnodes <- 10 nnedges <- 20 nodes <- data.frame(id = 1:nnodes) edges <- data.frame(from = sample(1:nnodes, nnedges, replace = T), to = sample(1:nnodes, nnedges, replace = T)) visNetwork(nodes, edges) %>% visIgraphLayout(layout = "layout_in_circle") %>% visNodes(shape="circle") %>% visOptions(highlightNearest = list(enabled = T, hover = T), nodesIdSelection = T) My question is:

tkplot in latex via knitr and igraph

限于喜欢 提交于 2019-12-10 12:43:31
问题 This may be a wild strange dream. I dreampt that I could put a tkplot from igraph inside a latex document via knitr . I know Yihui is know for animation stuff so I thought maybe this is possible. A google search didn't show what I was after so here's a non working attempt: \documentclass[a4paper]{scrartcl} \begin{document} <<setup, include=FALSE, cache=FALSE>>= library(igraph) @ <<network>>= edges <- structure(c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "A", "B", "C", "D", "E", "F",

Hamiltonian path using iGraph

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 10:15:12
问题 I started evaluating igraph library and its functionality. I need to calculate hamiltonian path of a graph generated by igraph_de_bruijn() function. Is there any ready made function in igraph library for that? I don't want to implement it from scratch. An example in C would be perfect. 回答1: The Hamiltonian path problem can be cast as a subgraph isomorphism problem, for which igraph has several functions. Construct a 1D lattice graph (a "line") with the same number of vertices as your graph,

Collapsing graph by clusters in igraph

ε祈祈猫儿з 提交于 2019-12-10 03:34:07
问题 I want to collapse a graph into its respective communities/clusters. Let me illustrate this with the following toy example: set.seed(123) #toy graph g <- barabasi.game(10) %>% as.undirected() #identify communities c_g <- fastgreedy.community(g) There are three communities, as seen in the following graph. I want to reduce the collapse the vertices so that vertices in the resulting graph correspond to the membership of the previous vertices. See the graph. I'm new to the igraph package and I'm

How do I calculate weighted degree distributions with igraph in R?

跟風遠走 提交于 2019-12-10 02:26:37
问题 Consider a dataframe df where the first two columns are node pairs and successive columns V1 , V2 , ..., Vn represent flows between the nodes (potentially 0, implying no edge for that column's network). I would like to conduct analysis on degree, community detection, and other network measures using the flows as weights. Then to analyze the graph with respect to the weights in V1 I do: # create graph and explore unweighted degrees with respect to V1 g <- graph.data.frame( df[df$V1!=0,] )

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

蹲街弑〆低调 提交于 2019-12-08 18:24:35
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 weights, etc... I found lots of topics about igraph package but i can't figure out how to feed my data into

How to get triad census in undirected graph using networkx in python

a 夏天 提交于 2019-12-08 13:22:15
问题 I have an undirected networkx graph as follows and I want to print triad census of the graph. However, nx.triadic_census(G) does not support undirected graphs. import networkx as nx G = nx.Graph() G.add_edges_from( [('A', 'B'), ('A', 'C'), ('D', 'B'), ('E', 'C'), ('E', 'F'), ('B', 'H'), ('B', 'G'), ('B', 'F'), ('C', 'G')]) Error: NetworkXNotImplemented: not implemented for undirected type I am aware that there is only 4 isomorphic classes for undirected graphs (not 16 as directed graphs). Is

Various issues installing igraph in Visual Studio 2010 and Cygwin/MinGW (“sys/time.h not found”)

别等时光非礼了梦想. 提交于 2019-12-08 12:15:52
问题 I couldn't get igraph to work with Visual Studio 2010 (supposedly many known issues), and so decided to try installing it in Cygwin. ./configure went fine. But make gave this error: f2c/dtime_.c:16:23: fatal error: sys/times.h: No such file or directory Makefile:2190: recipe for target `libf2c_la-dtime_.lo' failed make[3]: *** [libf2c_la-dtime_.lo] Error 1 I tried installing it in MinGW and get the same error when I make . Should I be providing "sys/time.h" or a path to it? Where is sys/time