'How to save Sankey diagram node positions after manual arrangement?

I am trying to create Sankey diagrams with node positions using R and plotly package (https://plotly.com/r/sankey-diagram/#define-node-position).

library(plotly)

fig <- plot_ly(

  type = "sankey",

  arrangement = "snap",

  node = list(

    label = c("A", "B", "C", "D", "E", "F"),

    x = c(0.2, 0.1, 0.5, 0.7, 0.3, 0.5),

    y = c(0.7, 0.5, 0.2, 0.4, 0.2, 0.3),

    pad = 10), # 10 Pixel

  link = list(

    source = c(0, 0, 1, 2, 5, 4, 3, 5),

    target = c(5, 3, 4, 3, 0, 2, 2, 3),

    value = c(1, 2, 1, 1, 1, 1, 1, 2)))

fig <- fig %>% layout(title = "Sankey with manually positioned node")


fig

However, the default node positions are not good enough. So I need to manually adjust the node positions from the interactive plot. However, I need to save the new positions and update the positions in the script. Then next time when I run the script again, I don't need to adjust the positions manually again?

Is there anyway to save node positions after manual arrangement?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source