Toggle navigation
Home
▼ Details
Products and pricing
Chart gallery
User stories
Text analytics
CDC NAMCS Library
Blog
Tutorials
Contact
Sign in
Post Editor
← All help posts
View post
Save
Sankey diagrams are sometimes useful to show the relationship between discrete variables. Applications include progression of therapy, customer conversion, or almost any crosstab. Here's how to create and customize them in Protobi. <img src="/uploads/upload/image/5200/direct/1561570771291-q1-q2-sankey.png" alt="Sankey flow diagram showing the relationship between Q1 (happiness) and Q2 (health) with colored flows connecting response categories. Left side shows happiness levels (Very happy, Pretty happy, Not too happy, Don't know/Refused) and right side shows health ratings (Excellent, Good, Only fair, Poor, Don't know/Refused). Gray and white flowing bands connect the categories showing how responses correlate, with varying widths indicating the proportion of respondents." style="width: 480px;" class="fr-fic fr-dib"> The above chart shows the relationship between two discrete questions, **Q1**(happiness) and **Q1** (health). ## Flow diagrams from crosstabs Below are these two questions shown as marginal distributions: <img src="/uploads/upload/image/5200/direct/1561570784718-q1-q2-marginal.png" alt="Two side-by-side bar charts showing marginal distributions. Left chart (q1) shows happiness levels with responses: Very happy 30.5%, Pretty happy 50.9%, Not too happy 15.4%, Don't know/Refused 3.2% (N=2511). Right chart (q2) shows health ratings with responses: Excellent 25.4%, Good 51.7%, Only fair 17.8%, Poor 4.9%, Don't know/Refused 0.3% (N=2511). Both display horizontal blue bars with percentages and frequency counts." style="width: 720px;" class="fr-fic fr-dib"> We can create a crosstab by dragging one element onto another (see [brief video](/videos/crosstabs-video "Go to \"Crosstabs\" video")): <img src="/uploads/upload/image/5200/direct/1561570797979-q1-q2-crosstab.png" alt="Crosstab table showing Q2 (health) by Q1 (happiness) with blue-shaded cells. Rows show health ratings (Excellent, Good, Only fair, Poor, Don't know/Refused) and columns show happiness levels (Overall, Very happy, Pretty happy, Not too happy, Don't know/Refused). Each cell contains percentage values with stronger colors indicating higher percentages. Chi Square statistic of 416.9 (p = 0.000) shown at bottom, indicating significant relationship between variables." style="width: 480px;" class="fr-fic fr-dib"> Press the circle edit icon and from the context menu choose "Chart type..." and select "Sankey": <img src="/uploads/upload/image/5200/direct/1561570811508-chart-dialog-sankey.png" alt="Chart type selection dialog with blue header showing a grid of chart type icons. The Sankey chart type (showing flow diagram icon) is selected with green highlight in the third row. Other visible options include core, paired, tornado, column, bar, line, pie, scatter, cumul, venn, cloud, pmap, tabs, and data. Below the chart types are Chart options (stack, swap, legend, overall, reverse-x, reverse-y) and Legend position options (top, right, bottom). Cancel and Ok buttons at bottom." style="width: 480px;" class="fr-fic fr-dib"> The graph should now look like the one at top of this page. Colors are assigned by default, but you can override them by specifying colors, see below. ## Flow diagrams from groups You may have a sequence of variables, like first-, second- and third-line therapy. You can create a Sankey flow diagram directly from any collection of discrete variables. The order of columns in the diagram is the order of elements in the group. Here we created a special group of **Q1** (happiness), **Q2** (health) and **Q3** (wealth): <img src="/uploads/upload/image/5200/direct/1561570825367-q1-q2-q3-marginal.png" alt="Three survey questions displayed in a grid layout under parent group Q1-Q3. Top section shows cq1 (happiness) with three response levels: Very happy 30.5%, Pretty happy 50.9%, Not too happy 15.4%, Don't know/Refused 3.2%. Top right shows cq2 (health): Excellent 25.4%, Good 51.7%, Only fair 17.8%, Poor 4.9%, Don't know/Refused 0.3%. Bottom shows cq3 (financial situation): Live comfortably 36.8%, Meet your basic expenses 29.2%, Just meet your basic expenses 22.6%, Don't even have enough 9.2%, [VOL. DO NOT READ] 2.1%. All questions display blue horizontal bars with N=2511." style="width: 720px;" class="fr-fic fr-dib"> Setting the chart type to Sankey creates a diagram as follows: <img src="/uploads/upload/image/5200/direct/1561570837972-q1-q2-q3-sankey-black.png" alt="Three-column Sankey flow diagram with black rectangular boxes and gray/white flowing bands. Left column (cq1) shows happiness levels (Very happy, Pretty happy, Not too happy, Don't know/Refused), middle column (cq2) shows health ratings (Excellent, Good, Only fair, Poor, Don't know/Refused), right column (cq3) shows financial situations (Live comfortably, Meet your basic expenses, Just meet your basic expe, Don't even have enough t, [VOL. DO NOT READ] Do). Flow bands connect categories across all three variables showing multi-way relationships." style="width: 480px;" class="fr-fic fr-dib"> ## Customize colors If the overall chart has a format specified, colors will be assigned by default. Otherwise, colors will appear all black initially: <img src="/uploads/upload/image/5200/direct/1561570852929-q1-q2-q3-json.png" alt="JSON editor dialog titled 'Edit element properties' showing configuration for a Sankey diagram. The JSON includes key properties like "key": "sankey", "children": ["cq1", "cq2", "cq3"], "chartType": "SankeyDiagram", and a "colors" object (line 66) mapping numeric values to color codes: "1": "forestgreen", "2": "#9b6", "3": "#fa0", "4": "#39C", "5": "#26A". Also shows "titles" mapping question keys to labels. Cancel and Ok buttons at bottom." style="width: 480px;" class="fr-fic fr-dib"> You can set specific colors from the context menu for the chart element. Choose "Edit JSON..." and create a `"colors"` attribute. This should be an object mapping (unformatted) values to HTML colors like below: <img src="/uploads/upload/image/5200/direct/1561570865955-q1-q2-q3-sankey-color.png" alt="Three-column Sankey flow diagram now displaying with color-coded boxes showing happiness, health, and financial situation relationships. Left column shows happiness levels in varying shades of green and orange. Middle column shows health ratings ranging from dark green (Excellent) through light green (Good) to orange (Only fair) and blue (Poor). Right column shows financial situations in similar color coding. Gray and white flow bands connect the colored boxes, making relationships easier to trace visually." style="width: 480px;" class="fr-fic fr-dib"> ## Customize positions The boxes are positioned by default to minimize line crossings. You can customize box positions by dragging them up or down. The positions you drag are saved, the rest are free. Since the graph is redrawn on every press, it's often best to position everything if you position anything. Although sometimes it's sufficient to move special categories like "Other" down to the bottom and leave the others free to move. ## Customize size To change the size or margin of the graph, select the chart element by pressing on the header. Blue resize handles and red margin handles will appear. You can drag these with the mouse or set them explicitly under "Edit JSON..." by setting the `"size"`and `"margin"` attributes under `"chartOptions"`: <img src="/uploads/upload/image/5200/direct/1561570881068-q1-q2-q3-sankey-size.png" alt="Three-column Sankey diagram with visible selection handles, displayed with light blue background. The diagram shows the same happiness-health-wealth relationships with colored boxes, but now includes a dashed border with red corner handles (for margins) and blue handles (for resizing) around the chart area. The header 'Q1-Q3' appears in a light blue badge at top left. The overall chart has more spacing and appears larger than previous versions." style="width: 600px;" class="fr-fic fr-dib">
Publishing
Date
Status
Published
Draft
Slug
edit
Content
Thumbnail
Categories
Manage
New to Protobi?
Charts
Making Changes
Intermediate topics for editors
Frequently Asked Questions
SERMO Topics
Tutorial Pages
Internal Docs
Data Processing
Videos
Obsolete
GSG Admin
SERMO Admin
GSG Topics
How to...
Basics for viewers
Basics for editors
For project admins
Advanced topics
Assessments
Articles (in-progress)
New and updated articles
Process data in Protobi
superseded
Text open-end questions
Troubleshooting
Tracking studies
Organizing the view
API References
Tools
AI Database
Checking AI...
Convert to MD
Danger zone
Delete