I have had a lot of trouble getting igraph attributes (vertex size, vertex colour, edge weights) into other software (ORA) via Pajek format.
I’ve exported igraph networks with
write_graph() to the Pajek format. The output .paj file appears to have content relating to my three attributes. (Pajek’s format requires that the nominated colours begin with a capital letter.)
(I used this reference to help me use the correct names for igraph attributes so that they would show up in Pajek: Importing and Exporting Graphs )
However, when I read one of these exported graphs back into R,
g <- igraph::read.graph("test.paj",format="pajek")
plot(g), the colours are recognised, but vertex size and edge weight are neglected. I can see these attributes on the graph if I use
plot(g, vertex.size=V(g)$size, edge.width=E(g)$weight)
However, I find it curious that only the vertex colour is recognised by default.
This raises two issues for:
- Is the export to (or import from) Pajek completely behaving as it should at this point in time?
- If my understanding is current, I’ve seen that Pajek .paj/.net files show that colours are not enclosed in quotation marks, yet
write_graph()does this. Is there any plan to reconsider this?
Here’s an example that shows my import/export issue:
library(igraph) num.vertices <- 12 g <- graph.star(num.vertices) num.edges <- length(E(g)) V(g)$name <- letters[1:num.vertices]
Pajek doesn’t recognise these names, so use a new attribute to set vertex ids
V(g)$id ← as.character(V(g)$name)
Random attributes for the sake of illustration
E(g)$weight <- floor(rnorm(n = num.edges,mean=10,sd=5)) V(g)$size <- floor(runif(n = num.vertices, min = 1, max=20 ))
Use a size attribute that Pajek should understand according to docs.
V(g)$vertexsize <- V(g)$size
Make the central node blue, the others red.
sample.blue.node <- 1 node.colours <- rep("Red",num.vertices) node.colours[sample.blue.node] <-"Blue" V(g)$color <- node.colours summary(g) igraph::write_graph(g, file ="test_export.paj" , format = "pajek") pajek.read.test <- igraph::read.graph("test_export.paj",format="pajek")
Only vertex colours are recognised
To recognise the other attributes, specify further options
plot(pajek.read.test, vertex.size=V(g)$size, edge.width=E(g)$weight)