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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With