PlotSet LogoPlotSet

How to Create a Sankey Diagram

A step by step walkthrough for turning a source, target and value spreadsheet into a published Sankey diagram in PlotSet, from shaping the sheet to exporting or embedding the finished flow.

约 9 分钟

This guide shows how to create a Sankey diagram in PlotSet starting from a plain three column spreadsheet, source, target and value, with nodes named automatically from whatever text sits in those columns and link widths sized to match. We use a budget flow as the running example, but the same three columns work just as well for a website funnel, an energy balance or a customer journey.

Set aside nine minutes if your rows are already in source, target, value shape. That climbs by five if you're reconciling a spreadsheet with a totals row mixed into the real flows, or working out how to fold a dozen small categories into one node before upload.

你需要的数据

Three columns, one row per flow: where the amount comes from, where it goes, and how much. Nodes are created automatically from whatever names appear in the source and target columns, so there is no separate list of nodes to maintain.

示例 CSV
SourceTargetAmount
RevenueCost of Goods420000
RevenueOperating Costs260000
RevenueNet Profit180000
Cost of GoodsManufacturing300000
Cost of GoodsShipping120000
Operating CostsSalaries190000
Operating CostsMarketing70000
备注

Every amount is a positive number. A Sankey link has no concept of a negative flow, so a refund or a loss needs its own row and its own honestly named target, such as "Returns", rather than a minus sign.

A name that appears in both a source and a target column becomes one node with flow passing through it, which is exactly how a multi-stage diagram like the budget example above works.

Keep source and target names spelled identically everywhere they appear. "Marketing" and "marketing " with a trailing space will render as two separate nodes rather than merging into one.

If a node's inflows and outflows do not add up, PlotSet still draws it, just with a visibly lopsided shape. Reconcile the numbers in your spreadsheet before uploading rather than after.

操作步骤

PlotSet 中从空白模板到完成图表的具体点击路径。

  1. 01

    Open the Sankey diagram template

    From the PlotSet dashboard, start a new project and choose the Sankey template. It loads with sample data already bound, so you can see the exact three column shape (source, target, value) before you touch your own file.

    PlotSet 的模板选择界面:左侧是图表分类列表,中间展开 Bar Charts 分类的模板网格,Bar Chart 模板卡片上显示「Select」按钮。
    每份指南都从这里开始:先选分类,再选模板,不管你要做哪种图表,用的都是同一个网格。
  2. 02

    Shape your sheet into source, target and value

    Rework your spreadsheet into one row per flow, in that column order. A pivot table or a report with running totals will not work as is: pull out the individual transitions first, one row per movement from one stage to the next.

  3. 03

    Upload the file or connect a live sheet

    Import a CSV or .xlsx file from the data panel, paste rows directly from a spreadsheet, or connect a Google Sheet if you want the diagram to refresh later without a re-upload. PlotSet reads the first row as your headers.

    PlotSet 编辑器的数据视图:表格中 Name、Value、Region 三列填着加拿大各省的数据,旁边的「Data」面板提供 CSV 上传、「Magic Import」和 Google Sheet 同步。
    这里的数据视图取自一个条形图项目。你可以上传 CSV、用「Magic Import」从图片里提取数字,或同步 Google Sheet,每种图表类型的面板都一样。
  4. 04

    Map the source, target and value columns

    Confirm which column feeds each role. This is usually automatic when your headers read clearly as Source, Target and Value or similar, but check it by hand if your sheet carries extra columns PlotSet might have guessed on.

    PlotSet 数据面板中高亮的列绑定:「Label/time」对应 A 列,「Values」对应 B 列,「Filter/color」对应 C 列,下方是「Auto Binding」按钮。
    绑定决定哪一列作标签、哪一列提供数值、哪一列决定颜色。「Auto Binding」(自动绑定)会根据表头推测,所以要核对一遍,别想当然。
  5. 05

    Order the stages left to right

    PlotSet places nodes by the order flow moves through them, but if your data has a natural sequence (acquisition before conversion before retention, for instance), check the node order matches that story rather than an alphabetical default.

  6. 06

    Label the nodes and turn on link values

    Rename any node whose spreadsheet name would confuse a reader, such as an internal code, to something they would recognize. Turn on the value label so hovering, or the static label itself, shows the exact number each link carries.

  7. 07

    Set node and link colour

    Colour links by their source node by default, which is what lets a reader's eye follow one path through the crossings. Reserve a distinct colour for a terminal node you want to call out, such as a loss or a drop-off, rather than colouring every node differently.

    PlotSet 编辑器停在「Preview」标签页:画布上是做好的 Sankey Diagram,右侧的设置面板用红框标出。
    Sankey Diagram 的「Preview」标签页。所有样式设置都在红框标出的这个面板里,每个设置各自占一个标签页:外观、标题、脚注,以及这种图表类型特有的选项。
  8. 08

    Publish, embed or export the diagram

    Publish for a live, interactive diagram where hovering a link shows its exact value and a shareable link, grab the embed code for a page, or export a PNG, SVG or PDF for a deck or report.

