Question

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?

Was it helpful?

Solution

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'.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top