Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot only Edges with a specific weight - igraph

Tags:

r

igraph

I have a really large edge list, and I would like to plot only the edges that have a particular weight, how can I do that?

I have so far tried

plot.graph(E(sgdf)[E(sgdf)$weight==3]))

but I always get this error

Error in V(g) : Not a graph object
like image 780
Jose187 Avatar asked Jun 04 '12 17:06

Jose187


1 Answers

Copy your graph first, remove the edges that you don't need, and plot the rest:

> sgdf.copy <- delete.edges(sgdf, which(E(sgdf)$weight != 3)-1)
> plot(sgdf.copy)

The -1 is needed in delete.edges because igraph uses zero-based edge indices while R uses 1-based indices.

Update: as an anonymous editor (whose edit was sadly rejected) pointed out, igraph uses 1-base edge indices from igraph 0.6 onwards. Therefore, subtract 1 only if you are using igraph 0.5.x or earlier.

like image 155
Tamás Avatar answered Sep 22 '22 16:09

Tamás