Sankey图输入和损失

时间:2014-07-28 22:23:45

标签: r sankey-diagram

我需要创建一个Sankey Diagram(代码在这里:https://gist.github.com/aaronberdanier/1423501),其中我的输入标签是成分,输出是成品。例如,我的输入是"政策分析","政策流程","政策评估"我的损失是"政策制定"。在

SankeyR(inputs,losses,unit,labels)

我的输入损失和单位应该是多少?

1 个答案:

答案 0 :(得分:0)

对于那些不知道的人,Sankey图表显示了流程的输入和损失是如何相关的。从Github存储库中的代码链接到一个很好的示例:http://leniwiki.epfl.ch/index.php/DrawSankey

来自Github代码:

# 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:

此外,代码中列出了一个示例。它已被注释掉,但现在是:

# 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)

因此,如果我们下载代码,请将其源代码并像这样运行...

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()

我们得到了这个可爱的情节。

enter image description here

因此,从这个例子中可以清楚地看出,前两个标签是指输入,而该向量的其余部分是指损失。此示例中的单位是每年的Gigatonnes碳,但可以通过给“单位”赋予不同的值来更改。