This question is about the ggraph library in R. This is the working example
set.seed(3)
widths <- sample(seq(0.1,1,0.1), 10)
test.df <- data.frame("from" = seq(1,10),
"to" = rep(c(2,6),5),
"col" = rgb(seq(0,1, length.out=10),0,0),
"width" = factor(widths, levels=sort(widths)))
arc_test <- graph_from_data_frame(test.df)
ggraph(arc_test, layout = 'linear', circular = TRUE) +
geom_edge_arc0(aes(edge_width=width, edge_color=col)) +
scale_color_identity() +
coord_fixed() +
geom_node_text(label=test.df$from)
> test.df
from to col width
1 1 2 #000000 0.5
2 2 6 #1C0000 0.7
3 3 2 #390000 0.4
4 4 6 #550000 0.2
5 5 2 #710000 0.3
6 6 6 #8E0000 0.8
7 7 2 #AA0000 0.9
8 8 6 #C60000 0.6
9 9 2 #E30000 1
10 10 6 #FF0000 0.1
You can see that the colors in the data frame are not interpreted. I was expecting scale_color_identity()
to achieve this as indicated on SO here and from the function's help. If I put edge_color
outside the aesthetics
geom_edge_arc0(aes(edge_width=width), edge_color=test.df$col)
I get an error requesting me to provide data of length 36. If I test what these 36 values do with
geom_edge_arc0(aes(edge_width=width), edge_color = rep(test.df$col, each=4)[-1:-4])
I see the colors of the df interpreted, but wrongly assigned (the color order matches the order of the line thinkness).
That's doubly confusing and so this brings me to these three questions:
a) How do I achieve what I want?
b) Why does color outside aes()
request 36 values? It's not even a multiple of the 10 lines and rather 4*lines -4. geom_edge_arc
and geom_edge_arc2
even request 900 values. Where can I look up what all these values are asking for?
c) Why does the order of colors not match the data frame if I define the color outside aes()
?