Set up

library(igraph)
library(ggraph)
library(magrittr)
library(ptrapr)
library(tidygraph)

Issue - direction of the edges in ptrapr output

Sometimes, the direction of the edges in the graphs produced with ptrap is inverted.

Every edge correspond to the part of a branch that connect one node to another. By convention each edge should be directed outward: pointing from the node closer to the base of the panicle to the one further away.

You can understand this better by looking at the panicle graphs: we provide two panicle graph objects:

  • One named good_panicle in which every edge points outward.
  • One named inverted_panicle in which the edges on the main rachis axis point inward.

We can see this comparing the graphs.

The good_panicle graph has no inverted edges:

good_panicle %>% plot_panicle()

Compare the previous graph with the one below, representing the inverted_panicle object. In the graph below, the edges on the main axis are inverted.

inverted_panicle %>% plot_panicle()

Invert edges with invert_edges()

If you find a panicle with inverted edges on the main axis, you can use the function invert_edges() to revert them.

tst <- inverted_panicle %>% invert_edges()
tst %>% plot_panicle()

inverted_panicle %>%
  invert_edges(check_before = TRUE) %>%
  plot_panicle()

good_panicle %>%
  invert_edges(check_before = TRUE) %>%
  plot_panicle()

Details

  • The main axis is defined as all the edges between nodes with both type “Generating” or “Primary”