ggraph
ggraph copied to clipboard
Background in edge labels
For anyone visiting this page and wanting this functionality now: you can easily extract the edge position data and use the background functionality from geom_label.
graph <- tidygraph::as_tbl_graph(data.frame(from=1:10, to=sample(1:10, 15, T), label=sample(1:10, 20, T)))
ggraph(graph) +
geom_edge_link() +
geom_label(aes(x=(xend+x)/2, y = (yend+y)/2, label=label), get_edges()) +
theme_graph()
You can also use geom_label_repel.
graph <- tidygraph::as_tbl_graph(data.frame(from=1:10, to=sample(1:10, 15, T), label=sample(1:10, 20, T)))
ggraph(graph) +
geom_edge_link() +
ggrepel::geom_label_repel(aes(x = (xend+x)/2, y = (yend+y)/2, label=label), get_edges()) +
theme_graph()
This approach has issues however if the edges are arcs...