ggraph icon indicating copy to clipboard operation
ggraph copied to clipboard

Background in edge labels

Open thomasp85 opened this issue 8 years ago • 1 comments

thomasp85 avatar Feb 16 '17 22:02 thomasp85

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...

zouter avatar Feb 02 '18 09:02 zouter