Highlight most used path with DiagrammeR

52 views Asked by At

I made a pretty big flowchart of the path that people take in a program. Each nodes is an action and each edge connects the first action with the second action. Not everyone takes the same path in the program, so some paths are more traveled than others. I want to make a flowchart where the most traveled path is highlighted automatically.

Flowchart sample:

library(DiagrammeR)

df <- data.frame(
  from = c("start", "start", "start", "A", "B", "D", "D", "C", "E", "F"),
  to = c("A", "B", "C", "D", "D", "E", "F", "Finish", "Finish", "Finish"),
  perc = c("33%", "33%", "33%", "100%", "100%", "50%", "50%", "100%", "100%", "100%")
)

graph <- paste(
  df$from,"->",df$to,"[label = '",df$perc,"']"
)

graph_definition <- paste(
  "digraph flowchart {",
  paste(graph, collapse = " "),
  "}"
)

grViz(graph_definition)

The chance that somebody took a certain path is just the percentages of the edges on the path times eachother. In this example the path 'Start->C C->Finish' has the highest percentage. All the other paths have around 16,5%, while this one has 33,3%.

I want to make a automated visual change in the graph so that the path with the highest chance of using is black for example and the rest of the paths are grey.

I can only make it work for one edge, and also don't know how to calculate each possible path.

0

There are 0 answers