igraph

How to change the colour of nodes?

痴心易碎 提交于 2019-12-01 04:25:59
问题 I'm trying to change the colour of the nodes dependent upon the month. At the moment, I've done it this way which isn't concise at all and wouldn't work for large datasets. Is there a better way of doing it? Data <- read.csv(.....) library(igraph) MartixData <- as.matrix(Data) NetworkData <- graph.adjacency(MatrixData, mode="directed", weighted=TRUE) V(NetworkData) V(NetworkData)$month <- c("June", "July", "July", "February", "September", "June", "September", "June", "December", "September",

How to spread out community graph made by using igraph package in R

纵然是瞬间 提交于 2019-12-01 03:26:37
Trying to find communities in tweet data. The cosine similarity between different words forms the adjacency matrix. Then, I created graph out of that adjacency matrix. Visualization of the graph is the task here: # Document Term Matrix dtm = DocumentTermMatrix(tweets) ### adjust threshold here dtms = removeSparseTerms(dtm, 0.998) dim(dtms) # cosine similarity matrix t = as.matrix(dtms) # comparing two word feature vectors #cosine(t[,"yesterday"], t[,"yet"]) numWords = dim(t)[2] # cosine measure between all column vectors of a matrix. adjMat = cosine(t) r = 3 for(i in 1:numWords) { highElement

How do I get the vertices on the shortest path using igraph?

浪子不回头ぞ 提交于 2019-12-01 01:10:18
问题 I'm using igraph to generate a matrix of shortest path distances between pairs of vertices but I can't figure out how to return the vertices. So far I have: path_length_matrix = ig_graph.shortest_paths_dijkstra(None,None,"distance", "ALL") I'm looking for a function which returns a matrix of paths like the matrix of distances but I can't see anything in the igraph documentation which shows how to get the paths. 回答1: The function you need is get_shortest_paths I believe. See http://packages

Minimum Cost Flow - network optimization in R

元气小坏坏 提交于 2019-11-30 23:52:08
I am trying to implement a " Minimum Cost Network Flow " transportation problem solution in R . I understand that this could be implemented from scratch using something like lpSolve . However, I see that there is a convenient igraph implementation for " Maximum Flow ". Such a pre-existing solution would be a lot more convenient, but I can't find an equivalent function for Minimum Cost. Is there an igraph function that calculates Minimum Cost Network Flow solutions, or is there a way to apply the igraph::max_flow function to a Minimum Cost problem? igraph network example: library(tidyverse)

Python igraph: get all possible paths in a directed graph

假如想象 提交于 2019-11-30 23:07:09
I am using igraph (Python) and would like to get all possible paths between two nodes in a directed graph. I am aware of the function get_all_shortest_paths , which is for shortest paths, but could not find a general one. Update: My main goal is to get all nodes in these paths, so that I can then get a subgraph of these nodes. Since you mentioned in your question that your ultimate goal is to get only the nodes that are in these paths and not the paths themselves, I think you don't even have to calculate the paths. The Graph object in igraph has a method called subcomponent . By default, it

Format for importing edgelist into igraph in python

社会主义新天地 提交于 2019-11-30 18:39:38
问题 What is the edgelist format accepted by igraph for import into python? What should the textfile that contains my weighted edges look like? I've used igraph with R before, but don't have a working R installation on the machine I need to use---so I'm stuck in python. I have an egelist.txt something like this: 123123, 321321, 1 222222, 333333, 2 123123, 333333, 3 222222, 321321, 4 ...where the values are in (source, target, weight) form. How would I import this in python? Or should I reformat my

R igraph convert parallel edges to weight attribute

≯℡__Kan透↙ 提交于 2019-11-30 17:57:38
I'm working with igraph for R. My graph is based on an edgelist which includes parallel edges (more than one edge with the same source and target). I would like to convert these parallel edges to an edge attribute weight. Is there an eay way to do this? If there is no easy way. how can I identify these parallel edges? duplicated(E(net)) does not return a single duplicate. I suppose its looking for duplicated edge ids. You can also use E(graph)$weight <- 1 followed by simplify(graph, edge.attr.comb=list(weight="sum")) to assign a weight of 1 to each edge and then collapsing multiple edges into

Overlapping community detection with igraph or other libaries

十年热恋 提交于 2019-11-30 16:29:48
I would like to detect overlapping communities in small networks/graphs. By overlapping, I mean that a node can be included within more than one communities/clusters in the output of the detection algorithm. I have looked at various community detection algorithms curretly provided by igraph , but I think none of them handles overlapping communities. Ideally, I would like to be able to programmatically utilize some implementation of such algorithm(s) in Python. However, implementation in other languages is OK too. I have implemented the hierarchical link clustering algorithm of Ahn et al a

Adjusting the node size in igraph using a matrix

对着背影说爱祢 提交于 2019-11-30 15:12:47
I have the following network diagram: set.seed(1410) df<-data.frame( "site.x"=c(rep("a",4),rep("b",4),rep("c",4),rep("d",4)), "site.y"=c(rep(c("e","f","g","h"),4)), "bond.strength"=sample(1:100,16, replace=TRUE)) library(igraph) df<-graph.data.frame(df) V(df)$names <- c("a","b","c","d","e","f","g","h") layOUT<-data.frame(x=c(rep(1,4),rep(2,4)),y=c(4:1,4:1)) E(df)[ bond.strength < 101 ]$color <- "red" E(df)[ bond.strength < 67 ]$color <- "yellow" E(df)[ bond.strength < 34 ]$color <- "green" V(df)$color <- "white" l<-as.matrix(layOUT) plot(df,layout=l,vertex.size=10,vertex.label=V(df)$names,

Match vertex size to label size in igraph

筅森魡賤 提交于 2019-11-30 14:39:12
I am trying to plot small networks using igraph in R. Each vertex in the network has a name, which is equivalent to its label. I would like to make each vertex have a rectangular symbol that is just large enough to fit its label. This is my main inspiration. What is the best way to do this with igraph? Edit: more information The code is here jsonToNM <- function(jfile, directed=TRUE) { # Requires "rjson" and "igraph" nm.json <- fromJSON(file=jfile) nm.graph <- c() # Initialize the graph with the given nodes g <- graph.empty(n=length(nm.json), directed=directed) # Add their names V(g)$name <-