1

I am trying to reproduce the following plot using igraph in R.

graph

I have the following code:

library(igraph)
edges <- c(1,2, 2,3, 6,8, 6,7, 4,5, 9,10)
g<-graph(edges, n=max(edges), directed=F)
vcount(g)

plot(g, layout = layout.fruchterman.reingold,vertex.label=V(g)$number, 

edge.arrow.size=0.5)

mygraph

I am not sure how to create the topology of the graph and produce the exact same graph.

Ranji Raj
  • 778
  • 4
  • 18

2 Answers2

2

Use the layout= argument to specify the positions and V(g)$color and E(g)$lty to specify the vertex color and edge line types.

library(igraph)

edges <- c(1,2, 2,3, 6,8, 6,7, 4,5, 9,10, 1,6, 5,10)
x <- c(2, 1, 2, 1, 2, 5, 6, 5, 6, 5)
y <- c(5:1, 5:1)

g <- graph(edges, n=max(edges), directed = FALSE)
V(g)$color <- "yellow"
E(g)$lty <- c(rep(1, 6), 3, 3)
plot(g, layout = cbind(x, y))

giving

screenshot

G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341
1
library(igraph)
edges <- c(1,2, 2,3, 6,8, 6,7, 4,5, 9,10, 1,6, 5, 10)
g<-graph(edges, n=max(edges), directed=F)
E(g)$lty <- c(rep(1, length(E(g))-2), rep(2,2))
plot(g)

enter image description here

Onyambu
  • 67,392
  • 3
  • 24
  • 53
  • Is it possible to get the same topology as the original plot? – Ranji Raj Jun 01 '21 at 17:30
  • @Raj no unless you know some seed or generating engine etc. Even when you run the plot you will get the different plots but all represent the same graph – Onyambu Jun 01 '21 at 17:35
  • yes, the thing is I want to regenerate this to a PDF after knitting. I notice that they reorder newly each time. – Ranji Raj Jun 01 '21 at 17:37