Jose187
Jose187

Reputation: 449

Plot only Edges with a specific weight - 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

Upvotes: 5

Views: 10093

Answers (1)

Tamás
Tamás

Reputation: 48101

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.

Upvotes: 14

Related Questions