Reputation: 105
I want to change the orientation of the edges that start and end at the same vertex. When I use plot.igraph, these edges are all facing right, which means the vertices that are on the left side of the circle, will have their edge overlap on other edges. Does anyone know how we can control their directions, for example point to the outside of the circle? Below is the actual figure I want to edit.
A small example if you want to play around with is posted below:
library(igraph)
g <- data.frame(start=c("a","a","b","b", "c", "c"), end=c("a","b","b","c", "c", "a"))
graph <- graph.data.frame(g, directed = T)
plot(graph, layout = layout.circle(graph))
Upvotes: 3
Views: 1542
Reputation: 1
The problem is that all the edges have to be referenced, which made a large network hard to work with. This seems to work:
edgeloopAngles <- numeric(0)
b <- 1
M <- matrixSize
m <- 0
for(row in 1:nrow(myMatrix)) {
for(col in 1:ncol(myMatrix)) {
if (row == col) {
m <- m+1
}
if (myMatrix[row,col] > 0) {
edgeloopAngles[[b]] <- 0
if (row == col) {
edgeloopAngles[[b]] <- (2 * pi * (M - m) / M)
}
b <- b+1
}
}
}
Then when you call the igraph, use it like this:
plot(g, layout=star, vertex.label.cex=0.75, vertex.label.family="sans", edge.curved = T, vertex.size=15, edge.arrow.size=0.5, edge.width=E(g)$weight, edge.loop.angle=edgeloopAngles, main="Graph Name")
Upvotes: 0
Reputation: 37641
You can control this with the parameter edge.loop.angle
.
See the help page ?igraph.plotting
plot(graph, layout = layout.circle(graph),
edge.loop.angle=c(0,0,4*pi/3,0, 2*pi/3,0))
Note that you need an angle for all edges, not just the loops, even though this only applies to loops. Also, it appears that the angle gives the amount of clockwise rotation from the horizontal.
Upvotes: 6