Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Removing All Edges in Igraph

I have the following network graph:

library(tidyverse)
library(igraph)


set.seed(123)
n=15
data = tibble(d = paste(1:n))

relations = tibble(
  from = sample(data$d),
  to = lead(from, default=from[1]),
)

graph = graph_from_data_frame(relations, directed=T, vertices = data) 

V(graph)$color <- ifelse(data$d == relations$from[1], "red", "orange")

plot(graph, layout=layout.circle, edge.arrow.size = 0.2)

enter image description here

I am trying to see how to remove "edges" from this graph.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I found the following code to remove "edges" (https://igraph.org/r/doc/igraph-minus.html):

#remove the "edge" between "node 14 and node 10"
g = graph
g <- g - edge("14|10")
plot(g)

Is there a quick way to remove all "edges" in this graph?

for (i in 1:15) {
    for (j in 1:15) {
       g <- g - edge("i|j")
    }
}  

But this is not working:

Error in as.igraph.vs(graph, vp) : Invalid vertex names

Is there a better way then to remove all the edges one by one?

Thank you!

>Solution :

If you want to remove all edges, you can use

g <- graph-E(graph)
plot(g)

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading