0
votes

Using the igraph package in R, I've come upon the following unexpected behavior. If the edge.arrow.mode for a graph (in my case undirected, but it makes no difference) is specified as 3 (or "<->", arrows on both ends), and the edge.color is specified as rgb() with option alpha < 1, the arrows become differentially colored. It looks like there are two arrowheads on one end, and the overlap creates a darker color.

This is undesirable, since it makes the graph show some arrows as darker (looking more "important") than others. The actual graph I'm trying to visualize is undirected, the arrows on the ends of (all gray, semi-transparent) edges would be just used to illustrate how many connections a particular vertex has (the graph is quite large (100-500 vertices), with overlapping edges, so it's not easy to determine visually where an edge connects to a vertex; this also being the reason to use semi-transparent edges and vertices).

Here are some working examples:

library("igraph")
plot(make_tree(5, mode="undirected"), vertex.size=10, edge.arrow.mode=3, edge.color=rgb(0,0,0,0.2))
plot(make_tree(5, mode="undirected"), vertex.size=10, edge.arrow.mode=3, edge.color=rainbow(5, alpha=0.3))

enter image description here

The question is, is there a way around this, so the arrows would look all the same?

Displaying the number (and preferrably, the "direction") of the connections of the vertices visually some other way could also be considered (but note that vertex color (full color spectrum) is already used for another visual aid, and vertex edge coloring on top of that would make things too rainbow'sy). Changing the vertex shape to indicated the degree of connectedness is not a good solution either (edit - thanks to Tad). Making all arrowheads a solid color would be all right as well (but there does not seem to be a way to change arrow color separately from the edge color).

(Bonus: is this a bug or a feature of igraph?)

1

1 Answers

0
votes

Could you simply change vertex size based on node degree?

grph <- make_tree(5, mode="undirected")
plot(grph, vertex.size=degree(grph)*5, edge.arrow.mode=0, 
     edge.color='black')

graph

It's also possible to alter the thickness of edges (edge.width) which could give an idea of node strength in a weighted network. This doesn't really apply though.

Edit: What about changing the alpha channel of the color, such that more transparent nodes have a smaller degree? Other than that, I'm at a loss. Putting arrows on an undirected graph seems like a bad idea in general, especially if it's just as a means to visualize node degree.

colShift <-    function(x, alpha){
                        x <- col2rgb(x) / 255
                        rgb(x[1], x[2], x[3], alpha=alpha)  
                     }

grph <- make_tree(5, mode="undirected") %>%
      set_vertex_attr('color', value='dodgerblue4')

vertAlpha <- 1.1 - 1/degree(grph)
vertColor <- colShift(vertex_attr(grph, 'color'), vertAlpha)

V(grph)$color <- vertColor

plot(grph, vertex.size=degree(grph)*5, edge.arrow.mode=0, 
     edge.color='black')

enter image description here