thomasp85 / ggraph

Grammar of Graph Graphics
https://ggraph.data-imaginist.com
Other
1.07k stars 116 forks source link

question: having an absolute location custom layout. #375

Open OmarAshkar opened 3 months ago

OmarAshkar commented 3 months ago

Hello,

I am trying to have a specific absolute location layout. Is it possible?

For example I have this code that will create at tree with top-down

graph <- as_tbl_graph(
data.frame( from = c("1", "1", "1", "50", "5"),  
            to = c("200", "100", "50", "5", "2")) 
)
graph

layout <- create_layout(graph, layout = "tree" )
ggraph(graph, layout) + 
  geom_edge_bend() + 
  geom_node_point() + 
  geom_node_label(aes(label = as.data.frame(graph)$name))

What I am looking for is

  1. right to left orientation instead of top-down.
  2. All "to" nodes must be aligned on top of each other
  3. As you noticed, the branching sometimes happens from the same node, so may be different edges can be specified like arc if this happened.

I really appreciate some guidance on this.

Thank you!

schochastics commented 1 month ago

Not exactly sure what you are looking for, but you can specify a layout manually

x <- c(-3, -2, -1, -2, -2, 0)
y <- c(0, -1, -1, 0, 1, -1)
ggraph(graph, "manual", x = x,y = y) + 
  geom_edge_bend() + 
  geom_node_point() + 
  geom_node_label(aes(label = as.data.frame(graph)$name))