Edges with incorrect values

Asked

Viewed 31 times

-1

When running the code below, I do not get the expected graphic representation. Although A is connected to C with a value of 90.16 on Plot the link A - C is 80. Someone can help?

library(igraph)

df1 <- data.frame(origem=c( "A", "B", "B"),
                  destino=c("C", "A", "B"),
                  valor=c(90.16,80,100))

grafo11 <- graph_from_data_frame(df1, directed = FALSE)

plot(simplify(grafo11, remove.loops = TRUE, remove.multiple = TRUE),
     vertex.color = c("gold","skyblue")[1+(V(grafo11)$name=="B")],
     edge.label = E(grafo11)$valor)

inserir a descrição da imagem aqui

2 answers

3


You are filling the simplified graph, but giving the label the values of the complete graph. Place the simplified graph on a new object, indicating to the simplify what to do with attributes if they need to be aggregated (default is to discard anyone who is not Weight or name - see help for attribute.combination for details).

grafo.s <- simplify(grafo11, edge.attr.comb = "sum")

plot(grafo.s, edge.label = E(grafo.s)$valor)

inserir a descrição da imagem aqui

0

I switched the argument directed in graph_from_data_frame for TRUE and worked properly on my computer.

grafo11 <- graph_from_data_frame(df1, directed = TRUE)
  • In my case, the graph is not directed for this reason I used directed = FALSE

Browser other questions tagged

You are not signed in. Login or sign up in order to post.