Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sankey diagram: position of node cannot be rendered correctly #2331

Open
JinTonique opened this issue Jan 11, 2024 · 0 comments
Open

Sankey diagram: position of node cannot be rendered correctly #2331

JinTonique opened this issue Jan 11, 2024 · 0 comments

Comments

@JinTonique
Copy link

JinTonique commented Jan 11, 2024

Hello people!
I am trying to make a sankey diagram with Plotly, however, the alignment of certain node cannot be rendered correctly as I set.
PS: my Plotly version is 4.10.3 and R version is 4.3.1

Here is my code:

library("plotly")

# My data base
values <- c(10,1811,530,363,271,601,681,37,46,18,109,39,3,22,74,22,10,
            14,3,81,0,1,19,1807,521,363,270,601,16,36,8,46,86,1,0,0,23,
            14,18,34,684,23,0,16,0,23,0,0,0,23,14,18,69,1,34,0,0,0,684,
            43,643,101,6,68,43,620,101,6,19,1807,521,363,270,601,16,36,
            8,46,15,1555,79,244,346,4,115,2,2,0,4,17,251,265,1,3,25,3,
            16,0,8,43,105,24,2,1,1,6,0,601,0,129,196,109,14,82,124,1,
            34,2,0,13,0,11)
target <- c(2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,4,4,4,
            4,4,5,5,5,5,5,5,5,5,5,5,5,10,10,10,10,10,10,10,10,11,11,11,
            11,11,11,11,11,6,6,6,6,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,13,13,13,
            13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,14,15,15,
            15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,16,9,9,9,9)
source <- c(0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,
            2,2,2,2,2,2,2,2,2,2,2,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,10,
            11,11,11,6,6,6,6,6,4,4,4,4,4,4,4,4,4,4,8,8,8,8,8,8,8,8,8,8,
            8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8)

num_node <- c(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
x_position <- c(0.05,0.05,0.2,0.35,0.35,0.35,0.65,0.8,0.8,0.9,0.45,0.45,0.45,0.999,0.999,0.999,0.999)
y_position <- c(0.45,0.6,0.55,0.15,0.45,0.6,0.75,0.85,0.55,0.99,0.6,0.6,0.6,0.3,0.3,0.3,0.3)

# Sankey diagram with Plotly
fig <- plot_ly(
  type = "sankey",
  arrangement = "snap",
  node = list(
    label = num_node,
    x = x_position,
    y = y_position,
    pad = 15,
    thickness = 15
  ),
  link = list(
    source = source,
    target = target,
    value =  values
  )
)

fig

What I would expect is that node 13, 14, 15, 16 be at the same colomn, as I set their x position to 0.999. See picture below:
Capture d’écran 2024-01-11 à 18 38 34

However, for some reason, my node 13 would like to be in the middle of my diagram instead of the position where it should have been. See picture below:
Capture d’écran 2024-01-11 à 18 41 16

Does anyone have some insights why the node cannot accept x and y position I set? Thank you guys very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant