Is it possible to control the horizontal order of nodes in a ggraph
tree?
- The following code creates a tree:
library(ggraph)
library(igraph)
library(tidyverse)
mygraph <- tibble(from = c("A", "A", "C", "C"), to = c( "B", "C", "D", "E")) %>%
graph_from_data_frame()
V(mygraph)$node_label <- names(V(mygraph))
mygraph %>%
ggraph(layout = 'tree', circular = FALSE) +
geom_edge_diagonal(edge_width = 0.12) +
geom_node_label(aes(label=node_label), size = 10,
label.size = 0, label.padding = unit(0.1, "lines")) +
theme_void() +
coord_fixed()
- The resulting tree:
I want to be able to keep node B as the left branch and node C and its subsequent nodes as the right branch.