Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

280
Vistas
Create Sankey/ Alluvial diagram in which the links combine at the node

In all examples I can find for Sankey/ Alluvial diagrams I see the links come together at the node in such a way that the size of the node is the sum of all the links connecting to it. However, I would like to vizualize a matching procedure, in which 2 databases are matched, into 3 new datasets (A: the data from dataset 1, that could not be matched; B: the data that could be matched between the 2 datasets; and C: the data from dataset 2, that could not be matched).

If I draw a super simple version of this in paint, it looks something like this:

enter image description here

Is there a way to do this in R, python, or D3JS? Preferably in the R package networkD3 ot ggplot, but any software is acceptable.

In my real data, there will be multiple steps of matching and more than 2 datasets, that is why I want to implement this in R, python, or JS and not make an oneof version in Adobe.

Edit

Please, this is a labelled version of the plot, in which 75 from both A and B 'connect' together to D. So that A + B > C + D + E

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

  • you have stated python in question, hence answer in python
  • this really is all about data preparation. re-using this answer plotly sankey graph data formatting
  • create two data frames, one of 100 rows and a second one of 150 rows. These will have overlaps based on key has overlap values
  • find the counts of rows that are only in data frame / overlap
  • prepare nodes names and values. I don't see a way to fully meet your calculation. I've elected that target has correct value, however source is half of what actually flows
  • create figure
import pandas as pd
import plotly.graph_objects as go
import numpy as np

# two data sets with some overlap...
df1 = pd.DataFrame({"key":range(0,100)})
df2 = pd.DataFrame({"key":range(25, 175)})

# calculate overlap rows
o1 = df1["key"].isin(df2["key"]).value_counts()
o2 = df2["key"].isin(df1["key"]).value_counts()

# prep overlap rows into structure ready for sankey figure
df = pd.DataFrame([{"source":str(len(df1)), "target":"a" + str(o1[False]), "value":o1[False]},
              {"source":str(len(df1)), "target":"b" + str(o1[True]), "value":o1[True]/2},
              {"source":str(len(df2)), "target":"b" + str(o2[True]), "value":o2[True]/2},
              {"source":str(len(df2)), "target":"c" + str(o2[False]), "value":o2[False]},
             ])

# build sankey figure
nodes = np.unique(df[["source","target"]], axis=None)
nodes = pd.Series(index=nodes, data=range(len(nodes)))

go.Figure(
    go.Sankey(
        node={"label": nodes.index},
        link={
            "source": nodes.loc[df["source"]],
            "target": nodes.loc[df["target"]],
            "value": df["value"],
        },
    )
)

enter image description here

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda