Context
I am using ggraph
to arrange nodes (leaves of a tree) in a circular dendrogram and then add connections between some of the nodes (using hierarchical bundling using geom_conn_bundle
):
library(ggraph)
library(igraph)
# Example data
edges <- data.frame(from="root", to=paste("leaf", seq(1,100), sep=""))
vertices <- data.frame(name = unique(c(as.character(edges$from), as.character(edges$to))) )
tree <- graph_from_data_frame( edges, vertices=vertices )
# Drawing nodes
pr <- ggraph(tree, layout = "dendrogram", circular = TRUE) +
geom_edge_diagonal(alpha = 0.2)
# Example connection
pr <- pr + geom_conn_bundle(
data = get_con(from = 23, to = 42),
alpha=0.8,
width=3,
colour="skyblue",
tension = 0.9
)
print(pr)
This nicely displays a nearly transparent dendrogram and some (in this example one) connections in skyblue
.
Problem / Desired output
What I'd like though, is the direction of the connection being indicated by a color gradient (i.e. starting with green, slowly changing into red) instead of showing the connection in just one color (skyblue). How can I achive such a color gradient using R and ggraph's geom_conn_bundle
?
The following excerpt from Holten (2006) can serve of an example of how I'd like the connections to look: