0

I want to plot a directed graph, where each edge width and arrow width is proportional to edge weights. I also want to display the weight of the edge on the graph. I am able to produce this graph with code

library(ggraph)
mydf <- structure(list(from = c("NE", "NE", "NE", "NE", "NW", "NW", "NW",
"SE", "SW", "SW", "SW"), to = c("NE", "NW", "SE", "SW", "NE", 
"NW", "SW", "SE", "NE", "NW", "SW"), weights = c(32L, 16L, 1L, 
2L, 10L, 91L, 34L, 1L, 5L, 33L, 63L)), class = "data.frame", row.names = c(NA, -11L))
g <- graph_from_data_frame(mydf)

ggraph(g, layout = data.frame(x = c(1, 0, 1, 0), y = c(1, 1, 0, 0))) + 
    geom_edge_arc(arrow = arrow(type = "closed", length = unit(3, 'mm')),
        aes(width = weights,
        label = weights), 
        start_cap = circle(5, 'mm'),
        end_cap = circle(5, 'mm'),
    label_dodge = unit(2.5, 'mm'),
    strength = 0.4,
    alpha = 0.2) + 
geom_node_point()  + 
geom_node_text(aes(label = name), repel=TRUE) + 
coord_fixed()

My problem with this graph is that arrows are not clearly plotted. It looks like multiple arrows are drawn one over the other.

enter image description here

It might be that I am missing something on how to use arrows, and I am looking for some hints to plot them better and make the graph easier to interpret.

shazz
  • 387
  • 1
  • 13
  • From the look of it, it seems that the alpha parameter is making the arrows elements overlap. Have you tried a different alpha value ? Maybe you could use a light grey to compensate for the loss of transparency. – Pierre Chevallier May 17 '21 at 17:29
  • 1
    If you are using curved lines you don't necessarily need arrows if you remember that they always curve to the right. Having said that, it is annoying that they don't display properly! – Andrew Gustar May 17 '21 at 17:32
  • To avoid overlap, you can choose check_overlap or whatever works for you in the code below. `ggraph(g,'igraph',algorithm='dh',circular=FALSE)+ geom_edge_arc(arrow = arrow(type = "closed", length = unit(1,'mm')), ............ ............, check_overlap = TRUE, angle_calc = "rot")+ coord_fixed()+ scale_edge_alpha('Direction',guide='edge_direction')+ geom_node_text(aes(label=name),repel = TRUE,point.padding = unit(0.2, "lines"))+ theme_graph()+ ggforce::theme_no_axes()+geom_node_point()+theme_void()` – NCC1701 Aug 07 '22 at 15:51

0 Answers0