Thru this site I've recently discovered Sankey Diagrams, a great way to visualize what is happening in a traditional flow chart.

Here is a good example of a Sankey Diagram by George M. Whitesides and George W. Crabtree, Don't Forget Long-Term Fundamental Research in Energy Source; Don't Forget Long-Term Fundamental Research in Energy, Science 9 February 2007:Vol. 315. no. 5813, pp. 796 - 798.

After I realized that there was no Sankey R-package I found an R script online, unfortunately this script is quite raw and somewhat limited. With high hopes I asked for a Sankey R-package or a more mature function at stackoverflow, but to my surprise it seems as we do not have a mature function for building Sankey Diagrams in R.

After I posted a bounty Geek On Acid was kind enough to suggest a small hack on the existing script which made it work more or less for my specific purpose.

The improved R-script produced this diagram, Geek On Acid's R-Sankey Diagram Source; stackoverflow.com.

But, does the lack of a R package indicate that Sankey Diagrams isn't such an amazing way to visualize attrition using R in a data flow à la the one presented in the diagram above (see initial stackoverflow question for data and R code. Maybe there's a better way to visualize attrition.

What do you think is the best way to visualize attrition in a data flow using R?

  • 8
    $\begingroup$ It is very difficult to get the diagram to look nice in any automated way (the first example was likely done by the artist manually placing the nodes). Difficult to program has nothing to do with its utility as a graphical tool. You may find more motivation on this post of mine on the GIS site about visualizing flows. Also I give some examples of parsets and dot plots on an answer to this site. $\endgroup$
    – Andy W
    Apr 17, 2012 at 15:32
  • $\begingroup$ That top diagram is a great idea, but it looks to me as though the sum of the sources doesn't equal the sum of the sinks (assuming height describes magnitude) $\endgroup$
    – naught101
    Apr 21, 2012 at 13:31
  • $\begingroup$ Ah.. never mind, I read it wrong... the lighter bits on the sources are just labels, not part of the data. A little confusing.. $\endgroup$
    – naught101
    Apr 21, 2012 at 13:33

3 Answers 3


I agree with @gung. The Sankey diagram you posted is, I think, a pretty good example of where the technique can help. While it is complicated, the context (energy input and output) is complex too and it is hard to think of a nicer way of visualizing the paths of inputs-to-outputs-acting-as-new-inputs across multiple categories of usage.

Now then, for the attrition example you posted, as others have noted it is not helpful to use a Sankey diagram. I think you need to post your full set of variables if you want a good recommendation on alternative visualizations though. If you simply want to show differences in attrition sources between sites and clinicians, a small-multiples series of dot plots may be the easiest for your audience to understand and for you to implement (see this example, where in your case the groups could be the sites, the elements within the groups would be the causes of attrition, and the horizontal axis would be 0-100%).

If the Sankey diagram is something you want to use, and you are willing to dabble in another high level language, there is a nice example (with code) on the gallery for the Python plotting package, matplotlib.


I wouldn't necessarily assume the lack of a method implies that method is unimportant or not useful. After all, for all the methods that currently exist in R, there was a time (quite possibly recent--R is only ~10 years old) when there was no package for it.

However, I should think there are any number of ways to visualize data such as attrition. My first thought looking at your chart, is that it could be represented with a dot plot. Other possibilities exist as well. The extra functionality of the Sankey Diagram is going to come into play when you have some attrition due to a particular cause at one point, and then more due to the same cause later with other inputs and outputs in between. That would be more complicated to represent by standard plots (it's also harder to follow even with a Sankey diagram--for example, the one at the top of the page takes quite a bit of work to read). Since you don't seem to have that, the Sankey diagram seems to be pretty, but overkill.

  • 1
    $\begingroup$ The first graphic given is awesome IMO. It has much detail that would be difficult to capture so intuitively in a series of dot plots. Also the Sankey Diagram is good to visualize flows from and to different nodes (the re-combining into used energy and lost energy). $\endgroup$
    – Andy W
    Apr 17, 2012 at 15:39
  • $\begingroup$ @AndyW, I don't mean to knock that figure. It's a lot of work to read largely b/c it contains a lot of information. That it draws you in & holds you there for a while can be a real plus--I didn't mean for my description to come off as negative. OTOH, the OP's data are straightforward enough that simpler plots could convey them. $\endgroup$ Apr 17, 2012 at 15:47
  • $\begingroup$ Good point, if the OP's data is no more complicated than given it is probably more trouble than it is worth! I wouldn't even want to think about converting the original energy diagram to a series of dot plots though. $\endgroup$
    – Andy W
    Apr 17, 2012 at 15:52
  • $\begingroup$ @gung, Thank you for replying to my post. I agree, the lack of method shouldn't be taken as a definitive sign that the method is not good or useful, and I have definitely not given op on Sankey diagrams (SD). In regard to my data, what you see in the diagram is only the top dimension of my data, I have data collected at 4 different sites and by 7 different clinicians and I would like to include this information in my plot, like some kind of subdivide within the overall flow. It might look like overkill with the current data, but I believe a SD would be useful if I include all my variables. $\endgroup$
    – Eric Fail
    Apr 17, 2012 at 20:33
  • $\begingroup$ W/ greater complexity, the Sankey diagram probably is your best bet. It's also worth your while to look through some of @AndyW's posts, like those linked above. He's given a lot of good answers that might be relevant. Eg, if you click on his name to navigate to his page, then click on the data-visualization tag there, you could look through his posts. $\endgroup$ Apr 17, 2012 at 21:00

How about using R code to write an SVG file with the arrow widths set according to your data, and a simple layout. Then load into Inkscape and bend the arrows around, add labels etc etc to your heart's content to make something pretty.

Obvious problem: you need to redo all your prettification in Inkscape if your data changes (although you might be able to use your pretty SVG from Inkscape as a template and just substitute new arrow widths in).

But honestly, if that multi-coloured mess of straggling squiggles at the top is a good Sankey diagram, I'd hate to see a bad one on a full stomach [although staring at it for a few more minutes has given me a clue about what it's about, a good graphic shouldn't need that].

  • 2
    $\begingroup$ I'd be interested to see a better way of visualising that data. There's a LOT of information in that plot (and multiple different variables), so of course it's going to be complicated... $\endgroup$
    – naught101
    Apr 21, 2012 at 13:27
  • 2
    $\begingroup$ Dan Carr's micro maps take along time to digest the full graphic, so does any detailed road map. Neither is necessarily a bad thing. See James Chesire's blog post, Fast Thinking and Slow Thinking Visualization. $\endgroup$
    – Andy W
    Apr 21, 2012 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.