0

I trying to learn tidygraph to illustrate relationships between employees and external entities (suppliers). The relationships could have multiple nodes, example: the employee owns a % of a company that owns a % of the supplier etc.

With a sample data I have created the plot below. (1) denotes the employee, (2) denotes a firm/link between employee and the (3) supplier in question. The plot works, but I wish that it has a specific structure to it.

enter image description here

Here are three examples of the desired layout/appearance where it starts at the top with the first node and descend further down the relationships. How could I achieve this with tidygraph?

enter image description here

Sample data and code:

library(tidygraph)
library(ggraph)

nodes <- tibble(id = 1:3)

edges <- tibble(from = c(1, 1, 2),
                to = c(2, 3, 3))

data <- tbl_graph(nodes = nodes,
                  edges = edges,
                  directed = TRUE) %>%
  activate(edges) %>%
  mutate(relation = c("Board Member", "Owns 25%", "Owns 75%"))



data %>%
  ggraph(layout = "stress") +
  geom_edge_link(
    arrow = arrow(length = unit(3, "mm"), type = "closed"),
    aes(label = relation),
    angle_calc = "along",
    label_dodge = unit(3, "mm"),
    start_cap = circle(5, "mm"),
    end_cap = circle(6, "mm")
  ) +
  geom_node_point(size = 10, 
                  colour = "antiquewhite") +
  geom_node_text(aes(label = id)) +
  theme_graph() + 
  coord_fixed()
Chamkrai
  • 5,912
  • 1
  • 4
  • 14

0 Answers0