Generating no edges from adjacency matrix

Viewed 162

When calling graph_from_adjacency_matrix() from igraph I am getting no edges at all.

library(igraph)

set.seed(42)

# data = read.table("sequences_distancematrix.out", row.names = 1, stringsAsFactors = FALSE, header = TRUE)
data = read.table("https://pastebin.com/raw/UWt56tfh", row.names = 1, stringsAsFactors = FALSE, header = TRUE)


dismat = data.matrix(data)

# build the graph object
network <- graph_from_adjacency_matrix(dismat, mode = "undirected")

However upon inspection of the network there is no edges:

> print_all  (network)
IGRAPH f4f6666 UN-- 46 0 -- 
+ attr: name (v/c)

I though it was perhaps because igraph would not accept doubles below 0 so x10 everything in the matrix but go the same result

The distance matrix: https://pastebin.com/UWt56tfh

Any help would be appreciated.

2 Answers
  • If you want to have weighted edges:
(network <- graph_from_adjacency_matrix(dismat, mode = "undirected", weighted = TRUE))
  • If you want to have unweighted edges:
(network <- graph_from_adjacency_matrix(dismat > 0, mode = "undirected"))

I'm not sure how you tried to multiply everything by 10, but that worked for me.

library(igraph)

data <- read.table("https://pastebin.com/raw/UWt56tfh", 
                  row.names = 1, stringsAsFactors = FALSE, header = TRUE) 

dismat <- data.matrix(data)
network <-  graph_from_adjacency_matrix(dismat*10, mode = "undirected")
print_all(network)
Related