0

I create the circle network below with the left direction. The node "Robert Zero" is always set to be on top. The nummber of nodes may fiffer every time so I must get a generic solution.This happens with this code:

library('igraph')
id <- c("Steve Sweet",  "Tom Thompson", "Roger Rabbit", "Robert Zero" )
label <- c("Steve Sweet",  "Tom Thompson", "Roger Rabbit", "Robert Zero" )
color<-c("gray",   "gray",   "gray",   "yellow")
nodes <- data.frame(id,label,color)

from <- c("Steve Sweet",  "Tom Thompson", "Roger Rabbit", "Robert Zero" )
to <- c("Tom Thompson", "Roger Rabbit", "Robert Zero",  "Steve Sweet")
group<-c("Residential Mortgage", "Real Estate Law","Divorce Attorney","Personal Injury Law" )
width<-c(4.00, 1.00, 3.00, 0.01)
color<-c("cyan", "cyan", "cyan", "cyan")
lty<-c("solid",  "solid",  "solid",  "dashed")
label<-c(NA,NA,NA,"bridge")

edges <- data.frame(from,to,group,width,color,lty,label)

#Bringing the to name in this case main_name in the 1st row of nodes dataframe
nodes<-nodes[order(nodes$id != "Robert Zero"),]

#creating the graph object of nodes and edges simple paths
gph2 <- graph_from_data_frame(edges, directed=TRUE, vertices=nodes)

rot <- function(mat, mx = which.max(mat[, 2])) {
  if (mx == 1) mat else mat[c(mx:nrow(mat), 1:(mx-1)), ]
}
#plot every network
plot(gph2, layout = rot(layout_in_circle(gph2)))

enter image description here

But then I want to turn the direction of my network to clockwise (right) direction using igraph with this

plot(gph2, layout = rot(layout_in_circle(gph2, order = order(from,decreasing = T))))

but then I get this network with edges that cross each other while I want them to create a network like the above but with opposite direction:

enter image description here

firmo23
  • 7,490
  • 2
  • 38
  • 114

1 Answers1

1

You could get the vertices number sequence and inverse it :

vertices <- as.numeric(V(gph2))
inverse_order <- vertices[length(vertices):1]
plot(gph2, layout = rot(layout_in_circle(gph2, order = inverse_order)))

enter image description here

Waldi
  • 39,242
  • 6
  • 30
  • 78