简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM