2

I need to create a Sankey Diagram (code here: https://gist.github.com/aaronberdanier/1423501 ) where my input labels are ingredients and output is a finished product. For example, my input is "Policy Analysis", "Policy Process", "Policy Evaluation" and my losses is "Policy Formulation". In

SankeyR(inputs,losses,unit,labels)

What should my input losses and units be?

VividD
  • 10,456
  • 6
  • 64
  • 111
user3641630
  • 311
  • 1
  • 3
  • 11
  • if you could provide some data and an example of a Sankey plot, that would have been very useful. See http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example for some pointers on how you might get better answers by asking a better question. – Andy Clifton Jul 28 '14 at 23:26

1 Answers1

0

For those who don't know, a Sankey plot show how inputs and losses from a process are related. There's a good example linked to from the code in the Github repository: http://leniwiki.epfl.ch/index.php/DrawSankey

From the Github code:

# OPTIONS:
# 'inputs' is a vector of input values
# 'losses' is a vector of loss values
# 'unit' is a string of the unit
# 'labels' is a vector of the labels for inputs and losses
# 'format' is the type of plotting:

Also, there is an example listed in the code. It's commented out, but here it is:

# EXAMPLE:
# Try using these values for the global carbon cycle, from Schlesinger (1997):
# inputs = c(120,92)
# losses = c(45,75,90,1,6)
# unit = "GtC/yr"
# labels = c("GPP","Ocean assimilation","Ra","Rh","Ocean loss","LULCC","Fossil fuel emissions")
# SankeyR(inputs,losses,unit,labels)

So, if we download the code, source it and run it like this...

inputs = c(120,92)
losses = c(45,75,90,1,6)
unit = "GtC/yr"
labels = c("GPP","Ocean assimilation",
           "Ra","Rh","Ocean loss","LULCC","Fossil fuel emissions")
png("SankeyPlot.png", 
    width = 960, height = 480, units = "px", 
    pointsize = 6,
    res = 300,
    type = c("quartz"))
  SankeyR(inputs,losses,unit,labels)

dev.off()

We get this lovely plot.

enter image description here

So, it should be clear from this example that the first two labels refer to the inputs, and the remainder of that vector refers to the losses. The units in this example are Gigatonnes of Carbon per year, but can be changed by giving a different value to 'unit'.

Andy Clifton
  • 4,926
  • 3
  • 35
  • 47