Home > Software design >  How to obtain a clear graph plot / zoom under R- igraph package
How to obtain a clear graph plot / zoom under R- igraph package

Time:11-14

Assume we have the following graph under R :

library(tidyverse)
library("igraph")
library("rmutil")
library("cubature")
cities <- data.frame(name=c("Site A", "Stantsiya port", "Sahaidachnoha island", "Ulyanivka",
                            "Lyubymivka","Dnipro","Voronezeh","Oryol","Hrakove","Poltava","Suponevo","Borshchevka","Krestopivshchyna","Kalinkavishy","Chernobyl"))

relations <- data.frame(from=c("Site A", "Stantsiya port", "Sahaidachnoha island", "Ulyanivka",
                               "Lyubymivka","Dnipro", "Voronezeh", "Voronezeh", "Oryol", "Oryol", "Oryol","Hrakove","Suponevo","Suponevo","Suponevo","Poltava","Krestopivshchyna","Borshchevka","Krestopivshchyna","Kalinkavishy"),
                        to=c("Stantsiya port", "Sahaidachnoha island", "Ulyanivka", "Lyubymivka", "Dnipro", "Voronezeh","Oryol","Hrakove","Hrakove","Poltava","Suponevo","Poltava","Poltava","Krestopivshchyna","Borshchevka","Krestopivshchyna","Borshchevka","Kalinkavishy","Kalinkavishy","Chernobyl"),
                        weight=c(45, 30, 585, 1050, 493.8, 13800, 7800, 8400, 11400, 11100, 
                                   3600, 6000, 12000, 6600, 9000, 12600, 6000, 10200, 3600, 6000
                        ))

g <- graph_from_data_frame(relations, directed=FALSE, vertices=cities)

I want to plot this graph so :

plot(g, edge.arrow.size=.5, vertex.color="gold", vertex.size=15, vertex.frame.color="gray", vertex.label.color="black", vertex.label.cex=0.8, vertex.label.dist=2, edge.curved=0.2) 

Output :

enter image description here

Request : The graph paths / vertices / edges are not obvious in the previous plot , i need more clear / obious one ( edges with associated values if possible ).

Thanks

CodePudding user response:

Look at the layout_* functions available. This one worked well for me. The arguments are the same as in the question except we added the layout= argument.

plot(g, edge.arrow.size=.5, vertex.color="gold", vertex.size=15, 
  vertex.frame.color = "gray", vertex.label.color = "black", 
  vertex.label.cex = 0.8, vertex.label.dist = 2, edge.curved = 0.2,
  layout = layout_with_sugiyama)

screenshot

CodePudding user response:

I beleive i come out with some solution using similar questions :

igraph.options(plot.layout=layout.graphopt, vertex.size=7)
plot(g)

enter image description here

It will be great if i can add values to graph vertices

  • Related