Igraph command

Hi, I’m a beginner in working with igraph with no statistical background. I wonder if you could help me with how I can plot two-mode network data? I have 9 lines and 13 columns. I run this command:

library(igraph)
data= read.table(file.choose())
d1= as.matrix(data)
d2= graph_from_incidence_matrix(d1, weighted=TRUE)
vcount(d2)
par(mar=c(0,0,0,0))
gplot(d2,
     vertex.color=c(rep("darkblue",9),rep("pink",11)),
     edge.width=3, edge.color=ifelse(2 < E(d2)$weight, "red", "gray"))
1 Like

Hi Nasrin_Ashrafi,

Please try using plot instead of ‘gplot’ instead of ‘plot’. For example,

library(igraph)
# data= read.table(file.choose())
# d1= as.matrix(data)

## Since I don't have your table, I'm generating a sample one.
## It will have values randomly chosen from the integers 0, 1, and 2
d1 <- matrix(sample(0:2, 9*13, repl=TRUE), 9, 13)


d2= graph_from_incidence_matrix(d1, weighted=TRUE)
vcount(d2)
par(mar=c(0,0,0,0))

plot(d2,
     vertex.color=c(rep("darkblue",7),rep("pink",6)),
     edge.width=3, edge.color=ifelse(1 < E(d2)$weight, "red", "gray"))

Alternatively, you can set the edge and node attributes within the network object itself

V(d2)$color <- c(rep("darkblue",7),rep("pink",6))
E(d2)$color <- ifelse(1 < E(d2)$weight, "red", "gray")
plot(d2, edge.width=3)

Yours sincerely,

Ignatius Pang