[R] Sankey Diagrams in R

From: Eric Fail <eric.fail_at_gmx.us>
Date: Mon, 19 Mar 2012 02:52:16 -0400

Dear R-list,

I am trying to visualize where the dropout happens in our patient flow. We are currently using traditional flowcharts and it bothers me that I can't visualize both the percentage and the flow in one diagram.

The other day I came across some interesting diagrams doing exactly what I wanted, they had both flow and percentages visualized on one diagram. Here is some nice examples apparently made with ‘sankeypython’ http://www.sankey-diagrams.com/tag/software/

It didn't take long to find a blog where a Ruser (thanks!) had posted an R script that actually produces an Sankey Diagram in R http://biologicalposteriors.blogspot.com/2010/07/sankey-diagrams-in-r.html

See below for working example.

My questions are, is this the most updated Sankey Diagram-script we have in the R community? Is there a better way to visualize flow and percentages in one diagram in R?


## the working example

## th, https://tonybreyal.wordpress.com/2011/11/24/source_https-sourcing-an-r-script-from-github/ sourc.https <- function(url, ...) {
  # load package
  # install.packages(c("RCurl"), dependencies = TRUE)

  # parse and evaluate each .R script
  sapply(c(url, ...), function(u) {
    eval(parse(text = getURL(u, followlocation = TRUE, cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))), envir = .GlobalEnv)


# Example from https://gist.github.com/1423501

# My example (there is another example inside Sankey.R):
inputs = c(6, 144)
losses = c(6,47,14,7, 7, 35, 34)
unit = "n ="

labels = c("Transfers",
           "Unable to Engage",
           "Consultation only",
           "Did not complete the intake",
           "Did not engage in Treatment",
           "Discontinued Mid-Treatment",
           "Completed Treatment",
           "Active in \nTreatment")

# Clean up my mess

rm("inputs", "labels", "losses", "SankeyR", "sourc.https", "unit")

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 19 Mar 2012 - 06:54:22 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 19 Mar 2012 - 07:10:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive