0

I am stuck on sankey plots. I would like the green bar on the image below to represent a width of 525, but at the moment it is 1131. I think this is because the source is the purple 1131 to the left of the green, but I cannot figure out how to change it. I would like to understand how it's working, as I have read the documentation (https://plotly.com/python/sankey-diagram/) but just cannot get my head around it. Thank you!

Image:

Code:

import plotly.graph_objects as go
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt


fig1 = go.Figure(data=[go.Sankey(
    arrangement = "freeform",
    node = dict(
      pad = 80,
      thickness = 10,
      line = dict(color = "black", width = 0.5),
      label = ["1131 articles identified through database search",
               "3 additional articles identified",
               "525 articles after duplicates removed",
               "426 articles excluded based on title/abstract",
               "98 full-text articles assessed for eligibility",
               "50 full-text articles excluded",
               "48 articles included in the literature overview"],
      x = [0, 0, 0.4, 0.6, 0.5, 0.8, 0.7],
      y = [0, 0, 0.5, 0.8, 0.15, 0.05, 0.4],
      #color = ["darkblue","darkblue","darkblue","darkred","darkgreen","darkred","darkgreen"]
    ),
    link = dict(
      source = [0, 1, 2, 2, 4, 4], #corresponds to labels
      target = [2, 2, 3, 4, 5, 6],
      value = [1131, 3, 426, 98, 50, 48],
  ))])

fig1.update_layout(title = dict(text="Figure 1 - Review search and article screening"),
                   width=650,
                   height=450,
                   font_size=10,
                   margin=dict(l=0))```
Derek O
  • 16,770
  • 4
  • 24
  • 43
firefly
  • 339
  • 2
  • 10
  • I think it's because the plot needs to know how to label the *other* (1131 - 525) articles. – Karl Knechtel Sep 02 '21 at 15:55
  • @KarlKnechtel OK, I thought the labels for the other articles were correct because each other value corresponds to a label and seems to add up...do you have any suggestions? – firefly Sep 02 '21 at 16:43
  • 1
    I think this is really a question about how the diagrams work, rather than about how the libraries work. The size of the nodes depends on the inputs, not the outputs. That's the *specification* of a sankey diagram, according to which the library is drawing the figure. – Karl Knechtel Sep 02 '21 at 17:25

0 Answers0