1

I am new to igraph. I use it with R (which I am new to as well). I want to use the CINNA R package later on, but am struggling to load my network into igraph/create an igraph object out of my file. What I have tried so far:

  1. ```read.graph("file", format = "graphml")
    Error in read.graph.graphml(file, ...) :
    At rinterface.c:6077 : cannot open GraphML file, File operation error```
    
  2. ```read.graph("file", format="gml")```
    

--> then R crashes.

  1. ```read.graph("file", format="edgelist")
    Error in read.graph.edgelist(file, ...) :
    At rinterface.c:5006 : cannot read edgelist, File operation error```
    
  2. ```graph_from_edgelist("file", directed=TRUE)
    Error in graph_from_edgelist("file",  : 
    graph_from_edgelist expects a matrix with two columns```
    

Does anyone understand my problem and knows how to solve it?

Caty
  • 11
  • 1

1 Answers1

0

You will need to import your file as a dataframe , then you could use the dataframe to create igraph object :

This is an example from igraph :

library(igraph)

df <- data.frame(
  A = c("Berlin", "Amsterdam", "New York") , 
  B = c("Munich", "Utrecht", "Chicago"))

df.g <- graph.data.frame(d = df, directed = FALSE)

plot(df.g, vertex.label = V(df.g)$name)

For more explanations , you could see :

Introduction to Network Analysis with R

To import a file as a dataframe , you could try the following :

links <- read.csv("Dataset1.csv", header=T, as.is=T)
# or read.table(file='Dataset1.csv')
head(links)
net <- graph_from_data_frame(d=links, vertices=nodes, directed=T) 
plot(net)

Also , have a look at ( part 3 ) here :

graph_from_data_frame

To create a graph from a format that is convenient to igraph , you could use :

# possible formats : read_graph(file, format = c(“edgelist”, “pajek”, “ncol”, “lgl”, “graphml”, “dimacs”, “graphdb”, “gml”, “dl”), …)
graph1 <- read.graph(file='your_file_name.gml',format="gml")
class(graph1)
plot(graph1)
Tou Mou
  • 1,270
  • 5
  • 16