graph_from_data_frame function

I have a question about the graph_from_data_frame function.

I have an edge list (el) that has 271 drugs as V1, and 6754 compounds as V2. But when I create a graph, g has just 10 nodes of only the first 10 drugs.

> length(unique(f$DRUG))

[1] 271

> length(unique(f$Compound_ID))

[1] 6754

> length(g)

[1] 10
el<-cbind(f$DRUG,f$Compound_ID, f$FC)
colnames(el)<-c("V1","V2", "weight")
g=graph_from_data_frame(el)
g <- set_edge_attr(g, "weight", value= f$FC)

What can be the problem?

Thanks in advance!

You are using length, which just gives the number of elements that is used to represent a graph. Every igraph has “length” 10. Instead, use vcount, ecount, or summary. For example:

> g <- make_full_graph(50)
> summary(g)
IGRAPH a3a4dde U--- 50 1225 -- Full graph
+ attr: name (g/c), loops (g/l)
> length(g)
[1] 10
1 Like