1

I would like to make a modified sankey plot in R, where it is possible to have several edges between nodes, to identify different paths. It is a bit hard to explain so I made sample picture in ppt :)

enter image description here

I know it is ugly :) but my point is that I would like to be able to make to edges between A and B1, and clearly indicate which edge belongs to the path going to C1 and C2.

I tried sankeyPlot from the rCharts-packages, however I could only get two columns of nodes.

I have also tried the riverplot-packages, but here I can not make two edges between the same nodes.

www
  • 38,575
  • 12
  • 48
  • 84
user2335015
  • 111
  • 11

1 Answers1

2

You can use DiagrammeR with graphviz graph and HTML table labels:

library(DiagrammeR)

g1 <- 
'digraph structs {
    B1_node [label=<
      <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
        <TR><TD PORT="One">B One</TD></TR>
        <TR><TD PORT="Two">B Two</TD></TR>
      </TABLE>
      > ];

    A -> B1_node:One;
    A -> B1_node:Two;
    A -> B2;
    B1_node:One -> C1;
    B1_node:Two -> C2;
    B2 -> C3;

    rankdir=LR
}'

grViz(g1)

enter image description here

See DiagrammeR/graphviz and graphviz/node shapes documentation.

Sankey version

You could use Sankey diagram but you have to split your node B1:

links <- data.frame(
  source = c("A", "A", "B1",   "B1", "A",    "B1a", "B1b", "B2" ),
  target =c("B1", "B1", "B1a", "B1b", "B2",  "C1", "C2", "C3"),
  value = c(20, 20, 20, 20, 30, 20, 20, 30)
)

enter image description here

bergant
  • 7,122
  • 1
  • 20
  • 24