从已加载示例数据的 Sankey Diagram 模板开始,再替换成你自己的数据。

打开模板

发布、嵌入或导出

最后一段路对每种图表都一样:「Share」(分享)把图表变成一个在线的公开链接和一段嵌入代码,「Export」(导出)把它输出成静态文件。

Share:公开链接与嵌入代码

打开嵌入代码和公开链接的开关,图表就发布出去了。链接可以放心发给任何人;嵌入代码以 iframe 的形式放进任意页面,悬停提示和交互效果都会保留。之后修改了图表,点「Recreate」就能把改动同步到链接和嵌入代码两边。

PlotSet 编辑器工具栏中高亮的「Share」按钮,紧挨着「Export」按钮。
点「Share」,完成的图表就会变成一个公开链接和一段嵌入代码。
PlotSet 的「Share」对话框:用于启用嵌入代码和公开链接的开关,「Link」「Embed」「Facebook」「Reddit」「Twitter」「LinkedIn」「Email」几个按钮,以及带「Copy」按钮的图表公开链接。
打开嵌入代码和公开链接的开关,然后复制链接或取用 iframe。之后再修改图表,点「Recreate」就能把改动同步给所有已拿到链接的人。

Export:SVG、PNG 或 JPG

「Export」会按你需要的尺寸输出一份静态副本。SVG 放到多大都清晰,还能在设计工具里继续编辑;幻灯片和文档用 PNG 或 JPG 最稳妥。想让图片在高分屏上够锐利,关键就是那个倍数设置。

PlotSet 编辑器工具栏中高亮的「Export」按钮。
要做成幻灯片或报告里的静态文件,就走「Export」这条路。
PlotSet 的「Export chart」对话框:倍数选择器设为 2x,宽高输入框填的是 1000 和 600,展开的格式菜单里列出 SVG、PNG 和 JPG。
SVG 放到多大都清晰,还能在设计工具里继续编辑;做幻灯片用 PNG 或 JPG 最稳妥。导出前先设好倍数,图片在高分屏上才够锐利。

Sankey Diagram 的样式提示

Aggregate the long tail before you upload

If fifteen small categories each carry under two percent of the total, group them into one "Other" node in your spreadsheet before uploading. Ten legible links reading well beats forty threads nobody can trace, and the reader can still see what the group contains from its label.

Name terminal nodes for what actually happened

A node where flow simply stops should say so plainly: "Churned", "Unconverted", "Written off". A vague label like "Other" at the end of a diagram hides the one part most readers came to see.

Keep the stage count at two or three

Two stages show a split, three show a journey. A fourth stage is where crossings start to dominate the picture, so if your data has more steps than that, consider whether two linked diagrams tell the story more clearly than one dense one.

Let link width do the talking, skip a legend

Because width already encodes the amount, a separate legend explaining colour usually repeats information the diagram already shows. Put your effort into a title that states what is flowing and over what period instead.

制作 Sankey Diagram 时的常见错误

A node looks wider on one side than the other

This means the inflows and outflows for that node do not sum to the same total. Add up both sides in your spreadsheet: if quantity genuinely disappears at that step, add an explicit row sending the difference to a named node like "Loss" instead of leaving it unbalanced.

The same category shows up as two separate nodes

Check for a spelling or capitalization mismatch between the source and target columns, most often a trailing space or an inconsistent abbreviation. A TRIM and a consistent name in your spreadsheet before re-uploading fixes this in one pass.

The diagram is a tangle of thin crossing links

This happens past roughly a dozen nodes on one stage. Go back to the spreadsheet and merge the smallest categories into a single named group, then re-upload. It is much easier to fix in the source data than to untangle visually after the fact.

深入了解 Sankey Diagram

不确定 Sankey Diagram 是否是正确选择?查看它是什么、何时使用以及何时不使用。

关于 Sankey Diagram

Sankey Diagram:常见问题

Three columns: source, target and value, one row per flow. Nodes are created automatically from whatever names appear in the source and target columns, so there is no separate node list to build or maintain before uploading.

现在制作你的 Sankey Diagram

免费开始,300+ 模板任选。无需信用卡。